{"record":{"id":"e97c562c7abe9a08","repo":"redis/redis-py","slug":"both-vector-and-element-must-be-provided","errorCode":null,"errorMessage":"Both vector and element must be provided","messagePattern":"Both vector and element must be provided","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/commands/vectorset/commands.py","lineNumber":141,"sourceCode":"                If not provided, int8 quantization is used.\n                The options are:\n                - NOQUANT: No quantization\n                - BIN: Binary quantization\n                - Q8: Signed 8-bit quantization\n\n        ``ef`` sets the exploration factor to use.\n                If not provided, the default exploration factor is used.\n\n        ``attributes`` is a dictionary or json string that contains the attributes to set for the vector.\n                If not provided, no attributes are set.\n\n        ``numlinks`` sets the number of links to create for the vector.\n                If not provided, the default number of links is used.\n\n        For more information, see https://redis.io/commands/vadd.\n        \"\"\"\n        if not vector or not element:\n            raise DataError(\"Both vector and element must be provided\")\n\n        pieces = []\n        if reduce_dim:\n            pieces.extend([\"REDUCE\", reduce_dim])\n\n        values_pieces = []\n        if isinstance(vector, bytes):\n            values_pieces.extend([\"FP32\", vector])\n        else:\n            values_pieces.extend([\"VALUES\", len(vector)])\n            values_pieces.extend(vector)\n        pieces.extend(values_pieces)\n\n        pieces.append(element)\n\n        if cas:\n            pieces.append(\"CAS\")\n","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/commands/vectorset/commands.py#L123-L159","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure vector is a non-empty list[float] or non-empty bytes before calling vadd.","Ensure element is a non-empty string.","Skip the add when either is missing, or raise a clearer error upstream."],"exampleFix":"// before\nclient.vadd(key, vector=[], element='e1')\n// after\nif vector and element:\n    client.vadd(key, vector=vector, element=element)","handlingStrategy":"validation","validationCode":"if not vector or not element:\n    raise ValueError('vector and element are required')\nclient.vadd(key, vector=vector, element=element)","typeGuard":"def is_valid_vadd_input(vector, element) -> bool:\n    return bool(vector) and bool(element) and isinstance(element, str)","tryCatchPattern":"from redis.exceptions import DataError\ntry:\n    client.vadd(key, vector=vector, element=element)\nexcept DataError:\n    pass  # skip invalid entries","preventionTips":["Validate embedding length and element name before calling vadd.","Filter out empty/None records in batch ingestion loops."],"tags":["vectorset","vadd","argument-validation"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}