{"record":{"id":"9de637bb5fd3e408","repo":"mem0ai/mem0","slug":"collection-not-initialized-call-create-col-first","errorCode":null,"errorMessage":"Collection not initialized. Call create_col first.","messagePattern":"Collection not initialized\\. Call create_col first\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/vector_stores/faiss.py","lineNumber":350,"sourceCode":"\n        return self\n\n    def insert(\n        self,\n        vectors: List[list],\n        payloads: Optional[List[Dict]] = None,\n        ids: Optional[List[str]] = None,\n    ):\n        \"\"\"\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)","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/faiss.py#L332-L368","documentation":"Raised by FAISS.insert() when self.index is None, i.e. no collection was created or loaded before writing. Mem0's FAISS store requires create_col() (or a successful load) to build the underlying faiss.Index before any vectors can be added. ValueError.","triggerScenarios":"Constructing FAISS with no existing on-disk store (fresh path) and calling insert()/add() before create_col(); or a load failure that silently left self.index None (the broad except in __init__ resets state instead of raising).","commonSituations":"Using the FAISS store directly instead of through Memory, which calls create_col automatically; a corrupted load path that swallowed an exception (logger.warning then empty dicts), leaving the object half-initialized.","solutions":["Call create_col(vectors dimension) once before the first insert","Prefer the Memory/MemoryConfig pipeline, which initializes the collection for you","If loading an existing store, check logs for 'Failed to load FAISS index' — the initializer may have silently reset state, meaning the on-disk data needs fixing first"],"exampleFix":"# before\nvs.insert(vectors=[...])  # ValueError: Collection not initialized\n\n# after\nvs.create_col(len(embedding))\nvs.insert(vectors=[...], payloads=[...], ids=[...])","handlingStrategy":"validation","validationCode":"if vs.index is None:\n    vs.create_col(dimension)  # dimension = len(embedding)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always call create_col(dim) before the first insert","Watch for 'Failed to load FAISS index' warnings — the init fallback leaves index None","Prefer the Memory API, which handles collection creation"],"tags":["faiss","vector-store","initialization","lifecycle"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}