{"record":{"id":"1c18e2a83821bdd4","repo":"mem0ai/mem0","slug":"vector-at-index-idx-is-null-this-usually-means","errorCode":null,"errorMessage":"Vector at index {idx} is null. This usually means the embedding model failed to generate an embedding. Check that your embedding model is configured correctly and returning valid vectors.","messagePattern":"Vector at index (.+?) is null\\. This usually means the embedding model failed to generate an embedding\\. Check that your embedding model is configured correctly and returning valid vectors\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/vector_stores/opensearch.py","lineNumber":164,"sourceCode":"                except Exception:\n                    retry_count += 1\n                    if retry_count == max_retries:\n                        raise TimeoutError(f\"Index {name} creation timed out after {max_retries} seconds\")\n                    time.sleep(0.5)\n\n    def insert(\n        self, vectors: List[List[float]], payloads: Optional[List[Dict]] = None, ids: Optional[List[str]] = None\n    ) -> List[OutputData]:\n        \"\"\"Insert vectors into the index.\"\"\"\n        if not ids:\n            ids = [str(i) for i in range(len(vectors))]\n\n        if payloads is None:\n            payloads = [{} for _ in range(len(vectors))]\n\n        for idx, vec in enumerate(vectors):\n            if vec is None:\n                raise ValueError(\n                    f\"Vector at index {idx} is null. \"\n                    f\"This usually means the embedding model failed to generate an embedding. \"\n                    f\"Check that your embedding model is configured correctly and returning valid vectors.\"\n                )\n            if len(vec) == 0:\n                raise ValueError(\n                    f\"Vector at index {idx} is empty. \"\n                    f\"Expected a vector of dimension {self.embedding_model_dims}, got an empty vector.\"\n                )\n            if len(vec) != self.embedding_model_dims:\n                raise ValueError(\n                    f\"Vector at index {idx} has dimension {len(vec)}, \"\n                    f\"but the index '{self.collection_name}' expects dimension {self.embedding_model_dims}. \"\n                    f\"Ensure your embedding model's output dimensions match the vector store configuration.\"\n                )\n\n        results = []\n        for i, (vec, id_) in enumerate(zip(vectors, ids)):","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/opensearch.py#L146-L182","documentation":"insert() in the OpenSearch store rejects a None entry in the vectors list before writing anything. A None vector means the embedding model returned nothing for that text (API failure silently swallowed, wrong key, empty input), and indexing it would corrupt the store's vector field.","triggerScenarios":"Calling add()/insert where the embedder returned None for one of the texts: embedding API errors swallowed by a wrapper, mismatched batch counts, or a stub embedder in tests returning None.","commonSituations":"Embedding provider outage or rate-limit where the client returns None instead of raising; custom embedding classes not implementing embed() for all inputs; blank documents passed through the memory pipeline.","solutions":["Fix the embedding step so it either returns a real vector or raises — never None","Check embedding provider credentials/quota if vectors come back None intermittently","Pre-validate: assert all(v is not None for v in vectors) with the index of the offender logged before insert"],"exampleFix":"# before\nstore.insert(vectors=[v1, None, v3], payloads=ps, ids=ids)\n\n# after\nbad = [i for i, v in enumerate(vectors) if v is None]\nif bad:\n    raise ValueError(f\"embeddings missing at {bad}; check the embedder\")\nstore.insert(vectors=vectors, payloads=ps, ids=ids)","handlingStrategy":"validation","validationCode":"missing = [i for i, v in enumerate(vectors) if v is None]\nif missing:\n    raise ValueError(f\"embedding model returned None at positions {missing}\")\nstore.insert(vectors=vectors, payloads=payloads, ids=ids)","typeGuard":"def all_embeddings_present(vectors) -> bool:\n    return all(v is not None for v in vectors)","tryCatchPattern":"try:\n    store.insert(vectors, payloads, ids)\nexcept ValueError as e:\n    if \"is null\" in str(e):\n        idx = int(str(e).split(\"index \")[1].split(\" is\")[0])\n        vectors[idx] = embedder.embed(texts[idx])  # re-embed the failure\n        store.insert(vectors, payloads, ids)\n    else:\n        raise","preventionTips":["Make the embedding wrapper raise on provider errors instead of returning None","Log and drop inputs the embedder cannot handle before batching","Add a pre-insert assertion in a shared helper so every insert path is guarded"],"tags":["opensearch","embeddings","validation","data-integrity"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}