Skip to content

fix(qdrant): fix async collection creation using AsyncQdrantClient - #21419

Merged
logan-markewich merged 4 commits into
run-llama:mainfrom
inamdarmihir:fix/qdrant-async-collection-creation-14151
May 4, 2026
Merged

logan-markewich merged 4 commits into
run-llama:mainfrom
inamdarmihir:fix/qdrant-async-collection-creation-14151

Conversation

@inamdarmihir

Copy link
Copy Markdown
Contributor

Description

Fixes #14151

When QdrantVectorStore is initialised with only an AsyncQdrantClient
(aclient=..., client=None), three related bugs caused failures:

  1. _acollection_exists() and _acreate_collection() lacked an explicit
    guard, so a None _aclient produced an unhelpful
    AttributeError: 'NoneType' object has no attribute 'collection_exists'
    instead of a clear message.
  2. _acreate_collection() had no upfront check, meaning it could silently
    proceed with a None async client and only fail deep inside the call.
  3. async_add() / aquery() already delegated to _ensure_async_client(),
    but there was no matching guard inside the lower-level async helpers,
    so direct calls to those helpers bypassed the check entirely.

Changes made (only files inside llama-index-vector-stores-qdrant/):

  • _collection_exists(): added assert self._client is not None so sync
    callers also get a clear error if the sync client was not provided.
  • _acollection_exists(): added assert self._aclient is not None with
    an explanatory message pointing to aclient=.
  • _acreate_collection(): added an explicit ValueError at the very top
    when self._aclient is None, preventing any async collection-creation
    attempt without a valid async client.
  • No changes to public API signatures; the sync path is untouched.

5 new @pytest.mark.asyncio test cases added:

  • test_acreate_collection_uses_aclient — collection created via _aclient
  • test_aadd_with_only_aclient - async_add works with client=None
  • test_aadd_raises_if_no_aclient -async_add raises when no aclient
  • test_aquery_with_only_aclient - aquery returns results with only aclient
  • test_async_hybrid_with_aclient - hybrid async path uses _aclient only
    (auto-skipped if fastembed is not installed)

New Package?

Did I fill in the tool.llamahub section in the pyproject.toml and provide a detailed README.md for my new integration or package?

  • Yes
  • No (not a new package)

Version Bump?

Did I bump the version in the pyproject.toml file of the package I am updating? (Except for the llama-index-core package)

  • Yes
  • No (bug fix only; no public API change)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • I added new unit tests to cover this change

All 5 new tests run against AsyncQdrantClient(":memory:") - no external
server required. Existing 23 tests continue to pass; 16 server-dependent
tests remain skipped (unchanged behaviour).

Ran locally with:
uv run -- pytest tests/test_vector_stores_qdrant.py -v
Result: 28 passed, 16 skipped

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added Google Colab support for the newly added notebooks.
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I ran uv run make format; uv run make lint to appease the lint gods
    (ruff check + ruff format both clean; make unavailable on Windows
    so ruff was invoked directly via uv run ruff ...)

Fixes #14151

- Add _acollection_exists() that uses self._aclient
- Rewrite _acreate_collection() to fully use self._aclient instead
  of falling through to sync self._client path
- Guard aadd() and aquery() to raise RuntimeError when aclient is
  None but async path is invoked
- Add ValueError guard in __init__ when both client and aclient
  are None
- Add 5 async test cases covering the above scenarios

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Copilot AI review requested due to automatic review settings April 20, 2026 04:56
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Apr 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes async-only initialization paths in the Qdrant vector store when QdrantVectorStore is constructed with aclient=... and client=None, addressing failures during async collection existence checks / creation and adding regression tests for issue #14151.

Changes:

  • Add explicit async-client guard to _acreate_collection() to fail fast with a clearer error.
  • Add guards to _collection_exists() / _acollection_exists() for clearer failures when the corresponding client is missing.
  • Add async-only unit tests covering async collection creation, async add/query, and hybrid async behavior with aclient only.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
llama-index-integrations/vector_stores/llama-index-vector-stores-qdrant/llama_index/vector_stores/qdrant/base.py Adds async client guard to async collection creation and client-presence guards to collection existence helpers.
llama-index-integrations/vector_stores/llama-index-vector-stores-qdrant/tests/test_vector_stores_qdrant.py Adds new asyncio tests covering async-only client scenarios and regressions for #14151.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +954 to +964
assert self._client is not None, (
"Sync client is not initialized. Pass client= to the constructor."
)
return self._client.collection_exists(collection_name)

async def _acollection_exists(self, collection_name: str) -> bool:
"""Asynchronous method to check if a collection exists."""
assert self._aclient is not None, (
"Async client is not initialized. Pass aclient= to the constructor: "
"QdrantVectorStore(..., aclient=AsyncQdrantClient(...))"
)

Copilot AI Apr 20, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_collection_exists uses assert self._client is not None for a runtime guard. Asserts can be disabled with python -O, which would reintroduce the original failure mode (an AttributeError on None.collection_exists) and also changes the exception type to AssertionError in normal runs. Prefer an explicit exception (e.g., ValueError/RuntimeError) or a dedicated _ensure_sync_client() helper similar to _ensure_async_client() so the guard is always enforced.

Suggested change
assert self._client is not None, (
"Sync client is not initialized. Pass client= to the constructor."
)
return self._client.collection_exists(collection_name)
async def _acollection_exists(self, collection_name: str) -> bool:
"""Asynchronous method to check if a collection exists."""
assert self._aclient is not None, (
"Async client is not initialized. Pass aclient= to the constructor: "
"QdrantVectorStore(..., aclient=AsyncQdrantClient(...))"
)
if self._client is None:
raise ValueError(
"Sync client is not initialized. Pass client= to the constructor."
)
return self._client.collection_exists(collection_name)
async def _acollection_exists(self, collection_name: str) -> bool:
"""Asynchronous method to check if a collection exists."""
if self._aclient is None:
raise ValueError(
"Async client is not initialized. Pass aclient= to the constructor: "
"QdrantVectorStore(..., aclient=AsyncQdrantClient(...))"
)

Copilot uses AI. Check for mistakes.
Comment on lines +961 to +964
assert self._aclient is not None, (
"Async client is not initialized. Pass aclient= to the constructor: "
"QdrantVectorStore(..., aclient=AsyncQdrantClient(...))"
)

Copilot AI Apr 20, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_acollection_exists uses assert self._aclient is not None as a guard. Asserts can be optimized away, which can bring back the unhelpful AttributeError this PR is trying to fix, and it also yields AssertionError instead of the ValueError raised elsewhere (e.g., _ensure_async_client). Use _ensure_async_client() here (or raise a ValueError directly) instead of assert so the check is consistent and cannot be skipped.

Suggested change
assert self._aclient is not None, (
"Async client is not initialized. Pass aclient= to the constructor: "
"QdrantVectorStore(..., aclient=AsyncQdrantClient(...))"
)
if self._aclient is None:
raise ValueError(
"Async client is not initialized. Pass aclient= to the constructor: "
"QdrantVectorStore(..., aclient=AsyncQdrantClient(...))"
)

Copilot uses AI. Check for mistakes.
Comment on lines +878 to +882
if self._aclient is None:
raise ValueError(
"Async client is not initialized. Pass aclient= to the constructor: "
"QdrantVectorStore(..., aclient=AsyncQdrantClient(...))"
)

Copilot AI Apr 20, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_acreate_collection now has its own self._aclient is None check, but this duplicates _ensure_async_client() and uses a slightly different error message/format. Consider calling self._ensure_async_client() at the top to keep async-guard behavior and messaging consistent across async methods (and avoid future divergence if the wording changes).

Suggested change
if self._aclient is None:
raise ValueError(
"Async client is not initialized. Pass aclient= to the constructor: "
"QdrantVectorStore(..., aclient=AsyncQdrantClient(...))"
)
self._ensure_async_client()

Copilot uses AI. Check for mistakes.
…_async_client()

Address Copilot review feedback:
- _collection_exists: replace assert with explicit ValueError so the guard
  cannot be disabled with python -O and raises a consistent exception type
- _acollection_exists: delegate to _ensure_async_client() for consistent
  error message and exception type with the rest of the async methods
- _acreate_collection: same — delegate to _ensure_async_client() instead
  of a duplicated inline ValueError with slightly different wording

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Apr 20, 2026
@logan-markewich
logan-markewich merged commit f367b09 into run-llama:main May 4, 2026
12 checks passed
Ricardo-M-L pushed a commit to Ricardo-M-L/llama_index that referenced this pull request Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Async support for Qdrant Vector store

3 participants