microsoft/semantic-kernel · error · ServiceInitializationError
Dimensionality of {dimension_num} exceeds the maximum allowe
Error message
Dimensionality of {dimension_num} exceeds the maximum allowed value of {MAX_DIMENSIONALITY}. What it means
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.
Source
Thrown at python/semantic_kernel/connectors/memory_stores/postgres/postgres_memory_store.py:495
async def __does_collection_exist(self, cur: Cursor, collection_name: str) -> bool:
results = await self.__get_collections(cur)
return collection_name in results
async def __get_collections(self, cur: Cursor) -> list[str]:
cur.execute(
"""
SELECT table_name
FROM information_schema.tables
WHERE table_schema = %s
""",
(self._schema,),
)
return [row[0] for row in cur.fetchall()]
def _check_dimensionality(self, dimension_num):
if dimension_num > MAX_DIMENSIONALITY:
raise ServiceInitializationError(
f"Dimensionality of {dimension_num} exceeds " + f"the maximum allowed value of {MAX_DIMENSIONALITY}."
)
if dimension_num <= 0:
raise ServiceInitializationError("Dimensionality must be a positive integer. ")
def __serialize_metadata(self, record: MemoryRecord) -> str:
return json.dumps({
"text": record._text,
"description": record._description,
"additional_metadata": record._additional_metadata,
})
# Enable the connection pool to be closed when using as a context manager
def __enter__(self) -> "PostgresMemoryStore":
"""Enter the runtime context."""
return self
def __exit__(self, exc_type, exc_value, traceback) -> bool:View on GitHub (pinned to c028a0c7dc)
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.
Example fix
// before store = PostgresMemoryStore(conn_str, default_dimensionality=3072) // after store = PostgresMemoryStore(conn_str, default_dimensionality=1536) # <= 2000
Defensive patterns
Strategy: validation
Validate before calling
from semantic_kernel.connectors.postgres import MAX_DIMENSIONALITY # 2000
assert 0 < dim <= MAX_DIMENSIONALITY, f'dim {dim} out of range'
store = PostgresMemoryStore(conn_str, default_dimensionality=dim) Type guard
def valid_postgres_dim(dim: int) -> bool:
return isinstance(dim, int) and 0 < dim <= 2000 Try / catch
from semantic_kernel.exceptions import ServiceInitializationError
try:
store = PostgresMemoryStore(conn_str, default_dimensionality=dim)
except ServiceInitializationError:
# choose a different store or reduce dimensionality
... Prevention
- 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).
When it happens
Trigger: Constructing PostgresMemoryStore(default_dimensionality=N) or calling create_collection(name, dimension_num=N) with N > 2000.
Common situations: 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).
Related errors
- Dimensionality must be a positive integer.
- Dimensionality of {default_dimensionality} exceeds the maxim
- Failed to create Postgres settings.
- Vector dimension must be a positive integer
- Failed to validate Mistral AI settings: {e}
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/d93d0b7062c0d057.
Report an issue: GitHub.