mem0ai/mem0 · error · ValueError

Vectors, payloads, and IDs must have the same length

Error message

Vectors, payloads, and IDs must have the same length

What it means

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.

Source

Thrown at mem0/vector_stores/faiss.py:359

        """
        Insert vectors into a collection.

        Args:
            vectors (List[list]): List of vectors to insert.
            payloads (Optional[List[Dict]], optional): List of payloads corresponding to vectors. Defaults to None.
            ids (Optional[List[str]], optional): List of IDs corresponding to vectors. Defaults to None.
        """
        if self.index is None:
            raise ValueError("Collection not initialized. Call create_col first.")

        if ids is None:
            ids = [str(uuid.uuid4()) for _ in range(len(vectors))]

        if payloads is None:
            payloads = [{} for _ in range(len(vectors))]

        if len(vectors) != len(ids) or len(vectors) != len(payloads):
            raise ValueError("Vectors, payloads, and IDs must have the same length")

        vectors_np = np.array(vectors, dtype=np.float32)

        if self._should_normalize():
            faiss.normalize_L2(vectors_np)

        self.index.add(vectors_np)

        starting_idx = len(self.index_to_id)
        for i, (vector_id, payload) in enumerate(zip(ids, payloads)):
            self.docstore[vector_id] = payload.copy()
            self.index_to_id[starting_idx + i] = vector_id

        self._save()

        logger.info(f"Inserted {len(vectors)} vectors into collection {self.collection_name}")

    def search(

View on GitHub (pinned to 001c235229)

Solutions

  1. Assert equal lengths before calling insert
  2. Generate ids/payloads from the vectors list itself (len(vectors)) so they cannot drift
  3. Log the three lengths at the call site when the mismatch is intermittent

Example fix

# before
vs.insert(vectors=vecs, payloads=payloads, ids=ids)  # lengths differ

# after
assert len(vecs) == len(payloads) == len(ids), (len(vecs), len(payloads), len(ids))
vs.insert(vectors=vecs, payloads=payloads, ids=ids)
Defensive patterns

Strategy: validation

Validate before calling

assert len(vectors) == len(payloads or vectors) == len(ids or vectors), 'length mismatch'

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/73189a6a32c9ebc1. Report an issue: GitHub.