lancedb_haystack.filters

Attributes

COMPARISON_OPERATORS

Functions

convert_filters_to_where_clause(→ str)

Convert Haystack filters to a WHERE clause and a tuple of params to query PostgreSQL.

_parse_logical_condition(→ str)

Compose the sub-queries of a logical step

_parse_comparison_condition(→ str)

Identifies and applies the right comparison function.

equal(→ str)

Construct a query string for comparing equality between a field and a value.

not_equal(→ str)

Construct a query string for filtering when a field and a value are not equal

greater_than(→ str)

Construct a query string for filtering when a field is greater than the value.

greater_than_equal(→ str)

Construct a query string for filtering when a field is greater than or equal to the value.

less_than(→ str)

Construct a query string for filtering when a field is less than to the value.

less_than_equal(→ str)

Construct a query string for filtering when a field is less than or equal to the value.

not_in(→ str)

Construct a query string for filtering when a field's value is not in a provided list.

in_(→ str)

Construct a query string for filtering when a field's value is in a provided list.

is_null(→ str)

Construct Filter term for the field being either empty or Null

is_not_null(→ str)

Construct Filter term for the field being neither empty nor Null

Module Contents

lancedb_haystack.filters.convert_filters_to_where_clause(filters: Dict[str, Any]) str

Convert Haystack filters to a WHERE clause and a tuple of params to query PostgreSQL.

Parameters:

filters – the filters to convert. See: https://docs.haystack.deepset.ai/docs/metadata-filtering

Returns:

a string containing the LanceDB where clause.

lancedb_haystack.filters._parse_logical_condition(condition: Dict[str, Any]) str

Compose the sub-queries of a logical step

lancedb_haystack.filters._parse_comparison_condition(condition: Dict[str, Any]) str

Identifies and applies the right comparison function.

Parameters:

condition – The condition term to convert

Returns:

a string containing the comparison for use in a LanceDB where clause

lancedb_haystack.filters.equal(field: str, value: Any) str

Construct a query string for comparing equality between a field and a value.

Parameters:
  • field – the field to compare

  • value – the value to compare it to.

Returns:

a comparison string.

lancedb_haystack.filters.not_equal(field: str, value: Any) str

Construct a query string for filtering when a field and a value are not equal

Parameters:
  • field – the field to compare

  • value – the value to compare it to.

Returns:

a comparison string.

lancedb_haystack.filters.greater_than(field: str, value: Any) str

Construct a query string for filtering when a field is greater than the value.

Note: ‘greater_than’ comparisons to None always evaluate to false.

Parameters:
  • field – the field to compare

  • value – the value to compare it to.

Returns:

a comparison string.

Raises:

FilterError – if value is a DataFrame, string, list or dict which are not supported for this comparison.

lancedb_haystack.filters.greater_than_equal(field: str, value: Any) str

Construct a query string for filtering when a field is greater than or equal to the value.

Note: ‘greater_than_equal’ comparisons to None always evaluate to false.

Parameters:
  • field – the field to compare

  • value – the value to compare it to.

Returns:

a comparison string.

Raises:

FilterError – if value is a DataFrame, string, list or dict which are not supported for this comparison.

lancedb_haystack.filters.less_than(field: str, value: Any) str

Construct a query string for filtering when a field is less than to the value.

Note: ‘less_than’ comparisons to None always evaluate to false.

Parameters:
  • field – the field to compare

  • value – the value to compare it to.

Returns:

a comparison string.

Raises:

FilterError – if value is a DataFrame, string, list or dict which are not supported for this comparison.

lancedb_haystack.filters.less_than_equal(field: str, value: Any) str

Construct a query string for filtering when a field is less than or equal to the value.

Note: ‘less_than_equal’ comparisons to None always evaluate to false.

Parameters:
  • field – the field to compare

  • value – the value to compare it to.

Returns:

a comparison string.

Raises:

FilterError – if value is a DataFrame, string, list or dict which are not supported for this comparison.

lancedb_haystack.filters.not_in(field: str, value: Any) str

Construct a query string for filtering when a field’s value is not in a provided list.

Parameters:
  • field – the field to filter on

  • value – the list of values.

Returns:

a comparison string.

Raises:

FilterError – if value is not a list.

lancedb_haystack.filters.in_(field: str, value: Any) str

Construct a query string for filtering when a field’s value is in a provided list.

Parameters:
  • field – the field to filter on

  • value – the list of values.

Returns:

a comparison string.

Raises:

FilterError – if value is not a list.

lancedb_haystack.filters.is_null(field: str) str

Construct Filter term for the field being either empty or Null

Parameters:

field – the field to check for being null

Returns:

the filter string

lancedb_haystack.filters.is_not_null(field: str) str

Construct Filter term for the field being neither empty nor Null

Parameters:

field – the field to check for being null

Returns:

the filter string

lancedb_haystack.filters.COMPARISON_OPERATORS