microsoft/semantic-kernel · error · MemoryConnectorInitializationError
Failed to create AstraDB settings.
Error message
Failed to create AstraDB settings.
What it means
Raised in the `AstraDBMemoryStore` constructor when constructing the pydantic `AstraDBSettings` model raises a `ValidationError`. The validation error is wrapped in a `MemoryConnectorInitializationError` (chained via `from ex`) so callers see a connector-level failure. It means one or more required settings (app token, db id, region, keyspace) are missing or invalid.
Source
Thrown at python/semantic_kernel/connectors/memory_stores/astradb/astradb_memory_store.py:75
keyspace_name (str): The Astra keyspace
embedding_dim (int): The dimensionality to use for new collections.
similarity (str): TODO
session: Optional session parameter
env_file_path (str | None): Use the environment settings file as a
fallback to environment variables. (Optional)
env_file_encoding (str | None): The encoding of the environment settings file. (Optional)
"""
try:
astradb_settings = AstraDBSettings(
app_token=astra_application_token,
db_id=astra_id,
region=astra_region,
keyspace=keyspace_name,
env_file_path=env_file_path,
env_file_encoding=env_file_encoding,
)
except ValidationError as ex:
raise MemoryConnectorInitializationError("Failed to create AstraDB settings.", ex) from ex
self._embedding_dim = embedding_dim
self._similarity = similarity
self._session = session
if self._embedding_dim > MAX_DIMENSIONALITY:
raise MemoryConnectorInitializationError(
f"Dimensionality of {self._embedding_dim} exceeds the maximum allowed value of {MAX_DIMENSIONALITY}."
)
self._client = AstraClient(
astra_id=astradb_settings.db_id,
astra_region=astradb_settings.region,
astra_application_token=(
astradb_settings.app_token.get_secret_value() if astradb_settings.app_token else None
),
keyspace_name=astradb_settings.keyspace,
embedding_dim=embedding_dim,View on GitHub (pinned to c028a0c7dc)
Solutions
- Set the required Astra env vars: `ASTRA_DB_APP_TOKEN`, `ASTRA_DB_ID`, `ASTRA_DB_REGION`, `ASTRA_DB_KEYSPACE` (or pass them as constructor args).
- Point `env_file_path` at an existing `.env` file with these values, and confirm `env_file_encoding` matches.
- Inspect the chained `ValidationError` (`exc.__cause__`) for the exact missing/invalid field names.
- Verify secrets are actually exported in the runtime environment (container/CI), not just in a local file.
Example fix
// before
store = AstraDBMemoryStore(embedding_dim=1536) # no token/id/region -> ValidationError
// after
store = AstraDBMemoryStore(
astra_application_token=os.environ["ASTRA_DB_APP_TOKEN"],
astra_id=os.environ["ASTRA_DB_ID"],
astra_region=os.environ["ASTRA_DB_REGION"],
keyspace_name=os.environ["ASTRA_DB_KEYSPACE"],
embedding_dim=1536,
) Defensive patterns
Strategy: validation
Validate before calling
import os
def astra_env_ready() -> bool:
required = ["ASTRA_DB_APP_TOKEN", "ASTRA_DB_ID", "ASTRA_DB_REGION", "ASTRA_DB_KEYSPACE"]
return all(os.getenv(v) for v in required)
# assert astra_env_ready() before constructing the store Try / catch
from semantic_kernel.exceptions import MemoryConnectorInitializationError
try:
store = AstraDBMemoryStore(...)
except MemoryConnectorInitializationError as e:
cause = e.__cause__ # pydantic ValidationError -> missing fields
raise SystemExit(f"Astra settings invalid: {cause}") from e Prevention
- Centralize Astra secrets in env vars or a `.env` and load it explicitly.
- Fail fast at startup by validating required env vars exist.
- Inspect `__cause__` to see exactly which pydantic fields failed.
- Inject secrets into CI/containers rather than committing `.env`.
When it happens
Trigger: Instantiating `AstraDBMemoryStore(...)` without supplying `astra_application_token`, `astra_id`, `astra_region`, and/or `keyspace_name`, and the corresponding environment variables (`ASTRA_DB_APP_TOKEN`, `ASTRA_DB_ID`, etc.) plus the `.env` file (via `env_file_path`) are also absent. Pydantic raises `ValidationError`; the constructor converts it to `MemoryConnectorInitializationError`.
Common situations: Missing `.env` file or wrong `env_file_path`; environment variables not exported in the deployment shell; `.gitignore` excluding the secrets file; CI/container missing the Astra secrets; typo in an env var name; passing an empty string where a required field is expected.
Related errors
- Failed to create Azure Cognitive Search settings.
- Dimensionality of {self._embedding_dim} exceeds the maximum
- Failed to create Azure OpenAI settings: {exc}
- Failed to validate Google AI settings: {e}
- Failed to validate Google AI settings: {e}
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/134ab96ce5cef0fe.
Report an issue: GitHub.