Skip to content

Commit 5de24ee

Browse files
committed
Merge latest main after validation
2 parents 9913536 + 842909c commit 5de24ee

3 files changed

Lines changed: 104 additions & 1 deletion

File tree

‎python/packages/qdrant/README.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,23 @@ scroll pages without retaining the skipped prefix.
9797
Numeric range and mixed numeric membership operands are limited to
9898
`+/- (2**53-1)`; integer equality supports the full signed 64-bit range.
9999

100+
## Running integration tests locally
101+
102+
Start a disposable server using the Qdrant version pinned in CI, then run the
103+
integration suite from the `python/` directory:
104+
105+
```bash
106+
docker run -d --rm --name af-qdrant-test -p 127.0.0.1:16333:6333 qdrant/qdrant:v1.16.2
107+
curl --fail --retry 20 --retry-delay 1 --retry-connrefused http://127.0.0.1:16333/readyz
108+
QDRANT_TEST_URL=http://127.0.0.1:16333 uv run --frozen --directory packages/qdrant poe test-integration -p no:pytest-retry
109+
docker stop af-qdrant-test
110+
```
111+
112+
Disabling the retry plugin makes failures visible on the first attempt. To run
113+
only the concurrent-creation cases, append
114+
`-k concurrent_collection_creation_validates_winning_schema` to the test command.
115+
The fixtures create uniquely named collections and delete them after each test.
116+
100117
## Documentation
101118

102119
- [Microsoft Agent Framework](https://learn.microsoft.com/agent-framework/)

‎python/packages/qdrant/agent_framework_qdrant/_vector_store.py‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from __future__ import annotations
66

7+
import asyncio
78
import math
89
from collections.abc import Mapping, Sequence
910
from typing import Any, ClassVar, Generic, cast
@@ -429,6 +430,7 @@ async def collection_exists(self, *, operation_options: Mapping[str, Any] | None
429430
async def ensure_collection_exists(self, *, operation_options: Mapping[str, Any] | None = None) -> None:
430431
"""Create the collection and payload indexes, or validate an existing dense schema."""
431432
options = _validate_operation_options(operation_options, _CREATE_OPTIONS)
433+
creation_conflict = False
432434
if not await self.collection_exists():
433435
vectors = {
434436
field.storage_name or field.name: models.VectorParams(
@@ -445,16 +447,35 @@ async def ensure_collection_exists(self, *, operation_options: Mapping[str, Any]
445447
except UnexpectedResponse as exc:
446448
if exc.status_code != 409:
447449
raise
450+
creation_conflict = True
448451
except AioRpcError as exc:
449452
if exc.code() != StatusCode.ALREADY_EXISTS:
450453
raise
454+
creation_conflict = True
451455
except ValueError as exc:
452456
if not self._is_local or str(exc) != f"Collection {self.collection_name} already exists":
453457
raise
454458
else:
455459
if not created and not await self.collection_exists():
456460
raise IntegrationException(f"Qdrant did not create collection '{self.collection_name}'.")
457-
info = await self.async_client.get_collection(self.collection_name)
461+
attempt = 0
462+
while True:
463+
try:
464+
info = await self.async_client.get_collection(self.collection_name)
465+
break
466+
except (UnexpectedResponse, AioRpcError) as exc:
467+
# Qdrant can report a creation conflict before the winning creator has
468+
# initialized its shards. Only retry that specific readiness failure.
469+
if isinstance(exc, UnexpectedResponse):
470+
not_ready = exc.status_code == 500 and b"0 of 0 read operations failed" in exc.content
471+
else:
472+
not_ready = exc.code() == StatusCode.INTERNAL and "0 of 0 read operations failed" in (
473+
exc.details() or ""
474+
)
475+
if not creation_conflict or not not_ready or attempt >= 5:
476+
raise
477+
await asyncio.sleep(0.05 * 2**attempt)
478+
attempt += 1
458479
configured = info.config.params.vectors
459480
if not isinstance(configured, dict):
460481
raise ValueError("QdrantCollection requires named vectors, not an unnamed-vector collection.")

‎python/packages/qdrant/tests/qdrant/test_collection.py‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,71 @@ async def test_conflict_does_not_hide_missing_collection(definition):
620620
assert result.value is missing
621621

622622

623+
@pytest.mark.parametrize("matching_schema", [True, False])
624+
@pytest.mark.parametrize("transport", ["rest", "grpc"])
625+
async def test_create_conflict_waits_for_readable_schema(collection_factory, client, matching_schema, transport):
626+
collection = collection_factory()
627+
await collection.ensure_collection_exists()
628+
info = await client.get_collection(collection.collection_name)
629+
if not matching_schema:
630+
info.config.params.vectors["dense_text"].size = 4
631+
if transport == "grpc":
632+
conflict = AioRpcError(StatusCode.ALREADY_EXISTS, Metadata(), Metadata(), "collection already exists")
633+
not_ready = AioRpcError(
634+
StatusCode.INTERNAL, Metadata(), Metadata(), "Service internal error: 0 of 0 read operations failed"
635+
)
636+
else:
637+
conflict = UnexpectedResponse(409, "Conflict", b"exists", Headers())
638+
not_ready = UnexpectedResponse(
639+
500,
640+
"Internal Server Error",
641+
b'{"status":{"error":"Service internal error: 0 of 0 read operations failed"}}',
642+
Headers(),
643+
)
644+
with (
645+
patch.object(client, "collection_exists", return_value=False),
646+
patch.object(client, "create_collection", side_effect=conflict),
647+
patch.object(client, "get_collection", side_effect=[not_ready, not_ready, info]) as get_collection,
648+
):
649+
if matching_schema:
650+
await collection.ensure_collection_exists()
651+
else:
652+
with pytest.raises(ValueError, match="does not match"):
653+
await collection.ensure_collection_exists()
654+
assert get_collection.await_count == 3
655+
656+
657+
@pytest.mark.parametrize(
658+
("conflict", "error", "expected_reads"),
659+
[
660+
(True, UnexpectedResponse(500, "Internal Server Error", b"0 of 0 read operations failed", Headers()), 6),
661+
(False, UnexpectedResponse(500, "Internal Server Error", b"0 of 0 read operations failed", Headers()), 1),
662+
(True, UnexpectedResponse(500, "Internal Server Error", b"unrelated server failure", Headers()), 1),
663+
(True, UnexpectedResponse(403, "Forbidden", b"not authorized", Headers()), 1),
664+
(True, AioRpcError(StatusCode.INTERNAL, Metadata(), Metadata(), "0 of 0 read operations failed"), 6),
665+
(False, AioRpcError(StatusCode.INTERNAL, Metadata(), Metadata(), "0 of 0 read operations failed"), 1),
666+
(True, AioRpcError(StatusCode.INTERNAL, Metadata(), Metadata(), "unrelated server failure"), 1),
667+
(True, AioRpcError(StatusCode.INTERNAL, Metadata(), Metadata(), None), 1),
668+
(True, AioRpcError(StatusCode.PERMISSION_DENIED, Metadata(), Metadata(), "not authorized"), 1),
669+
],
670+
)
671+
async def test_collection_read_retries_are_bounded_and_specific(definition, conflict, error, expected_reads):
672+
client = AsyncMock(spec=AsyncQdrantClient)
673+
client.collection_exists.return_value = not conflict
674+
client.create_collection.side_effect = (
675+
AioRpcError(StatusCode.ALREADY_EXISTS, Metadata(), Metadata(), "collection already exists")
676+
if isinstance(error, AioRpcError)
677+
else UnexpectedResponse(409, "Conflict", b"exists", Headers())
678+
)
679+
client.get_collection.side_effect = error
680+
collection = QdrantCollection(dict, definition=definition, collection_name="test", async_client=client)
681+
with pytest.raises(type(error)) as result:
682+
await collection.ensure_collection_exists()
683+
assert result.value is error
684+
assert client.get_collection.await_count == expected_reads
685+
assert client.create_collection.await_count == int(conflict)
686+
687+
623688
@pytest.mark.parametrize("configuration", ["uint8", "flat"])
624689
async def test_existing_vector_datatype_and_index_mismatch(collection_factory, client, configuration):
625690
definition = VectorStoreCollectionDefinition([

0 commit comments

Comments
 (0)