microsoft/semantic-kernel · error · ServiceInitializationError

Path of persist directory is not set

Error message

Path of persist directory is not set

What it means

Raised by USearchMemoryStore._get_collection_path (ServiceInitializationError) when it needs to compute a collection file path but `self._persist_directory` is None. This is a defensive guard; in normal flow create_collection only calls _get_collection_path when _persist_directory is already truthy, so this is most often hit by direct calls, subclass overrides, or an in-memory store being used where persistence is expected.

Source

Thrown at python/semantic_kernel/connectors/memory_stores/usearch/usearch_memory_store.py:163

        if self._persist_directory:
            self._collections = self._read_collections_from_dir()

    def _get_collection_path(self, collection_name: str, *, file_type: _CollectionFileType) -> Path:
        """Get the path for the given collection name and file type.

        Args:
            collection_name (str): Name of the collection.
            file_type (_CollectionFileType): The file type.

        Returns:
            Path: Path to the collection file.

        Raises:
            ValueError: If persist directory path is not set.
        """
        collection_name = collection_name.lower()
        if self._persist_directory is None:
            raise ServiceInitializationError("Path of persist directory is not set")

        return self._persist_directory / (collection_name + _collection_file_extensions[file_type])

    async def create_collection(
        self,
        collection_name: str,
        ndim: int = 0,
        metric: str | MetricKind | CompiledMetric = MetricKind.IP,
        dtype: str | ScalarKind | None = None,
        connectivity: int | None = None,
        expansion_add: int | None = None,
        expansion_search: int | None = None,
        view: bool = False,
    ) -> None:
        """Create a new collection.

        Args:
            collection_name (str): Name of the collection. Case-insensitive.

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass a persist_directory to the constructor: `USearchMemoryStore(persist_directory='/data/usearch')`.
  2. Ensure the directory path exists and is writable before constructing the store.
  3. If in-memory-only is intended, avoid code paths that require file paths (create_collection still works without persistence).

Example fix

// before
store = USearchMemoryStore()
// after
store = USearchMemoryStore(persist_directory='/data/usearch')
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path
persist_dir = Path('/data/usearch')
if not persist_dir.exists():
    persist_dir.mkdir(parents=True)
store = USearchMemoryStore(persist_directory=persist_dir)  # in-memory: omit and avoid file-path calls

Try / catch

from semantic_kernel.exceptions import ServiceInitializationError
try:
    store = USearchMemoryStore(persist_directory=maybe_dir)
except ServiceInitializationError:
    store = USearchMemoryStore()  # fall back to in-memory

Prevention

When it happens

Trigger: Constructing `USearchMemoryStore()` with no `persist_directory`, then a code path that resolves a collection file path (directly or via a subclass/extension). Also reachable if persist_directory was set to a value that becomes falsy.

Common situations: Intended an in-memory store but later code (or a framework integration) expects on-disk persistence; copied code that assumes a persist_directory; misconfigured deployment where the directory env var is unset.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/476a3efcf0d51adc. Report an issue: GitHub.