mem0ai/mem0 · error · ValueError
Collection not initialized. Call create_col first.
Error message
Collection not initialized. Call create_col first.
What it means
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.
Source
Thrown at mem0/vector_stores/faiss.py:350
return self
def insert(
self,
vectors: List[list],
payloads: Optional[List[Dict]] = None,
ids: Optional[List[str]] = None,
):
"""
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)View on GitHub (pinned to 001c235229)
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
Example fix
# before vs.insert(vectors=[...]) # ValueError: Collection not initialized # after vs.create_col(len(embedding)) vs.insert(vectors=[...], payloads=[...], ids=[...])
Defensive patterns
Strategy: validation
Validate before calling
if vs.index is None:
vs.create_col(dimension) # dimension = len(embedding) Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Failed to auto-detect embedding dimension from provider '${t
- Invalid distance_strategy. Must be one of: 'euclidean', 'inn
- Extra fields not allowed: {', '.join(extra_fields)}. Please
- Invalid docstore format: expected tuple of (docstore, index_
- Invalid docstore format: docstore must be a dict
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/9de637bb5fd3e408.
Report an issue: GitHub.