Skip to content

fix(schema): enforce INT8/UINT8 range check on list vectors - #805

Draft
vishal-bala wants to merge 1 commit into
mainfrom
fix/int8-uint8-vector-range-check
Draft

vishal-bala wants to merge 1 commit into
mainfrom
fix/int8-uint8-vector-range-check

Conversation

@vishal-bala

Copy link
Copy Markdown
Collaborator

Motivation

The INT8/UINT8 range check in the vector validator never runs. It compared str(datatype).upper() with "INT8" and "UINT8". datatype is a VectorDataType(str, Enum) member, though, and str() on a str-mixin Enum returns "VectorDataType.INT8", so neither branch ever matched. On every supported Python version, a JSON schema with an int8 vector field therefore accepts {"v": [999, -999]} through validate_object.

Changes

  • redisvl/schema/validation.py: the vector validator now compares enum members directly (datatype == VectorDataType.INT8), as _map_field_to_pydantic_type in the same module already does. I flattened the nested if that the string comparison needed.
  • tests/unit/test_validation.py: TestIntegerVectorRangeValidation covers the boundary values on both sides for INT8 (-128, 127) and UINT8 (0, 255), plus the reported [999, -999] repro, on a JSON-storage schema. Hash storage takes bytes and is unaffected.

I searched redisvl/ for other str(<enum member>) comparisons and found none. mcp/tools/upsert.py:_vector_dtype unwraps .value first.

Release Notes

Schema validation now enforces the integer vector ranges it always claimed to. validate_object, load(..., validate_on_load=True) and the MCP upsert tool reject JSON int8 vectors with elements outside -128..127, and uint8 vectors outside 0..255. These inputs used to pass validation silently.

Reviewer Brief

Start here: redisvl/schema/validation.py, _validate_vector inside make_vector_validator. The whole fix is its two member comparisons.

Not verified: Redis's documentation confirms that INT8/UINT8 vector types exist, but I found no page that states their element ranges. -128..127 and 0..255 are the standard 8-bit ranges, not ones checked against Redis docs. I did not run integration tests (validate_on_load and the MCP upsert path) locally. CI runs them.

Beyond CI: the five new rejection cases fail against the code before the fix, and pass with it.

Reviewed 0e525da2 · Claude Code (claude-opus-5-5) · lenses: correctness, security, design, tests, docs, Redis behaviour

The vector validator compared `str(datatype).upper()` against "INT8" and
"UINT8", but `str()` on a str-mixin Enum member returns
"VectorDataType.INT8", so neither branch ever matched and out-of-range
values (e.g. [999, -999] for an int8 field) passed validation on every
Python version. Compare enum members directly, as `_map_field_to_pydantic_type`
already does.

Behaviour change: validate_object (and load with validate_on_load=True)
now rejects JSON int8 vectors outside -128..127 and uint8 vectors outside
0..255, which it previously accepted.
@vishal-bala vishal-bala added the auto:patch Increment the patch version when merged label Oct 30, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto:patch Increment the patch version when merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant