{"record":{"id":"73189a6a32c9ebc1","repo":"mem0ai/mem0","slug":"vectors-payloads-and-ids-must-have-the-same-leng","errorCode":null,"errorMessage":"Vectors, payloads, and IDs must have the same length","messagePattern":"Vectors, payloads, and IDs must have the same length","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/vector_stores/faiss.py","lineNumber":359,"sourceCode":"        \"\"\"\n        Insert vectors into a collection.\n\n        Args:\n            vectors (List[list]): List of vectors to insert.\n            payloads (Optional[List[Dict]], optional): List of payloads corresponding to vectors. Defaults to None.\n            ids (Optional[List[str]], optional): List of IDs corresponding to vectors. Defaults to None.\n        \"\"\"\n        if self.index is None:\n            raise ValueError(\"Collection not initialized. Call create_col first.\")\n\n        if ids is None:\n            ids = [str(uuid.uuid4()) for _ in range(len(vectors))]\n\n        if payloads is None:\n            payloads = [{} for _ in range(len(vectors))]\n\n        if len(vectors) != len(ids) or len(vectors) != len(payloads):\n            raise ValueError(\"Vectors, payloads, and IDs must have the same length\")\n\n        vectors_np = np.array(vectors, dtype=np.float32)\n\n        if self._should_normalize():\n            faiss.normalize_L2(vectors_np)\n\n        self.index.add(vectors_np)\n\n        starting_idx = len(self.index_to_id)\n        for i, (vector_id, payload) in enumerate(zip(ids, payloads)):\n            self.docstore[vector_id] = payload.copy()\n            self.index_to_id[starting_idx + i] = vector_id\n\n        self._save()\n\n        logger.info(f\"Inserted {len(vectors)} vectors into collection {self.collection_name}\")\n\n    def search(","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/faiss.py#L341-L377","documentation":"Raised by FAISS.insert() when vectors, payloads, and ids lists differ in length. Rows are inserted positionally (zip of ids and payloads against vectors), so mismatched lengths would silently drop data; mem0 validates and raises ValueError instead.","triggerScenarios":"Calling insert() with 3 vectors but 2 payloads, or passing ids of the wrong length; commonly when payloads is defaulted to a single dict or ids are generated for a subset of rows by upstream code.","commonSituations":"Batching bugs in caller code (e.g. filtering some vectors but not the parallel metadata lists); embedding calls that return fewer vectors than inputs; off-by-one slicing.","solutions":["Assert equal lengths before calling insert","Generate ids/payloads from the vectors list itself (len(vectors)) so they cannot drift","Log the three lengths at the call site when the mismatch is intermittent"],"exampleFix":"# before\nvs.insert(vectors=vecs, payloads=payloads, ids=ids)  # lengths differ\n\n# after\nassert len(vecs) == len(payloads) == len(ids), (len(vecs), len(payloads), len(ids))\nvs.insert(vectors=vecs, payloads=payloads, ids=ids)","handlingStrategy":"validation","validationCode":"assert len(vectors) == len(payloads or vectors) == len(ids or vectors), 'length mismatch'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive ids and payloads from the vectors list so lengths cannot diverge","Validate batch tuples at the boundary where they are constructed"],"tags":["faiss","vector-store","input-validation","batching"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}