mirror of
https://github.com/qdrant/qdrant.git
synced 2026-09-21 13:37:46 -05:00
* docs(schema): declare enforced 1..=65536 bound on VectorParams.size The REST layer enforces an upper bound of 65536 on VectorParams.size via a custom validator (validate_nonzerou64_range_min_1_max_65536), but custom validators contribute no bounds to the generated JSON schema - so the published OpenAPI document only declared minimum: 1, while DenseVectorConfig.size already documented both bounds. Add an explicit #[schemars(range(min = 1, max = 65536))] attribute so clients validating requests against the schema see the same contract the server enforces, update docs/redoc/master/openapi.json accordingly, and pin the bound with a unit test asserting the generated schema. Fixes #9942 * test(openapi): accept documented size bound as a rejection path test_vector_dimension_limit asserted that an oversized VectorParams.size reaches the server and returns the exact runtime 422 message. Now that the enforced 1..=65536 bound is documented in the served OpenAPI schema (#9942), request_with_validation rejects such payloads client-side before sending. Accept either layer: a client-side jsonschema.ValidationError or the server-side validation error. * test(openapi): handle both rejection layers in dimension limit pytest.raises only covered the client-side jsonschema rejection; if the request reached the server instead, the test would fail on an unhandled response. Use try/except around request_with_validation and assert the server-side status and exact error message in the else branch. * test(openapi): assert exact HTTP 422 on server-side rejection A broad not-ok check would pass on any error status carrying the same error text; pin the documented contract to 422. * refactor(tests): address review feedback Remove the unit test asserting the generated VectorParams schema shape - it only restates the schemars attribute and adds maintenance cost. Reduce test_vector_dimension_limit to its actual contract: an oversized dimension is rejected by the documented OpenAPI schema before the request is sent.
66 lines
1.7 KiB
Python
66 lines
1.7 KiB
Python
import jsonschema
|
|
import pytest
|
|
|
|
from .helpers.collection_setup import drop_collection
|
|
from .helpers.helpers import request_with_validation
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def setup(collection_name):
|
|
yield
|
|
drop_collection(collection_name=collection_name)
|
|
|
|
|
|
# Tests vulnerability related limits, see: <https://github.com/qdrant/qdrant/pull/2544>
|
|
def test_vector_dimension_limit(collection_name):
|
|
dim_max = 65536
|
|
|
|
drop_collection(collection_name)
|
|
|
|
response = request_with_validation(
|
|
api='/collections/{collection_name}',
|
|
method="PUT",
|
|
path_params={'collection_name': collection_name},
|
|
body={
|
|
"vectors": {
|
|
"size": dim_max,
|
|
"distance": "Dot",
|
|
},
|
|
}
|
|
)
|
|
assert response.ok
|
|
|
|
drop_collection(collection_name)
|
|
|
|
# An oversized dimension must be rejected by the documented schema
|
|
# (see #9942): request_with_validation raises before sending.
|
|
with pytest.raises(jsonschema.exceptions.ValidationError):
|
|
request_with_validation(
|
|
api='/collections/{collection_name}',
|
|
method="PUT",
|
|
path_params={'collection_name': collection_name},
|
|
body={
|
|
"vectors": {
|
|
"size": dim_max + 1,
|
|
"distance": "Dot",
|
|
},
|
|
}
|
|
)
|
|
|
|
drop_collection(collection_name)
|
|
|
|
response = request_with_validation(
|
|
api='/collections/{collection_name}',
|
|
method="PUT",
|
|
path_params={'collection_name': collection_name},
|
|
body={
|
|
"vectors": {
|
|
"size": 1,
|
|
"distance": "Dot",
|
|
},
|
|
}
|
|
)
|
|
assert response.ok
|
|
|
|
drop_collection(collection_name)
|