mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-18 16:16:33 +00:00
OpenSearch: Add Support for Lucene Filter (#3201)
### Description Add Support for Lucene Filter. When you specify a Lucene filter for a k-NN search, the Lucene algorithm decides whether to perform an exact k-NN search with pre-filtering or an approximate search with modified post-filtering. This filter is supported only for approximate search with the indexes that are created using `lucene` engine. OpenSearch Documentation - https://opensearch.org/docs/latest/search-plugins/knn/filter-search-knn/#lucene-k-nn-filter-implementation Signed-off-by: Naveen Tatikonda <navtat@amazon.com>
This commit is contained in:
@@ -164,3 +164,13 @@ def test_appx_search_with_boolean_filter() -> None:
|
||||
"foo", k=3, boolean_filter=boolean_filter_val, subquery_clause="should"
|
||||
)
|
||||
assert output == [Document(page_content="bar")]
|
||||
|
||||
|
||||
def test_appx_search_with_lucene_filter() -> None:
|
||||
"""Test Approximate Search with Lucene Filter."""
|
||||
lucene_filter_val = {"bool": {"must": [{"term": {"text": "bar"}}]}}
|
||||
docsearch = OpenSearchVectorSearch.from_texts(
|
||||
texts, FakeEmbeddings(), opensearch_url=DEFAULT_OPENSEARCH_URL, engine="lucene"
|
||||
)
|
||||
output = docsearch.similarity_search("foo", k=3, lucene_filter=lucene_filter_val)
|
||||
assert output == [Document(page_content="bar")]
|
||||
|
Reference in New Issue
Block a user