{"record":{"id":"d04cf3a4fa38d20f","repo":"microsoft/semantic-kernel","slug":"collection-collection-name-does-not-exist-d04cf3","errorCode":null,"errorMessage":"Collection '{collection_name}' does not exist","messagePattern":"Collection '(.+?)' does not exist","errorType":"exception","errorClass":"ServiceResourceNotFoundError","httpStatus":404,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/postgres/postgres_memory_store.py","lineNumber":172,"sourceCode":"        Returns:\n            True if the collection exists; otherwise, False.\n        \"\"\"\n        with self._connection_pool.connection() as conn, conn.cursor() as cur:\n            return await self.__does_collection_exist(cur, collection_name)\n\n    async def upsert(self, collection_name: str, record: MemoryRecord) -> str:\n        \"\"\"Upserts a record.\n\n        Args:\n            collection_name: The name of the collection to upsert the record into.\n            record: The record to upsert.\n\n        Returns:\n            The unique database key of the record. In Pinecone, this is the record ID.\n        \"\"\"\n        with self._connection_pool.connection() as conn, conn.cursor() as cur:\n            if not await self.__does_collection_exist(cur, collection_name):\n                raise ServiceResourceNotFoundError(f\"Collection '{collection_name}' does not exist\")\n            cur.execute(\n                SQL(\n                    \"\"\"\n                        INSERT INTO {scm}.{tbl} (key, embedding, metadata, timestamp)\n                        VALUES (%s, %s, %s, %s)\n                        ON CONFLICT (key) DO UPDATE\n                        SET embedding = EXCLUDED.embedding,\n                            metadata = EXCLUDED.metadata,\n                            timestamp = EXCLUDED.timestamp\n                        RETURNING key\n                        \"\"\"\n                ).format(\n                    scm=Identifier(self._schema),\n                    tbl=Identifier(collection_name),\n                ),\n                (\n                    record._id,\n                    record.embedding.tolist(),","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/postgres/postgres_memory_store.py#L154-L190","documentation":"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.","triggerScenarios":"Calling upsert(collection_name, record) where the backing table does not exist in self._schema — never created, dropped, or wrong schema name.","commonSituations":"create_collection never run; schema mismatch (default 'public' vs custom); table dropped manually; cross-environment connection_string pointing at a different DB.","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."],"exampleFix":"// before\nawait store.upsert(\"my_table\", record)\n\n// after\nif not await store.does_collection_exist(\"my_table\"):\n    await store.create_collection(\"my_table\", dimension_num=1536)\nawait store.upsert(\"my_table\", record)","handlingStrategy":"validation","validationCode":"if not await store.does_collection_exist(collection_name):\n    await store.create_collection(collection_name, dimension_num=1536)\nawait store.upsert(collection_name, record)","typeGuard":"async def pg_collection_exists(store, name: str) -> bool:\n    return await store.does_collection_exist(name)","tryCatchPattern":"from semantic_kernel.exceptions import ServiceResourceNotFoundError\ntry:\n    await store.upsert(collection_name, record)\nexcept ServiceResourceNotFoundError:\n    await store.create_collection(collection_name, dimension_num=1536)\n    await store.upsert(collection_name, record)","preventionTips":["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."],"tags":["postgres","memory-store","deprecated","collection-not-found","upsert","pgvector"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}