{"record":{"id":"d93d0b7062c0d057","repo":"microsoft/semantic-kernel","slug":"dimensionality-of-dimension-num-exceeds-the-maxi-d93d0b","errorCode":null,"errorMessage":"Dimensionality of {dimension_num} exceeds the maximum allowed value of {MAX_DIMENSIONALITY}.","messagePattern":"Dimensionality of (.+?) exceeds the maximum allowed value of (.+?)\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/postgres/postgres_memory_store.py","lineNumber":495,"sourceCode":"\n    async def __does_collection_exist(self, cur: Cursor, collection_name: str) -> bool:\n        results = await self.__get_collections(cur)\n        return collection_name in results\n\n    async def __get_collections(self, cur: Cursor) -> list[str]:\n        cur.execute(\n            \"\"\"\n            SELECT table_name\n            FROM information_schema.tables\n            WHERE table_schema = %s\n            \"\"\",\n            (self._schema,),\n        )\n        return [row[0] for row in cur.fetchall()]\n\n    def _check_dimensionality(self, dimension_num):\n        if dimension_num > MAX_DIMENSIONALITY:\n            raise ServiceInitializationError(\n                f\"Dimensionality of {dimension_num} exceeds \" + f\"the maximum allowed value of {MAX_DIMENSIONALITY}.\"\n            )\n        if dimension_num <= 0:\n            raise ServiceInitializationError(\"Dimensionality must be a positive integer. \")\n\n    def __serialize_metadata(self, record: MemoryRecord) -> str:\n        return json.dumps({\n            \"text\": record._text,\n            \"description\": record._description,\n            \"additional_metadata\": record._additional_metadata,\n        })\n\n    # Enable the connection pool to be closed when using as a context manager\n    def __enter__(self) -> \"PostgresMemoryStore\":\n        \"\"\"Enter the runtime context.\"\"\"\n        return self\n\n    def __exit__(self, exc_type, exc_value, traceback) -> bool:","sourceCodeStart":477,"sourceCodeEnd":513,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/postgres/postgres_memory_store.py#L477-L513","documentation":"Raised by PostgresMemoryStore._check_dimensionality() (called from __init__ and create_collection) when the requested embedding dimension exceeds MAX_DIMENSIONALITY, which is 2000 for the Postgres connector (semantic_kernel/connectors/postgres.py). It is a ServiceInitializationError thrown at configuration time, before any table is created.","triggerScenarios":"Constructing PostgresMemoryStore(default_dimensionality=N) or calling create_collection(name, dimension_num=N) with N > 2000.","commonSituations":"Switching to an embedding model with large output (e.g. some 2048/3072-dim models) against the pgvector-backed store; copy-pasting a dimension from another connector (Pinecone/Astra allow up to 20000).","solutions":["Use an embedding dimension <= 2000, or reduce dimensionality (e.g. Matryoshka/truncation) before storage.","Pick a different memory store whose MAX_DIMENSIONALITY is higher (Pinecone, AstraDB = 20000).","If pgvector supports larger vectors in your Postgres build, prefer the newer PostgresStore API which does not hard-cap at 2000.","Validate dimension_num against 2000 in app config before constructing the store."],"exampleFix":"// before\nstore = PostgresMemoryStore(conn_str, default_dimensionality=3072)\n// after\nstore = PostgresMemoryStore(conn_str, default_dimensionality=1536)  # <= 2000","handlingStrategy":"validation","validationCode":"from semantic_kernel.connectors.postgres import MAX_DIMENSIONALITY  # 2000\nassert 0 < dim <= MAX_DIMENSIONALITY, f'dim {dim} out of range'\nstore = PostgresMemoryStore(conn_str, default_dimensionality=dim)","typeGuard":"def valid_postgres_dim(dim: int) -> bool:\n    return isinstance(dim, int) and 0 < dim <= 2000","tryCatchPattern":"from semantic_kernel.exceptions import ServiceInitializationError\ntry:\n    store = PostgresMemoryStore(conn_str, default_dimensionality=dim)\nexcept ServiceInitializationError:\n    # choose a different store or reduce dimensionality\n    ...","preventionTips":["Check the embedding model's dimension against MAX_DIMENSIONALITY (2000) at config load.","If you need > 2000 dims, use Pinecone/AstraDB (cap 20000) or truncate embeddings.","Unit-test store construction with boundary dimensions (2000 ok, 2001 fails)."],"tags":["postgres","memory-store","dimensionality","service-initialization-error","configuration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}