Repository navigation
fix(qdrant): fix async collection creation using AsyncQdrantClient - #21419
logan-markewich merged 4 commits into
Conversation
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]>
There was a problem hiding this comment.
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
aclientonly.
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.
| 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(...))" | ||
| ) |
There was a problem hiding this comment.
_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.
| 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(...))" | |
| ) |
| assert self._aclient is not None, ( | ||
| "Async client is not initialized. Pass aclient= to the constructor: " | ||
| "QdrantVectorStore(..., aclient=AsyncQdrantClient(...))" | ||
| ) |
There was a problem hiding this comment.
_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.
| 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(...))" | |
| ) |
| if self._aclient is None: | ||
| raise ValueError( | ||
| "Async client is not initialized. Pass aclient= to the constructor: " | ||
| "QdrantVectorStore(..., aclient=AsyncQdrantClient(...))" | ||
| ) |
There was a problem hiding this comment.
_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).
| if self._aclient is None: | |
| raise ValueError( | |
| "Async client is not initialized. Pass aclient= to the constructor: " | |
| "QdrantVectorStore(..., aclient=AsyncQdrantClient(...))" | |
| ) | |
| self._ensure_async_client() |
…_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]>
Description
Fixes #14151
When
QdrantVectorStoreis initialised with only anAsyncQdrantClient(
aclient=..., client=None), three related bugs caused failures:_acollection_exists()and_acreate_collection()lacked an explicitguard, so a
None_aclientproduced an unhelpfulAttributeError: 'NoneType' object has no attribute 'collection_exists'instead of a clear message.
_acreate_collection()had no upfront check, meaning it could silentlyproceed with a
Noneasync client and only fail deep inside the call.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(): addedassert self._client is not Noneso synccallers also get a clear error if the sync client was not provided.
_acollection_exists(): addedassert self._aclient is not Nonewithan explanatory message pointing to
aclient=._acreate_collection(): added an explicitValueErrorat the very topwhen
self._aclient is None, preventing any async collection-creationattempt without a valid async client.
5 new
@pytest.mark.asynciotest cases added:test_acreate_collection_uses_aclient— collection created via_aclienttest_aadd_with_only_aclient-async_addworks withclient=Nonetest_aadd_raises_if_no_aclient-async_addraises when noaclienttest_aquery_with_only_aclient-aqueryreturns results with onlyaclienttest_async_hybrid_with_aclient- hybrid async path uses_aclientonly(auto-skipped if
fastembedis not installed)New Package?
Did I fill in the
tool.llamahubsection in thepyproject.tomland provide a detailed README.md for my new integration or package?Version Bump?
Did I bump the version in the
pyproject.tomlfile of the package I am updating? (Except for thellama-index-corepackage)Type of Change
How Has This Been Tested?
All 5 new tests run against
AsyncQdrantClient(":memory:")- no externalserver 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:
uv run make format; uv run make lintto appease the lint gods(ruff check + ruff format both clean;
makeunavailable on Windowsso ruff was invoked directly via
uv run ruff ...)