microsoft/semantic-kernel · error · MemoryConnectorInitializationError
Failed to create Postgres settings.
Error message
Failed to create Postgres settings.
What it means
Raised in PostgresMemoryStore.__init__ when constructing PostgresSettings raises a pydantic ValidationError. The error is wrapped as MemoryConnectorInitializationError('Failed to create Postgres settings.') with the original ValidationError chained. PostgresSettings resolves the connection_string from the arg or .env fallback; failure most often means a missing/invalid connection string or pool size bounds violation.
Source
Thrown at python/semantic_kernel/connectors/memory_stores/postgres/postgres_memory_store.py:71
Args:
connection_string: The connection string to the Postgres database.
default_dimensionality: The default dimensionality of the embeddings.
min_pool: The minimum number of connections in the connection pool.
max_pool: The maximum number of connections in the connection pool.
schema: The schema to use. (default: {"public"})
env_file_path: Use the environment settings file as a fallback
to environment variables. (Optional)
env_file_encoding: The encoding of the environment settings file.
"""
try:
postgres_settings = PostgresSettings(
connection_string=connection_string,
env_file_path=env_file_path,
env_file_encoding=env_file_encoding,
)
except ValidationError as ex:
raise MemoryConnectorInitializationError("Failed to create Postgres settings.", ex) from ex
min_pool = min_pool or postgres_settings.min_pool
max_pool = max_pool or postgres_settings.max_pool
self._check_dimensionality(default_dimensionality)
self._default_dimensionality = default_dimensionality
self._connection_pool = ConnectionPool(
min_size=min_pool, max_size=max_pool, open=True, kwargs=postgres_settings.get_connection_args()
)
self._schema = schema
atexit.register(self._connection_pool.close)
async def create_collection(
self,
collection_name: str,
dimension_num: int | None = None,
) -> None:View on GitHub (pinned to c028a0c7dc)
Solutions
- Set POSTGRES_CONNECTION_STRING (or pass connection_string) with a valid postgres:// URI including host, user, password, dbname.
- Inspect the chained ValidationError to see the exact failing field.
- Verify env_file_path points to a readable .env with the connection string.
- Migrate to PostgresStore + Collection.
Example fix
// before store = PostgresMemoryStore(connection_string=None, default_dimensionality=1536) // after import os conn = os.environ["POSTGRES_CONNECTION_STRING"] store = PostgresMemoryStore(connection_string=conn, default_dimensionality=1536)
Defensive patterns
Strategy: try-catch
Validate before calling
import os
conn = connection_string or os.environ.get("POSTGRES_CONNECTION_STRING")
if not conn:
raise RuntimeError("POSTGRES_CONNECTION_STRING is required")
store = PostgresMemoryStore(connection_string=conn, default_dimensionality=1536) Type guard
def has_postgres_credentials() -> bool:
return bool(os.environ.get("POSTGRES_CONNECTION_STRING")) Try / catch
from semantic_kernel.exceptions.memory_connector_exceptions import MemoryConnectorInitializationError
try:
store = PostgresMemoryStore(connection_string=conn, default_dimensionality=1536)
except MemoryConnectorInitializationError as e:
raise SystemExit(f"Postgres settings invalid: {e.__cause__}") from e Prevention
- Set POSTGRES_CONNECTION_STRING in every environment.
- Inspect the chained ValidationError for the exact failing field.
- Validate the URI includes host/user/password/dbname and any required SSL params.
When it happens
Trigger: Constructing PostgresMemoryStore without a connection_string and with no POSTGRES_CONNECTION_STRING env var/.env; providing a malformed connection string; min_pool/max_pool env values out of allowed range.
Common situations: Deployment missing the POSTGRES_CONNECTION_STRING secret; .env not loaded in prod; connection string lacks required pgvector/SSL params; pool size env vars misconfigured.
Related errors
- Failed to create Pinecone settings.
- Dimensionality of {default_dimensionality} exceeds the maxim
- Collection '{collection_name}' does not exist
- Upsert failed
- Dimensionality of {dimension_num} exceeds the maximum allowe
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/f1630692df0798ce.
Report an issue: GitHub.