microsoft/semantic-kernel · error · ServiceResourceNotFoundError

Collection '{collection_name}' does not exist

Error message

Collection '{collection_name}' does not exist

What it means

Raised as a ServiceResourceNotFoundError in ChromaMemoryStore.upsert when get_collection returns None, meaning no Chroma collection with the given name exists. Chroma requires a collection to exist before records can be added; upsert does not auto-create it.

Source

Thrown at python/semantic_kernel/connectors/memory_stores/chroma/chroma_memory_store.py:159

        Returns:
            bool: True if the collection exists; otherwise, False.
        """
        return await self.get_collection(collection_name) is not None

    async def upsert(self, collection_name: str, record: MemoryRecord) -> str:
        """Upsert a single MemoryRecord.

        Args:
            collection_name (str): The name of the collection to upsert the record into.
            record (MemoryRecord): The record to upsert.

        Returns:
            List[str]: The unique database key of the record.
        """
        collection = await self.get_collection(collection_name)
        if collection is None:
            raise ServiceResourceNotFoundError(f"Collection '{collection_name}' does not exist")

        record._key = record._id
        metadata = {
            "timestamp": record._timestamp or "",
            "is_reference": str(record._is_reference),
            "external_source_name": record._external_source_name or "",
            "description": record._description or "",
            "additional_metadata": record._additional_metadata or "",
            "id": record._id or "",
        }

        collection.add(
            metadatas=metadata,
            # by providing embeddings, we can skip the chroma's embedding function call
            embeddings=record.embedding.tolist(),
            documents=record._text,
            ids=record._key,
        )

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Call await store.create_collection(collection_name) before upserting, or guard with await store.does_collection_exist(collection_name).
  2. Verify the collection name matches exactly what was passed to create_collection.
  3. If using persistence, ensure persist_directory points to the same path across runs.
  4. Wrap the upsert call in try/except ServiceResourceNotFoundError and create-then-retry.

Example fix

// before
await store.upsert('docs', record)  # ServiceResourceNotFoundError
// after
if not await store.does_collection_exist('docs'):
    await store.create_collection('docs')
await store.upsert('docs', record)
Defensive patterns

Strategy: validation

Validate before calling

async def ensure_collection(store, name: str) -> None:
    if not await store.does_collection_exist(name):
        await store.create_collection(name)

await ensure_collection(store, 'docs')
await store.upsert('docs', record)

Try / catch

from semantic_kernel.exceptions import ServiceResourceNotFoundError

try:
    await store.upsert('docs', record)
except ServiceResourceNotFoundError:
    await store.create_collection('docs')
    await store.upsert('docs', record)

Prevention

When it happens

Trigger: Calling await store.upsert('my_collection', record) before await store.create_collection('my_collection'). Also if the collection name casing differs (Chroma lowercases internally) or if a persisted store lost its data directory.

Common situations: Skipping the create_collection step in a fresh run. Typo or case mismatch in the collection name. Using an ephemeral Chroma client (no persist_directory) so collections vanish on restart. Calling upsert on a collection that was deleted.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/8fb8c2e85dbcae31. Report an issue: GitHub.