Skip to content

Commit

Permalink
Support TEXT_MATCH FilterOperator in Postgres Vector Store (#16304)
Browse files Browse the repository at this point in the history
  • Loading branch information
ob1-dev authored Sep 30, 2024
1 parent 5ebd340 commit 0f04872
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ def _to_postgres_operator(self, operator: FilterOperator) -> str:
return "NOT IN"
elif operator == FilterOperator.CONTAINS:
return "@>"
elif operator == FilterOperator.TEXT_MATCH:
return "LIKE"
else:
_logger.warning(f"Unknown operator: {operator}, fallback to '='")
return "="
Expand All @@ -488,6 +490,13 @@ def _build_filter_clause(self, filter_: MetadataFilter) -> Any:
f"{self._to_postgres_operator(filter_.operator)} "
f"'[\"{filter_.value}\"]'"
)
elif filter_.operator == FilterOperator.TEXT_MATCH:
# Where the operator is text_match, we need to wrap the filter in '%' characters
return text(
f"metadata_->>'{filter_.key}' "
f"{self._to_postgres_operator(filter_.operator)} "
f"'%{filter_.value}%'"
)
else:
# Check if value is a number. If so, cast the metadata value to a float
# This is necessary because the metadata is stored as a string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exclude = ["**/BUILD"]
license = "MIT"
name = "llama-index-vector-stores-postgres"
readme = "README.md"
version = "0.2.5"
version = "0.2.6"

[tool.poetry.dependencies]
python = ">=3.8.1,<4.0"
Expand Down

0 comments on commit 0f04872

Please sign in to comment.