Skip to content

Commit

Permalink
Substring support for similarity_search_with_score (#10746)
Browse files Browse the repository at this point in the history
**Description:** Possible to filter with substrings in
similarity_search_with_score, for example: filter={'user_id':
{'substring': 'user'}}

---------

Co-authored-by: Harrison Chase <[email protected]>
  • Loading branch information
mateai and hwchase17 authored Sep 20, 2023
1 parent 740eafe commit 900dbd1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libs/langchain/langchain/vectorstores/pgembedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,13 @@ def similarity_search_with_score_by_vector(
value_case_insensitive[IN]
)
filter_clauses.append(filter_by_metadata)
elif isinstance(value, dict) and "substring" in map(
str.lower, value
):
filter_by_metadata = EmbeddingStore.cmetadata[key].astext.ilike(
f"%{value['substring']}%"
)
filter_clauses.append(filter_by_metadata)
else:
filter_by_metadata = EmbeddingStore.cmetadata[
key
Expand Down

0 comments on commit 900dbd1

Please sign in to comment.