microsoft/semantic-kernel · error · ServiceResourceNotFoundError

Collection "{collection_name}" does not exist

Error message

Collection "{collection_name}" does not exist

What it means

Raised by RedisMemoryStore.upsert() when does_collection_exist(collection_name) returns False, i.e. FT.INFO on that index raises ResponseError. In Redis a 'collection' is the search index, so absence means create_collection() (create_index) never ran or was dropped. ServiceResourceNotFoundError with double-quoted collection name.

Source

Thrown at python/semantic_kernel/connectors/memory_stores/redis/redis_memory_store.py:207

    async def upsert(self, collection_name: str, record: MemoryRecord) -> str:
        """Upsert a memory record into the data store.

        Does not guarantee that the collection exists.
            * If the record already exists, it will be updated.
            * If the record does not exist, it will be created.

        Note: if the record do not have the same dimensionality configured for the collection,
        it will not be detected to belong to the collection in Redis.

        Args:
            collection_name (str): Name for a collection of embeddings
            record (MemoryRecord): Memory record to upsert

        Returns:
            str: Redis key associated with the upserted memory record
        """
        if not await self.does_collection_exist(collection_name):
            raise ServiceResourceNotFoundError(f'Collection "{collection_name}" does not exist')

        # Typical Redis key structure: collection_name:{some identifier}
        record._key = get_redis_key(collection_name, record._id)

        # Overwrites previous data or inserts new key if not present
        # Index registers any hash matching its schema and prefixed with collection_name:
        try:
            self._database.hset(
                record._key,
                mapping=serialize_record_to_redis(record, self._vector_type),
            )
            return record._key
        except Exception as e:
            raise ServiceResponseException("Could not upsert messages.") from e

    async def upsert_batch(self, collection_name: str, records: list[MemoryRecord]) -> list[str]:
        """Upserts a group of memory records into the data store.

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Call `await store.create_collection(collection_name)` before the first upsert.
  2. Pre-check does_collection_exist() and create on demand.
  3. Confirm the Redis instance has RediSearch and the index is listed in FT._LIST (get_collections()).
  4. Migrate to the non-deprecated RedisStore/RedisHashsetCollection for managed lifecycle.

Example fix

// before
key = await store.upsert('mycol', record)
// after
if not await store.does_collection_exist('mycol'):
    await store.create_collection('mycol')
key = await store.upsert('mycol', record)
Defensive patterns

Strategy: validation

Validate before calling

if not await store.does_collection_exist(collection_name):
    await store.create_collection(collection_name)
key = await store.upsert(collection_name, record)

Try / catch

from semantic_kernel.exceptions import ServiceResourceNotFoundError
try:
    key = await store.upsert(collection_name, record)
except ServiceResourceNotFoundError:
    await store.create_collection(collection_name)
    key = await store.upsert(collection_name, record)

Prevention

When it happens

Trigger: Calling `await store.upsert(collection_name, record)` before create_collection(), or after the index was dropped/deleted. Because hashes are stored by key prefix, upsert refuses to write without a backing index to avoid orphaned, unindexed data.

Common situations: Skipping create_collection() on a fresh Redis; wrong collection name; index dropped by another process; RediSearch module restarted and lost in-memory index metadata.

Related errors


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