Skip to content

Commit

Permalink
fix: fix get vectors (#775)
Browse files Browse the repository at this point in the history
* fix: fix nested prefetch

* refactoring: simplify condition

* fix: fix condition in get vectors
  • Loading branch information
joein authored Sep 13, 2024
1 parent 2bd4f7a commit 75597a9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 3 additions & 5 deletions qdrant_client/local/local_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,9 @@ def _get_payload(
return deepcopy(processed_payload) if return_copy else processed_payload

def _get_vectors(
self, idx: int, with_vectors: Union[bool, Sequence[str]] = False
self, idx: int, with_vectors: Union[bool, Sequence[str], None] = False
) -> Optional[models.VectorStruct]:
if not with_vectors:
if with_vectors is False or with_vectors is None:
return None

dense_vectors = {
Expand All @@ -477,9 +477,7 @@ def _get_vectors(
}

# merge vectors
all_vectors = dense_vectors.copy()
all_vectors.update(sparse_vectors)
all_vectors.update(multivectors)
all_vectors = {**dense_vectors, **sparse_vectors, **multivectors}

if isinstance(with_vectors, list):
all_vectors = {name: all_vectors[name] for name in with_vectors if name in all_vectors}
Expand Down
21 changes: 21 additions & 0 deletions qdrant_client/local/tests/test_vectors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import random

from qdrant_client import models
from qdrant_client.local.local_collection import LocalCollection, DEFAULT_VECTOR_NAME


def test_get_vectors():
collection = LocalCollection(
models.CreateCollection(
vectors=models.VectorParams(size=2, distance=models.Distance.MANHATTAN)
)
)
collection.upsert(
points=[
models.PointStruct(id=i, vector=[random.random(), random.random()]) for i in range(10)
]
)

assert collection._get_vectors(idx=1, with_vectors=DEFAULT_VECTOR_NAME)
assert collection._get_vectors(idx=2, with_vectors=True)
assert collection._get_vectors(idx=3, with_vectors=False) is None

0 comments on commit 75597a9

Please sign in to comment.