{"record":{"id":"35cecbe3118f7e0e","repo":"run-llama/llama_index","slug":"expected-to-load-a-single-index-but-got-len-indi","errorCode":null,"errorMessage":"Expected to load a single index, but got {len(indices)} instead. Please specify index_id.","messagePattern":"Expected to load a single index, but got (.+?) instead\\. Please specify index_id\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/indices/loading.py","lineNumber":42,"sourceCode":"            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.\n\n    Args:\n        storage_context (StorageContext): storage context containing\n            docstore, index store and vector store.","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/indices/loading.py#L24-L60","documentation":"load_index_from_storage() requires a unique index: when load_indices_from_storage returns more than one (the index store persisted several index_structs), it raises ValueError asking you to disambiguate with index_id. The count is interpolated into the message.","triggerScenarios":"Persisting multiple indices into one storage_context (e.g. a VectorStoreIndex and a SummaryIndex sharing a persist_dir), then calling load_index_from_storage without index_id; re-running builds that accumulate index structs in the same store.","commonSituations":"One persist_dir holding a document index plus a summary/keyword index; iterative development saving several index versions into the same directory; shared storage context reused across index builds.","solutions":["Pass the specific index_id: load_index_from_storage(storage_context, index_id='<id>') — the ids are the index_struct ids you persisted (also visible via storage_context.index_store.index_structs()).","Inspect available ids before loading: [s.index_id for s in storage_context.index_store.index_structs()].","Or call load_indices_from_storage to get all of them and select programmatically."],"exampleFix":"# before\nindex = load_index_from_storage(storage_context)  # got 2 instead\n\n# after\nids = [s.index_id for s in storage_context.index_store.index_structs()]\nindex = load_index_from_storage(storage_context, index_id=ids[0])","handlingStrategy":"validation","validationCode":"ids = [s.index_id for s in storage_context.index_store.index_structs()]\nassert len(ids) >= 1, \"no indices to load\"\nif len(ids) > 1:\n    index = load_index_from_storage(storage_context, index_id=ids[0])  # disambiguate\nelse:\n    index = load_index_from_storage(storage_context)","typeGuard":null,"tryCatchPattern":"try:\n    index = load_index_from_storage(storage_context)\nexcept ValueError as e:\n    if \"Please specify index_id\" in str(e):\n        ids = [s.index_id for s in storage_context.index_store.index_structs()]\n        index = load_index_from_storage(storage_context, index_id=ids[0])\n    else:\n        raise","preventionTips":["Store index_id alongside the persist dir when you persist (index.index_id).","Use one persist_dir per index to keep loads unambiguous.","Inspect index_structs() before loading in generic tooling."],"tags":["llama-index","storage","persistence","loading","index-id"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}