{"record":{"id":"85405548f60963ba","repo":"headroomlabs-ai/headroom","slug":"memory-memory-id-has-no-embedding","errorCode":null,"errorMessage":"Memory {memory.id} has no embedding","messagePattern":"Memory (.+?) has no embedding","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"headroom/memory/adapters/hnsw.py","lineNumber":334,"sourceCode":"    def size(self) -> int:\n        \"\"\"Return the number of vectors currently indexed.\"\"\"\n        with self._lock:\n            return len(self._memory_to_hnsw)\n\n    async def index(self, memory: Memory) -> None:\n        \"\"\"Index a memory's embedding for similarity search.\n\n        The memory must have an embedding set. If max_entries is set and\n        the limit is reached, low-importance entries are evicted.\n\n        Args:\n            memory: The memory to index.\n\n        Raises:\n            ValueError: If the memory has no embedding or wrong dimension.\n        \"\"\"\n        if memory.embedding is None:\n            raise ValueError(f\"Memory {memory.id} has no embedding\")\n\n        embedding = np.asarray(memory.embedding, dtype=np.float32)\n        if embedding.shape[0] != self._dimension:\n            raise ValueError(\n                f\"Embedding dimension {embedding.shape[0]} does not match \"\n                f\"index dimension {self._dimension}\"\n            )\n\n        with self._lock:\n            # Check if already indexed - update if so\n            if memory.id in self._memory_to_hnsw:\n                await self._update_embedding_internal(memory.id, embedding)\n                # Update metadata\n                self._metadata[memory.id] = IndexedMemoryMetadata.from_memory(memory)\n            else:\n                # Evict if at capacity (before adding new entry)\n                if self._max_entries is not None:\n                    current_size = len(self._memory_to_hnsw)","sourceCodeStart":316,"sourceCodeEnd":352,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/headroom/memory/adapters/hnsw.py#L316-L352","documentation":"Raised by HNSWVectorIndex.add_memory (or add) when the Memory object passed in has memory.embedding set to None. The HNSW index only stores pre-computed vectors, so it refuses to index a memory that lacks one. Embedding must be produced by an external Embedder before indexing.","triggerScenarios":"Calling index.add_memory(memory) on a Memory that was never run through an Embedder; embedding a memory asynchronously and indexing before the embedding task finishes; loading memories from a store that did not persist embeddings.","commonSituations":"Pipeline ordering bugs where embed() and index() run in the wrong order; memories created from plain text and passed directly to the vector index; partial deserialization where the embedding column was null.","solutions":["Run the memory through your Embedder (e.g. memory.embedding = await embedder.embed(memory.content)) before calling add_memory.","Check memory.embedding is not None before indexing and route un-embedded memories to an embedding step.","If embeddings are generated in a background task, await its completion before the index call."],"exampleFix":"// before\nawait index.add_memory(memory)  # memory.embedding is None\n\n// after\nif memory.embedding is None:\n    memory.embedding = await embedder.embed(memory.content)\nawait index.add_memory(memory)","handlingStrategy":"validation","validationCode":"if memory.embedding is None:\n    memory.embedding = await embedder.embed(memory.content)\nawait index.add_memory(memory)","typeGuard":"def has_embedding(m: Memory) -> bool:\n    return m.embedding is not None","tryCatchPattern":"try:\n    await index.add_memory(memory)\nexcept ValueError as e:\n    if \"no embedding\" in str(e):\n        memory.embedding = await embedder.embed(memory.content)\n        await index.add_memory(memory)\n    else:\n        raise","preventionTips":["Make embedding a mandatory step in the ingest pipeline before any index call.","Use a type hint MemoryWithEmbedding (NewType) to distinguish embedded memories in code."],"tags":["hnsw","embedding","validation","vector-index"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}