Skip to content

Commit

Permalink
fix: fix local mode loading with dense and sparse vectors (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
joein authored Jan 19, 2024
1 parent 41c0ed7 commit 6b01861
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 5 additions & 2 deletions qdrant_client/local/local_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,12 @@ def load_vectors(self) -> None:
if v is not None:
vectors[name].append(v)
else:
vectors[name].append(
np.ones(self.config.vectors[name].size, dtype=np.float32)
vector_size = (
self.config.vectors.size
if isinstance(self.config.vectors, models.VectorParams)
else self.config.vectors[name].size
)
vectors[name].append(np.ones(vector_size, dtype=np.float32))
deleted_ids.append((idx, name))

# handle sparse vectors
Expand Down
12 changes: 8 additions & 4 deletions tests/test_local_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def ingest_dense_vector_data(
vector_size: int = 1500,
path: Optional[str] = None,
collection_name: str = default_collection_name,
): # vector_size < 433: works, vector_size >= 433: crashes
):
lines = [x for x in range(10)]

embeddings = np.random.randn(len(lines), vector_size).tolist()
Expand Down Expand Up @@ -46,13 +46,16 @@ def ingest_sparse_vector_data(
max_vector_size: int = 100,
path: Optional[str] = None,
collection_name: str = default_collection_name,
add_dense_to_config: bool = False,
):
sparse_vectors = generate_random_sparse_vector_list(vector_count, max_vector_size, 0.2)
client = qdrant_client.QdrantClient(path=path)

client.recreate_collection(
collection_name,
vectors_config={},
vectors_config={}
if not add_dense_to_config
else rest.VectorParams(size=1500, distance=rest.Distance.COSINE),
sparse_vectors_config={
"text": rest.SparseVectorParams(),
},
Expand Down Expand Up @@ -101,9 +104,10 @@ def test_local_dense_persistence():
assert client.count("example_2").count == 10


def test_local_sparse_persistence():
@pytest.mark.parametrize("add_dense_to_config", [True, False])
def test_local_sparse_persistence(add_dense_to_config):
with tempfile.TemporaryDirectory() as tmpdir:
client = ingest_sparse_vector_data(path=tmpdir)
client = ingest_sparse_vector_data(path=tmpdir, add_dense_to_config=add_dense_to_config)
assert client.count(default_collection_name).count == 10

(post_result, _) = client.scroll(
Expand Down

0 comments on commit 6b01861

Please sign in to comment.