Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Qdrant filters supports #5446

Merged
Prev Previous commit
Next Next commit
Run format and lint
  • Loading branch information
kacperlukawski committed May 30, 2023
commit fb22b8048637fe84c9d61ccf9b179bb1954a97fa
13 changes: 6 additions & 7 deletions langchain/vectorstores/qdrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from hashlib import md5
from operator import itemgetter
from typing import (
TYPE_CHECKING,
Any,
Callable,
Dict,
Expand All @@ -33,12 +32,11 @@
"Please install it with `pip install qdrant-client`."
)

from qdrant_client.http import models as rest
from qdrant_client.conversions import common_types
from qdrant_client.http import models as rest

MetadataFilter = Union[
Dict[str, Union[str, int, bool, dict, list]], common_types.Filter
]
DictFilter = Dict[str, Union[str, int, bool, dict, list]]
MetadataFilter = Union[DictFilter, common_types.Filter]


class Qdrant(VectorStore):
Expand Down Expand Up @@ -228,7 +226,8 @@ def similarity_search_with_score(
if filter is not None and isinstance(filter, dict):
warnings.warn(
dev2049 marked this conversation as resolved.
Show resolved Hide resolved
"Using dict as a `filter` is deprecated. Please use qdrant-client "
"filters directly: https://qdrant.tech/documentation/concepts/filtering/",
"filters directly: "
"https://qdrant.tech/documentation/concepts/filtering/",
DeprecationWarning,
)
qdrant_filter = self._qdrant_filter_from_dict(filter)
Expand Down Expand Up @@ -499,7 +498,7 @@ def _build_condition(self, key: str, value: Any) -> List[rest.FieldCondition]:
return out

def _qdrant_filter_from_dict(
self, filter: Optional[MetadataFilter]
self, filter: Optional[DictFilter]
) -> Optional[rest.Filter]:
if not filter:
return None
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_tests/vectorstores/fake_embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class ConsistentFakeEmbeddings(FakeEmbeddings):
"""Fake embeddings which remember all the texts seen so far to return consistent
vectors for the same texts."""

def __init__(self):
self.known_texts = []
def __init__(self) -> None:
self.known_texts: List[str] = []

def embed_documents(self, texts: List[str]) -> List[List[float]]:
"""Return consistent embeddings for each text seen so far."""
Expand Down
3 changes: 1 addition & 2 deletions tests/integration_tests/vectorstores/test_qdrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
from typing import Callable, Optional

import pytest
from qdrant_client.http import models as rest

from langchain.docstore.document import Document
from langchain.embeddings.base import Embeddings
from langchain.vectorstores import Qdrant
from tests.integration_tests.vectorstores.fake_embeddings import FakeEmbeddings

from qdrant_client.http import models as rest


@pytest.mark.parametrize(
["content_payload_key", "metadata_payload_key"],
Expand Down