{"record":{"id":"5b7efae7201aec16","repo":"microsoft/semantic-kernel","slug":"failed-to-create-redis-settings","errorCode":null,"errorMessage":"Failed to create Redis settings.","messagePattern":"Failed to create Redis settings\\.","errorType":"exception","errorClass":"MemoryConnectorInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/redis/redis_memory_store.py","lineNumber":100,"sourceCode":"        Args:\n            connection_string (str): Provide connection URL to a Redis instance\n            vector_size (str): Size of vectors, defaults to 1536\n            vector_distance_metric (str): Metric for measuring vector distances, defaults to COSINE\n            vector_type (str): Vector type, defaults to FLOAT32\n            vector_index_algorithm (str): Indexing algorithm for vectors, defaults to HNSW\n            query_dialect (int): Query dialect, must be 2 or greater for vector similarity searching, defaults to 2\n            env_file_path (str | None): Use the environment settings file as a fallback to\n                environment variables, defaults to False\n            env_file_encoding (str | None): Encoding of the environment settings file, defaults to \"utf-8\"\n        \"\"\"\n        try:\n            redis_settings = RedisSettings(\n                connection_string=connection_string,\n                env_file_path=env_file_path,\n                env_file_encoding=env_file_encoding,\n            )\n        except ValidationError as ex:\n            raise MemoryConnectorInitializationError(\"Failed to create Redis settings.\", ex) from ex\n\n        if vector_size <= 0:\n            raise MemoryConnectorInitializationError(\"Vector dimension must be a positive integer\")\n\n        self._database = redis.Redis.from_url(redis_settings.connection_string.get_secret_value())\n        self._ft = self._database.ft\n\n        self._query_dialect = query_dialect\n        self._vector_distance_metric = vector_distance_metric\n        self._vector_index_algorithm = vector_index_algorithm\n        self._vector_type_str = vector_type\n        self._vector_type = np.float32 if vector_type == \"FLOAT32\" else np.float64\n        self._vector_size = vector_size\n\n    async def close(self):\n        \"\"\"Closes the Redis database connection.\"\"\"\n        logger.info(\"Closing Redis connection\")\n        self._database.close()","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/redis/redis_memory_store.py#L82-L118","documentation":"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`.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nstore = RedisMemoryStore(connection_string=os.getenv('REDIS_URL'))  # None if unset\n// after\nstore = RedisMemoryStore(connection_string='redis://localhost:6379')\n# or set env: export REDIS_CONNECTION_STRING=redis://localhost:6379","handlingStrategy":"validation","validationCode":"import os\nconn = os.getenv('REDIS_CONNECTION_STRING')\nassert conn and conn.startswith(('redis://', 'rediss://')), 'valid REDIS_CONNECTION_STRING required'\nstore = RedisMemoryStore(connection_string=conn)","typeGuard":"def valid_redis_url(s: str) -> bool:\n    return isinstance(s, str) and s.startswith(('redis://', 'rediss://')) and len(s) > len('redis://')","tryCatchPattern":"from semantic_kernel.exceptions.memory_connector_exceptions import MemoryConnectorInitializationError\ntry:\n    store = RedisMemoryStore(connection_string=conn)\nexcept MemoryConnectorInitializationError as e:\n    raise RuntimeError(f'invalid redis settings: {e.__cause__}') from e","preventionTips":["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."],"tags":["redis","memory-store","configuration","memory-connector-initialization-error","settings"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}