Files
qdrant-client/qdrant_client
shashvat singhamandGeorge Panchuk 1860632b68 fix: validate sparse vectors with raises instead of asserts (#1343)
* fix: validate sparse vectors with raises instead of asserts

validate_sparse_vector checks user input, but does so with `assert`.
python -O strips assert statements, so under -O the checks disappear
entirely and a malformed sparse vector is accepted into a local
collection:

    $ python -O
    >>> client.upsert("t", [PointStruct(id=1, vector={"s": SparseVector(
    ...     indices=[1, 1, 1], values=[1.0, 1.0, 1.0])})])
    # accepted

The damage surfaces later rather than at the point of the mistake. A
vector whose indices and values have different lengths is stored, and a
subsequent query raises from deep inside the search path:

    >>> client.query_points("t", query=SparseVector(indices=[3], values=[1.0]), using="s")
    IndexError: list index out of range

Raise ValueError instead. This also stops user input being reported as
an AssertionError, which is inconsistent with the rest of the client.

* refactor: replace assert error with value error

* fix: validate vectors before write

* fix: add validation for update vectors and batch update points

* fix: validate vector dimensions and batch arguments before write

---------

Co-authored-by: George Panchuk <george.panchuk@qdrant.tech>
2026-09-16 00:27:57 +07:00
..
2025-12-12 17:21:08 +07:00
2025-12-12 17:21:08 +07:00
2023-10-16 19:01:01 +02:00