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

fix: fix local mode loading with dense and sparse vectors #433

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions qdrant_client/local/local_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,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
Loading