microsoft/semantic-kernel · error · ServiceResourceNotFoundError
Collection '{collection_name}' does not exist
Error message
Collection '{collection_name}' does not exist What it means
Raised in PostgresMemoryStore.upsert() when the internal __does_collection_exist(cur, collection_name) returns False inside the connection-pool transaction. ServiceResourceNotFoundError fires before the INSERT. In Postgres a 'collection' is a table in the configured schema; it must be created via create_collection first.
Source
Thrown at python/semantic_kernel/connectors/memory_stores/postgres/postgres_memory_store.py:172
Returns:
True if the collection exists; otherwise, False.
"""
with self._connection_pool.connection() as conn, conn.cursor() as cur:
return await self.__does_collection_exist(cur, collection_name)
async def upsert(self, collection_name: str, record: MemoryRecord) -> str:
"""Upserts a record.
Args:
collection_name: The name of the collection to upsert the record into.
record: The record to upsert.
Returns:
The unique database key of the record. In Pinecone, this is the record ID.
"""
with self._connection_pool.connection() as conn, conn.cursor() as cur:
if not await self.__does_collection_exist(cur, collection_name):
raise ServiceResourceNotFoundError(f"Collection '{collection_name}' does not exist")
cur.execute(
SQL(
"""
INSERT INTO {scm}.{tbl} (key, embedding, metadata, timestamp)
VALUES (%s, %s, %s, %s)
ON CONFLICT (key) DO UPDATE
SET embedding = EXCLUDED.embedding,
metadata = EXCLUDED.metadata,
timestamp = EXCLUDED.timestamp
RETURNING key
"""
).format(
scm=Identifier(self._schema),
tbl=Identifier(collection_name),
),
(
record._id,
record.embedding.tolist(),View on GitHub (pinned to c028a0c7dc)
Solutions
- Call create_collection(collection_name, dimension_num) before upsert.
- Guard with does_collection_exist and create on demand.
- Verify self._schema matches the schema where the table lives.
- Confirm the connection_string targets the right database.
Example fix
// before
await store.upsert("my_table", record)
// after
if not await store.does_collection_exist("my_table"):
await store.create_collection("my_table", dimension_num=1536)
await store.upsert("my_table", record) Defensive patterns
Strategy: validation
Validate before calling
if not await store.does_collection_exist(collection_name):
await store.create_collection(collection_name, dimension_num=1536)
await store.upsert(collection_name, record) Type guard
async def pg_collection_exists(store, name: str) -> bool:
return await store.does_collection_exist(name) Try / catch
from semantic_kernel.exceptions import ServiceResourceNotFoundError
try:
await store.upsert(collection_name, record)
except ServiceResourceNotFoundError:
await store.create_collection(collection_name, dimension_num=1536)
await store.upsert(collection_name, record) Prevention
- Create the table via create_collection before upsert.
- Verify the schema and connection_string target the right DB.
- Share a collection-name source of truth.
When it happens
Trigger: Calling upsert(collection_name, record) where the backing table does not exist in self._schema — never created, dropped, or wrong schema name.
Common situations: create_collection never run; schema mismatch (default 'public' vs custom); table dropped manually; cross-environment connection_string pointing at a different DB.
Related errors
- Upsert failed
- Collection '{collection_name}' does not exist
- Error upserting record: {upsert_response.message}
- Failed to create Postgres settings.
- Collection {collection_name} does not exist, cannot insert.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/d04cf3a4fa38d20f.
Report an issue: GitHub.