{"record":{"id":"45a4a29e61a323d5","repo":"run-llama/llama_index","slug":"no-index-in-storage-context-check-if-you-specifie","errorCode":null,"errorMessage":"No index in storage context, check if you specified the right persist_dir.","messagePattern":"No index in storage context, check if you specified the right persist_dir\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/indices/loading.py","lineNumber":38,"sourceCode":"    Args:\n        storage_context (StorageContext): storage context containing\n            docstore, index store and vector store.\n        index_id (Optional[str]): ID of the index to load.\n            Defaults to None, which assumes there's only a single index\n            in the index store and load it.\n        **kwargs: Additional keyword args to pass to the index constructors.\n\n    \"\"\"\n    index_ids: Optional[Sequence[str]]\n    if index_id is None:\n        index_ids = None\n    else:\n        index_ids = [index_id]\n\n    indices = load_indices_from_storage(storage_context, index_ids=index_ids, **kwargs)\n\n    if len(indices) == 0:\n        raise ValueError(\n            \"No index in storage context, check if you specified the right persist_dir.\"\n        )\n    elif len(indices) > 1:\n        raise ValueError(\n            f\"Expected to load a single index, but got {len(indices)} instead. \"\n            \"Please specify index_id.\"\n        )\n\n    return indices[0]\n\n\ndef load_indices_from_storage(\n    storage_context: StorageContext,\n    index_ids: Optional[Sequence[str]] = None,\n    **kwargs: Any,\n) -> List[BaseIndex]:\n    \"\"\"\n    Load multiple indices from storage context.","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/indices/loading.py#L20-L56","documentation":"load_index_from_storage(storage_context) loads every index found in the storage context's index store and expects exactly one. If load_indices_from_storage returns zero indices — the index store has no index_structs — it raises ValueError pointing at the persist_dir. This means the directory either is not a persisted llama-index storage dir or contains no index (e.g. only a docstore).","triggerScenarios":"StorageContext.from_defaults(persist_dir=...) pointing at an empty/never-persisted directory; persisting with StorageContext without any index (docstore-only persistence) and later calling load_index_from_storage; typos in the persist_dir path that silently create an empty dir.","commonSituations":"First run of an app before any index was saved; pointing at the wrong directory after moving storage; mixing up persist of documents vs persist of index; crashing between docstore.persist and index persist leaving a half-written dir.","solutions":["Confirm the target dir actually contains persisted storage: look for default_doc_store.json / docstore.json and an index store file (default_index_store.json) with index_structs entries.","Create the index first: VectorStoreIndex.from_documents(docs) then index.storage_context.persist(persist_dir=...) so the index store is written.","If multiple or optional indices are possible, call load_indices_from_storage directly and handle the empty list yourself instead of the singular helper."],"exampleFix":"# before\nstorage_context = StorageContext.from_defaults(persist_dir=\"./empty_dir\")\nindex = load_index_from_storage(storage_context)  # ValueError\n\n# after\n# ensure an index was persisted first\nVectorStoreIndex.from_documents(docs).storage_context.persist(persist_dir=\"./storage\")\nstorage_context = StorageContext.from_defaults(persist_dir=\"./storage\")\nindex = load_index_from_storage(storage_context)","handlingStrategy":"validation","validationCode":"import os\nfrom llama_index.core.storage.storage_context import StorageContext\n\npersist_dir = \"./storage\"\nassert os.path.isdir(persist_dir) and os.listdir(persist_dir), f\"{persist_dir} is empty or missing\"\nstorage_context = StorageContext.from_defaults(persist_dir=persist_dir)\nassert len(storage_context.index_store.index_structs()) > 0, \"no index persisted in this dir\"\nindex = load_index_from_storage(storage_context)","typeGuard":null,"tryCatchPattern":"try:\n    index = load_index_from_storage(storage_context)\nexcept ValueError as e:\n    if \"No index in storage context\" in str(e):\n        index = build_and_persist_index(persist_dir)  # build once, then load\n    else:\n        raise","preventionTips":["Check persist_dir exists and contains index-store JSON before loading.","Persist via index.storage_context.persist(dir) right after building so the dir is complete.","On first run, branch to index construction instead of load."],"tags":["llama-index","storage","persistence","loading","configuration"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}