microsoft/semantic-kernel · error · ServiceResourceNotFoundError
Collection {collection_name} does not exist, cannot insert.
Error message
Collection {collection_name} does not exist, cannot insert. What it means
Raised by USearchMemoryStore.upsert_batch (ServiceResourceNotFoundError) when the target collection is not in `self._collections`. The message says 'cannot insert' because upsert first removes existing labels then adds — so a missing collection is rejected before any index mutation. The name is matched case-insensitively (lowercased).
Source
Thrown at python/semantic_kernel/connectors/memory_stores/usearch/usearch_memory_store.py:332
Args:
collection_name (str): Name of the collection to search within.
records (List[MemoryRecord]): Records to upsert.
compact (bool, optional): Removes links to removed nodes (expensive). Defaults to False.
copy (bool, optional): Should the index store a copy of vectors. Defaults to True.
threads (int, optional): Optimal number of cores to use. Defaults to 0.
log (Union[str, bool], optional): Whether to print the progress bar. Defaults to False.
batch_size (int, optional): Number of vectors to process at once. Defaults to 0.
Raises:
KeyError: If collection not exist
Returns:
List[str]: List of IDs.
"""
collection_name = collection_name.lower()
if collection_name not in self._collections:
raise ServiceResourceNotFoundError(f"Collection {collection_name} does not exist, cannot insert.")
ucollection = self._collections[collection_name]
all_records_id = [record._id for record in records]
# Remove vectors from index
remove_labels = [
ucollection.embeddings_id_to_label[id] for id in all_records_id if id in ucollection.embeddings_id_to_label
]
ucollection.embeddings_index.remove(remove_labels, compact=compact, threads=threads)
# Determine label insertion points
table_num_rows = ucollection.embeddings_data_table.num_rows
insert_labels = np.arange(table_num_rows, table_num_rows + len(records))
# Add embeddings to index
ucollection.embeddings_index.add(
keys=insert_labels,
vectors=np.stack([record.embedding for record in records]),View on GitHub (pinned to c028a0c7dc)
Solutions
- Create the collection first: `await store.create_collection('docs', ndim=1536)`.
- Guard with `if 'docs' not in ...` / does_collection_exist before upserting.
- Match the name exactly (it is lowercased internally).
Example fix
// before
await store.upsert_batch('docs', records)
// after
if not await store.does_collection_exist('docs'):
await store.create_collection('docs', ndim=1536)
await store.upsert_batch('docs', records) Defensive patterns
Strategy: validation
Validate before calling
name = collection_name.lower()
if not await store.does_collection_exist(name):
await store.create_collection(name, ndim=embedding_dim)
await store.upsert_batch(name, records) Try / catch
from semantic_kernel.exceptions import ServiceResourceNotFoundError
try:
await store.upsert_batch(name, records)
except ServiceResourceNotFoundError:
await store.create_collection(name, ndim=dim)
await store.upsert_batch(name, records) Prevention
- Create the collection with the correct ndim before the first upsert.
- Keep collection names consistent (they are lowercased internally).
- If persistence is off, recreate collections on each process start.
When it happens
Trigger: Calling `await store.upsert_batch('docs', records)` when 'docs' was never created in this process (and not loaded from disk). The existence check runs before removing/adding vectors.
Common situations: Forgot to call create_collection before upserting; collection name typo or case mismatch (names are lowercased); in-memory store where the collection was lost after a restart; persist_directory not set so nothing was loaded.
Related errors
- Collection '{collection_name}' does not exist
- Collection '{collection_name}' does not exist
- Collection {collection_name} does not exist
- Error upserting record: {upsert_response.message}
- Upsert failed
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/3dfa2795ace2177f.
Report an issue: GitHub.