Skip to content

Commit 66513c8

Browse files
fix(qdrant): share in-memory collections dict between sync and async clients
When using location=':memory:', QdrantClient and AsyncQdrantClient each create a separate in-memory store, so data written via the sync client is invisible to the async client and vice versa. Fix by sharing the underlying .collections and .aliases dicts after the second client is initialised, so both clients always see the same data. This makes mixed sync/async tests (e.g. sync write_documents + async count_unique_metadata_by_filter_async) work correctly with in-memory stores.
1 parent 74a993b commit 66513c8

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

  • integrations/qdrant/src/haystack_integrations/document_stores/qdrant

integrations/qdrant/src/haystack_integrations/document_stores/qdrant/document_store.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ def _initialize_client(self) -> None:
269269
client_params = self._prepare_client_params()
270270
# This step adds the api-key and User-Agent to metadata
271271
self._client = qdrant_client.QdrantClient(**client_params)
272+
# For in-memory stores: if the async client was already initialised,
273+
# share its underlying collections dict so both clients see the same data.
274+
if self.location == ":memory:" and self._async_client is not None:
275+
self._client._client.collections = self._async_client._client.collections
276+
self._client._client.aliases = self._async_client._client.aliases
277+
return
272278
# Make sure the collection is properly set up
273279
self._set_up_collection(
274280
self.index,
@@ -290,6 +296,12 @@ async def _initialize_async_client(self) -> None:
290296
self._async_client = qdrant_client.AsyncQdrantClient(
291297
**client_params,
292298
)
299+
# For in-memory stores: if the sync client was already initialised,
300+
# share its underlying collections dict so both clients see the same data.
301+
if self.location == ":memory:" and self._client is not None:
302+
self._async_client._client.collections = self._client._client.collections
303+
self._async_client._client.aliases = self._client._client.aliases
304+
return
293305
await self._set_up_collection_async(
294306
self.index,
295307
self.embedding_dim,

0 commit comments

Comments
 (0)