{"record":{"id":"c2eb156508e02a20","repo":"microsoft/semantic-kernel","slug":"expected-expected-storage-files-files-for-collec","errorCode":null,"errorMessage":"Expected {expected_storage_files} files for collection {collection_name}","messagePattern":"Expected (.+?) files for collection (.+?)","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/usearch/usearch_memory_store.py","lineNumber":257,"sourceCode":"        # str cast is temporarily fix for https://github.com/unum-cloud/usearch/issues/196\n        return Index.restore(str(path), view=False)\n\n    def _read_collections_from_dir(self) -> dict[str, _USearchCollection]:\n        \"\"\"Read all collections from directory to memory.\n\n        Raises:\n            ValueError: If files for a collection do not match expected amount.\n\n        Returns:\n            Dict[str, _USearchCollection]: Dictionary with collection names as keys and\n              their _USearchCollection as values.\n        \"\"\"\n        collections: dict[str, _USearchCollection] = {}\n\n        for collection_name, collection_files in self._get_all_storage_files().items():\n            expected_storage_files = len(_CollectionFileType)\n            if len(collection_files) != expected_storage_files:\n                raise ServiceInitializationError(\n                    f\"Expected {expected_storage_files} files for collection {collection_name}\"\n                )\n            parquet_file, usearch_file = collection_files\n            if parquet_file.suffix == _collection_file_extensions[_CollectionFileType.USEARCH]:\n                parquet_file, usearch_file = usearch_file, parquet_file\n\n            embeddings_table, embeddings_id_to_label = self._read_embeddings_table(parquet_file)\n            embeddings_index = self._read_embeddings_index(usearch_file)\n\n            collections[collection_name] = _USearchCollection(\n                embeddings_index,\n                embeddings_table,\n                embeddings_id_to_label,\n            )\n\n        return collections\n\n    async def get_collections(self) -> list[str]:","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/usearch/usearch_memory_store.py#L239-L275","documentation":"Raised by USearchMemoryStore._read_collections_from_dir (ServiceInitializationError) during construction when a discovered collection does not have exactly the expected number of storage files (one .usearch index plus one .parquet table). The store pairs the two files per collection; a partial set means the persisted state is corrupt/incomplete, so it refuses to load.","triggerScenarios":"Constructing `USearchMemoryStore(persist_directory=...)` where some collection has only a .usearch file (or only a .parquet file), or has extra/orphaned files matching the storage extensions. Triggered at startup while scanning the directory.","commonSituations":"A previous process crashed during `close()`/save leaving only one of the two files written; manual deletion of one file; partial copy/restore of the data directory; leftover files from a format change.","solutions":["Inspect the persist_directory and ensure each collection has both a `.usearch` and a `.parquet` file and nothing extra with those extensions.","Remove the incomplete collection's orphaned file(s) so the store can recreate it.","Re-derive/reseed the affected collection from source data after deleting the partial files."],"exampleFix":"// before\nstore = USearchMemoryStore(persist_directory='/data/usearch')  # raises: 'my_docs' has 1 file\n// after\n// delete the orphaned /data/usearch/my_docs.usearch, then recreate + reseed\nstore = USearchMemoryStore(persist_directory='/data/usearch')","handlingStrategy":"try-catch","validationCode":"from pathlib import Path\nexts = {'.usearch', '.parquet'}\ngroups: dict[str, list[Path]] = {}\nfor p in Path(persist_dir).iterdir():\n    if p.suffix in exts:\n        groups.setdefault(p.stem.lower(), []).append(p)\nbad = [n for n, fs in groups.items() if len(fs) != 2]\nassert not bad, f'incomplete collections: {bad}'\nstore = USearchMemoryStore(persist_directory=persist_dir)","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import ServiceInitializationError\ntry:\n    store = USearchMemoryStore(persist_directory=persist_dir)\nexcept ServiceInitializationError as e:\n    if 'Expected' in str(e):\n        # quarantine the incomplete collection and retry\n        ...","preventionTips":["Ensure clean shutdowns (call store.close()) so both files are written atomically.","Back up the persist_directory as a unit, never individual files.","Validate the directory has paired (.usearch + .parquet) files before constructing the store."],"tags":["usearch","memory-store","initialization","persistence","data-corruption"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}