QdrantDocumentStore(location=":memory:"): sync and async clients don't share data, so mixed use silently returns empty results

Open
#4,271 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
56/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
databases

Research direction

The issue identifies _initialize_client and _initialize_async_client as the entry points and says the behavior reproduces on main at commit 8249f30. Read those initializers and the Qdrant document store tests; first check how each client is created for location=":memory:". Done means mixed sync and async use either shares documents or raises a clear error, with tests covering both client creation orders.

Written by the indexing model from the issue text.

Description

integration:qdrant P3

Describe the bug
With location=":memory:", QdrantDocumentStore creates a separate QdrantClient (sync) and AsyncQdrantClient (async). Each in-memory client gets its own isolated database, so documents written through the async API are invisible to the sync API and vice versa. count_documents / filter_documents just return 0 / [], with no error or warning.

This is easy to hit in tests and in pipelines that mix run and run_async. Using a shared local path instead isn't a workaround either: the second local client fails on Qdrant's exclusive storage lock.

To Reproduce

import asyncio
from haystack import Document
from haystack.document_stores.types import DuplicatePolicy
from haystack_integrations.document_stores.qdrant import QdrantDocumentStore

async def main():
    store = QdrantDocumentStore(location=":memory:", index="iso", embedding_dim=2, progress_bar=False)
    await store.write_documents_async(
        [Document(id="a", content="hello", embedding=[1.0, 0.0])],
        policy=DuplicatePolicy.FAIL,
    )
    print("async count:", await store.count_documents_async())        # 1
    print("sync count after async write:", store.count_documents())   # 0

    store2 = QdrantDocumentStore(location=":memory:", index="iso2", embedding_dim=2, progress_bar=False)
    store2.write_documents(
        [Document(id="b", content="sync", embedding=[0.0, 1.0])],
        policy=DuplicatePolicy.FAIL,
    )
    print("sync count:", store2.count_documents())                               # 1
    print("async count after sync write:", await store2.count_documents_async())  # 0

asyncio.run(main())

Output:

async count: 1
sync count after async write: 0
sync count: 1
async count after sync write: 0

Expected behavior
Either the sync and async methods see the same in-memory documents, or the store raises a clear error when the second client would be created for :memory: (and the docs note that mixing sync and async needs a Qdrant server via url/host). Silently returning empty results is the harmful case.

Root cause
_initialize_client and _initialize_async_client each build a new client from the same location, and for :memory: qdrant-client gives each client its own storage.

Possible fix
I have a local patch that raises QdrantStoreError when the second style of client would be opened on a :memory: store, with tests. Sync-only and async-only in-memory usage is unchanged. Happy to open a PR if this approach works for you, or adjust if you'd prefer a different behavior.

Describe your environment (please complete the following information):

  • OS: Linux
  • Python: 3.13.5
  • Haystack version: haystack-ai 3.5.0
  • Integration version: qdrant-haystack 13.2.0 (also reproduced on main at 8249f30), qdrant-client 1.20.0
Dominant language
Python
Stars
212
Forks
396
Avg merge
2d 9h
Merged PRs (30d)
95

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from deepset-ai/haystack-core-integrations

All issues in deepset-ai/haystack-core-integrations

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.