{"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/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/vectorset/commands.py#L123-L159","documentation":"Raised by VectorSetCommands.vadd when either vector is falsy (empty list or empty bytes) or element is falsy (empty string). VADD needs both a real vector and a non-empty element identifier. The check is 'not vector or not element', so a zero-length vector or blank element name is rejected before the command is sent.","triggerScenarios":"client.vadd('set', [], 'elem') (empty vector), client.vadd('set', b'', 'elem') (empty bytes), or client.vadd('set', [1,2], '') (empty element name). Also when a computed vector came back empty from an embedding model.","commonSituations":"Embedding pipeline returned an empty vector (model failure, empty input text); generating element names from data that produced a blank; passing bytes that happened to be empty.","solutions":["Ensure the vector is non-empty: a list of floats or non-empty bytes of the right dimensionality.","Ensure element is a non-empty string identifier.","Validate embeddings upstream: if not vector: skip/log instead of calling vadd."],"exampleFix":"// before\nclient.vadd('set', embedding, name)  # embedding == []\n// after\nif embedding:\n    client.vadd('set', embedding, name or 'default')","handlingStrategy":"validation","validationCode":"def safe_vadd(client, key, vector, element, **kw):\n    if not vector or not element:\n        return None\n    return client.vadd(key, vector, element, **kw)","typeGuard":"def vadd_inputs_valid(vector, element) -> bool:\n    return bool(vector) and bool(element)","tryCatchPattern":"try:\n    client.vadd('set', vec, name)\nexcept Exception as e:\n    if 'must be provided' in str(e):\n        pass  # skip empty embeddings\n    else:\n        raise","preventionTips":["Validate embeddings are non-empty before calling vadd.","Ensure element identifiers are non-empty strings.","Log/skip on empty embedding rather than erroring."],"tags":["vectorset","vadd","argument-error","validation"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}