Implement basic metadata filtering in Qdrant (#1689)

This PR implements a basic metadata filtering mechanism similar to the
ones in Chroma and Pinecone. It still cannot express complex conditions,
as there are no operators, but some users requested to have that feature
available.
This commit is contained in:
Kacper Łukawski
2023-03-15 15:31:39 +01:00
committed by GitHub
parent d4edd3c312
commit 4a327dd1d6
2 changed files with 43 additions and 4 deletions

View File

@@ -56,6 +56,20 @@ def test_qdrant_with_metadatas(
assert output == [Document(page_content="foo", metadata={"page": 0})]
def test_qdrant_similarity_search_filters() -> None:
"""Test end to end construction and search."""
texts = ["foo", "bar", "baz"]
metadatas = [{"page": i} for i in range(len(texts))]
docsearch = Qdrant.from_texts(
texts,
FakeEmbeddings(),
metadatas=metadatas,
host="localhost",
)
output = docsearch.similarity_search("foo", k=1, filter={"page": 1})
assert output == [Document(page_content="bar", metadata={"page": 1})]
@pytest.mark.parametrize(
["content_payload_key", "metadata_payload_key"],
[