redis/redis-py · error · DataError

Both vector and element must be provided

Error message

Both vector and element must be provided

What it means

Raised by VADD when either vector is empty/falsy or element is empty/falsy. Both a vector (the float list / FP32 bytes) and an element name are required to add an entry to a vector set.

Solutions

  1. Ensure vector is a non-empty list[float] or non-empty bytes before calling vadd.
  2. Ensure element is a non-empty string.
  3. Skip the add when either is missing, or raise a clearer error upstream.

Example fix

// before
client.vadd(key, vector=[], element='e1')
// after
if vector and element:
    client.vadd(key, vector=vector, element=element)
Defensive patterns

Strategy: validation

Validate before calling

if not vector or not element:
    raise ValueError('vector and element are required')
client.vadd(key, vector=vector, element=element)

Type guard

def is_valid_vadd_input(vector, element) -> bool:
    return bool(vector) and bool(element) and isinstance(element, str)

Try / catch

from redis.exceptions import DataError
try:
    client.vadd(key, vector=vector, element=element)
except DataError:
    pass  # skip invalid entries

Prevention

When it happens

Trigger: Calling client.vsim/vadd with vector=[] or vector=None, or element='' / element=None. Note: it triggers when NOT vector OR NOT element (truthiness), so a 0-length vector or empty element string both qualify.

Common situations: Loading vectors from a source that yielded an empty list. Empty element identifier from a join that matched nothing. None leaking through from an optional field.

Related errors


AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10). Data as JSON: /api/errors/e97c562c7abe9a08. Report an issue: GitHub.

Appendix: source

Thrown at redis/commands/vectorset/commands.py:141

                If not provided, int8 quantization is used.
                The options are:
                - NOQUANT: No quantization
                - BIN: Binary quantization
                - Q8: Signed 8-bit quantization

        ``ef`` sets the exploration factor to use.
                If not provided, the default exploration factor is used.

        ``attributes`` is a dictionary or json string that contains the attributes to set for the vector.
                If not provided, no attributes are set.

        ``numlinks`` sets the number of links to create for the vector.
                If not provided, the default number of links is used.

        For more information, see https://redis.io/commands/vadd.
        """
        if not vector or not element:
            raise DataError("Both vector and element must be provided")

        pieces = []
        if reduce_dim:
            pieces.extend(["REDUCE", reduce_dim])

        values_pieces = []
        if isinstance(vector, bytes):
            values_pieces.extend(["FP32", vector])
        else:
            values_pieces.extend(["VALUES", len(vector)])
            values_pieces.extend(vector)
        pieces.extend(values_pieces)

        pieces.append(element)

        if cas:
            pieces.append("CAS")

View on GitHub (pinned to 6a6b581b48)