microsoft/semantic-kernel · error · VectorStoreInitializationException
The connection string is missing.
Error message
The connection string is missing.
What it means
After successfully constructing MongoDBAtlasSettings (validation passed), the constructor checks that a connection string is actually present. If the settings object exists but `connection_string` is falsy (empty or None), this VectorStoreInitializationException is raised. It indicates that settings validation did not fail, but the connection string specifically was not provided — a distinct, more targeted message than the general settings failure.
Source
Thrown at python/semantic_kernel/connectors/mongodb.py:585
managed_client=managed_client,
database_name=database_name or DEFAULT_DB_NAME,
embedding_generator=embedding_generator,
)
if callable(mongo_client.append_metadata):
mongo_client.append_metadata(DRIVER_METADATA)
return
try:
mongodb_atlas_settings = MongoDBAtlasSettings(
env_file_path=env_file_path,
connection_string=connection_string,
database_name=database_name,
env_file_encoding=env_file_encoding,
)
except ValidationError as exc:
raise VectorStoreInitializationException("Failed to create MongoDB Atlas settings.") from exc
if not mongodb_atlas_settings.connection_string:
raise VectorStoreInitializationException("The connection string is missing.")
mongo_client = AsyncMongoClient(
mongodb_atlas_settings.connection_string.get_secret_value(),
driver=DRIVER_METADATA,
)
super().__init__(
mongo_client=mongo_client,
managed_client=managed_client,
database_name=mongodb_atlas_settings.database_name,
embedding_generator=embedding_generator,
)
@override
def get_collection(
self,
record_type: type[TModel],
*,View on GitHub (pinned to c028a0c7dc)
Solutions
- Explicitly provide `connection_string` to the MongoDBAtlasStore constructor.
- Ensure the `MONGODB_ATLAS_CONNECTION_STRING` environment variable is set to a non-empty value.
- Check the `.env` file for a blank or whitespace-only connection string value.
- Validate the connection string is non-empty before constructing the store.
Example fix
// before (env var set to empty string) store = MongoDBAtlasStore() // after store = MongoDBAtlasStore(connection_string="mongodb+srv://user:pass@cluster.mongodb.net")
Defensive patterns
Strategy: validation
Validate before calling
import os
conn = os.getenv("MONGODB_ATLAS_CONNECTION_STRING", "")
if not conn or not conn.strip():
raise ValueError("Connection string is empty or missing; set MONGODB_ATLAS_CONNECTION_STRING.") Try / catch
try:
store = MongoDBAtlasStore()
except VectorStoreInitializationException as e:
if "connection string is missing" in str(e):
# explicitly pass connection_string argument
... Prevention
- Always pass connection_string explicitly when not relying solely on env vars.
- Check .env files for blank or whitespace-only connection string values.
- Validate the connection string is non-empty before constructing the store.
When it happens
Trigger: MongoDBAtlasSettings builds without a ValidationError (e.g. connection_string is an optional field), but the connection_string ends up empty/None. This can happen if connection_string is conditionally required and the settings model allows it to be absent.
Common situations: The connection string env var is set to an empty string. A custom settings subclass or env configuration makes connection_string optional at the Pydantic level. The `.env` file exists but the connection string line is blank or commented.
Related errors
- Failed to create Azure OpenAI settings: {exc}
- Please provide either an api_key, ad_token, ad_token_provide
- Please provide an Azure OpenAI endpoint
- Please provide an Azure OpenAI Responses deployment name
- Configuration not found, please setup the notebooks first us
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/210d23de6c181e82.
Report an issue: GitHub.