microsoft/semantic-kernel · error · ServiceInitializationError
Persist directory is not set
Error message
Persist directory is not set
What it means
Raised by USearchMemoryStore._get_all_storage_files (ServiceInitializationError) when _persist_directory is None. This method enumerates on-disk collection files; without a directory there is nothing to scan. It is called during _read_collections_from_dir / re-resolution, so it effectively means 'persistence was never configured but on-disk collection discovery was attempted'.
Source
Thrown at python/semantic_kernel/connectors/memory_stores/usearch/usearch_memory_store.py:543
filtered_vectors,
)
)
]
def _get_all_storage_files(self) -> dict[str, list[Path]]:
"""Return storage files for each collection in `self._persist_directory`.
Collection name is derived from file name and converted to lowercase. Files with extensions that
do not match storage extensions are discarded.
Raises:
ValueError: If persist directory is not set.
Returns:
Dict[str, List[Path]]: Dictionary of collection names mapped to their respective files.
"""
if self._persist_directory is None:
raise ServiceInitializationError("Persist directory is not set")
storage_exts = _collection_file_extensions.values()
collection_storage_files: dict[str, list[Path]] = {}
for path in self._persist_directory.iterdir():
if path.is_file() and (path.suffix in storage_exts):
collection_name = path.stem.lower()
if collection_name in collection_storage_files:
collection_storage_files[collection_name].append(path)
else:
collection_storage_files[collection_name] = [path]
return collection_storage_files
def _dump_collections(self) -> None:
collection_storage_files = self._get_all_storage_files()
for file_path in itertools.chain.from_iterable(collection_storage_files.values()):
file_path.unlink()
for collection_name, ucollection in self._collections.items():View on GitHub (pinned to c028a0c7dc)
Solutions
- Pass a valid persist_directory to the constructor.
- Ensure the directory exists and is readable.
- Avoid code paths that require on-disk discovery for in-memory stores.
Example fix
// before store = USearchMemoryStore() // after store = USearchMemoryStore(persist_directory='/data/usearch')
Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
d = Path('/data/usearch')
assert d.exists(), 'persist directory required for storage discovery'
store = USearchMemoryStore(persist_directory=d) Try / catch
from semantic_kernel.exceptions import ServiceInitializationError
try:
store = USearchMemoryStore(persist_directory=d)
except ServiceInitializationError:
store = USearchMemoryStore() Prevention
- Always configure persist_directory when on-disk discovery is needed.
- Verify the directory is readable before constructing the store.
- Keep persistence configuration consistent across the process lifecycle.
When it happens
Trigger: Constructing `USearchMemoryStore()` without persist_directory and then invoking any internal path that re-scans storage files (e.g. reloading collections). In normal construction, the directory scan is skipped when _persist_directory is falsy, so this is reached via later/direct calls.
Common situations: In-memory store used in a context that later tries to discover collections from disk; misconfigured deployment missing the directory env var; subclass or framework hook calling storage discovery.
Related errors
- Path of persist directory is not set
- Expected {expected_storage_files} files for collection {coll
- WeaviateMemoryStore requires a URL or API key, or to use emb
- Failed to create Azure OpenAI settings: {exc}
- Please provide an Azure OpenAI endpoint
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/05bdc94f8669760c.
Report an issue: GitHub.