microsoft/semantic-kernel · error · MemoryConnectorInitializationError
Failed to create Redis settings.
Error message
Failed to create Redis settings.
What it means
Raised by RedisMemoryStore.__init__() when constructing RedisSettings raises a pydantic ValidationError (e.g. connection_string missing/invalid). It is wrapped as MemoryConnectorInitializationError (a MemoryConnectorException, not a ServiceException) with the original ValidationError chained via `from ex`.
Source
Thrown at python/semantic_kernel/connectors/memory_stores/redis/redis_memory_store.py:100
Args:
connection_string (str): Provide connection URL to a Redis instance
vector_size (str): Size of vectors, defaults to 1536
vector_distance_metric (str): Metric for measuring vector distances, defaults to COSINE
vector_type (str): Vector type, defaults to FLOAT32
vector_index_algorithm (str): Indexing algorithm for vectors, defaults to HNSW
query_dialect (int): Query dialect, must be 2 or greater for vector similarity searching, defaults to 2
env_file_path (str | None): Use the environment settings file as a fallback to
environment variables, defaults to False
env_file_encoding (str | None): Encoding of the environment settings file, defaults to "utf-8"
"""
try:
redis_settings = RedisSettings(
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 Redis settings.", ex) from ex
if vector_size <= 0:
raise MemoryConnectorInitializationError("Vector dimension must be a positive integer")
self._database = redis.Redis.from_url(redis_settings.connection_string.get_secret_value())
self._ft = self._database.ft
self._query_dialect = query_dialect
self._vector_distance_metric = vector_distance_metric
self._vector_index_algorithm = vector_index_algorithm
self._vector_type_str = vector_type
self._vector_type = np.float32 if vector_type == "FLOAT32" else np.float64
self._vector_size = vector_size
async def close(self):
"""Closes the Redis database connection."""
logger.info("Closing Redis connection")
self._database.close()View on GitHub (pinned to c028a0c7dc)
Solutions
- Set REDIS_CONNECTION_STRING (or pass connection_string explicitly), e.g. 'redis://localhost:6379'.
- If using a .env file, pass env_file_path correctly and ensure encoding matches.
- Inspect the chained ValidationError (ex) for the exact failing field.
- Validate the URL format (scheme redis:// or rediss://) before constructing the store.
Example fix
// before
store = RedisMemoryStore(connection_string=os.getenv('REDIS_URL')) # None if unset
// after
store = RedisMemoryStore(connection_string='redis://localhost:6379')
# or set env: export REDIS_CONNECTION_STRING=redis://localhost:6379 Defensive patterns
Strategy: validation
Validate before calling
import os
conn = os.getenv('REDIS_CONNECTION_STRING')
assert conn and conn.startswith(('redis://', 'rediss://')), 'valid REDIS_CONNECTION_STRING required'
store = RedisMemoryStore(connection_string=conn) Type guard
def valid_redis_url(s: str) -> bool:
return isinstance(s, str) and s.startswith(('redis://', 'rediss://')) and len(s) > len('redis://') Try / catch
from semantic_kernel.exceptions.memory_connector_exceptions import MemoryConnectorInitializationError
try:
store = RedisMemoryStore(connection_string=conn)
except MemoryConnectorInitializationError as e:
raise RuntimeError(f'invalid redis settings: {e.__cause__}') from e Prevention
- Always set REDIS_CONNECTION_STRING in the environment or pass it explicitly.
- Validate the URL scheme before constructing the store.
- Load .env via env_file_path and confirm it is found; inspect the chained ValidationError.
When it happens
Trigger: Constructing RedisMemoryStore(connection_string=...) where the value fails RedisSettings validation: empty/None connection_string, or the REDIS_CONNECTION_STRING env var (env_prefix 'REDIS_') is unset when no value is passed.
Common situations: REDIS_CONNECTION_STRING not set in the environment; .env file not loaded (env_file_path wrong); malformed redis:// URL; secret stripped to empty by config loader.
Related errors
- Vector dimension must be a positive integer
- Failed to create collection {collection_name}
- Failed to initialize the Amazon Bedrock Agent settings: {e}
- Expected OpenAISettings, got {type(settings).__name__}
- Failed to create OpenAI settings.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/5b7efae7201aec16.
Report an issue: GitHub.