{"record":{"id":"4c084bddc3d9474c","repo":"run-llama/llama_index","slug":"failed-to-load-index-with-id-index-id","errorCode":null,"errorMessage":"Failed to load index with ID {index_id}","messagePattern":"Failed to load index with ID (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/indices/loading.py","lineNumber":75,"sourceCode":"\n    Args:\n        storage_context (StorageContext): storage context containing\n            docstore, index store and vector store.\n        index_id (Optional[Sequence[str]]): IDs of the indices to load.\n            Defaults to None, which loads all indices in the index store.\n        **kwargs: Additional keyword args to pass to the index constructors.\n\n    \"\"\"\n    if index_ids is None:\n        logger.info(\"Loading all indices.\")\n        index_structs = storage_context.index_store.index_structs()\n    else:\n        logger.info(f\"Loading indices with ids: {index_ids}\")\n        index_structs = []\n        for index_id in index_ids:\n            index_struct = storage_context.index_store.get_index_struct(index_id)\n            if index_struct is None:\n                raise ValueError(f\"Failed to load index with ID {index_id}\")\n            index_structs.append(index_struct)\n\n    indices = []\n    for index_struct in index_structs:\n        type_ = index_struct.get_type()\n        index_cls = INDEX_STRUCT_TYPE_TO_INDEX_CLASS[type_]\n        index = index_cls(\n            index_struct=index_struct, storage_context=storage_context, **kwargs\n        )\n        indices.append(index)\n    return indices\n\n\ndef load_graph_from_storage(\n    storage_context: StorageContext,\n    root_id: str,\n    **kwargs: Any,\n) -> ComposableGraph:","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/indices/loading.py#L57-L93","documentation":"In load_indices_from_storage, when explicit index_ids are supplied, each id is looked up via storage_context.index_store.get_index_struct(index_id). A None return means no index struct with that id exists in the loaded index store, and the loop raises ValueError('Failed to load index with ID {index_id}').","triggerScenarios":"Calling load_index_from_storage(storage_context, index_id='...') with a stale, mistyped, or wrong-environment id; passing a node id or doc id instead of the index id; storage persisted after the index was rebuilt under a new id.","commonSituations":"Hardcoding an index_id that changed after a re-index; environments (dev/prod) sharing config but not storage; ids truncated or copied incorrectly; storage dir overwritten by a fresh build.","solutions":["List the ids actually present and use one of them: ids = [s.index_id for s in storage_context.index_store.index_structs()].","Persist/track index ids at build time (index.index_id) alongside the storage dir so loaders reference the right one.","If no ids are known, omit index_id and use load_indices_from_storage to load everything, then choose by index type (index_struct.get_type())."],"exampleFix":"# before\nindex = load_index_from_storage(storage_context, index_id=\"my-old-id\")\n\n# after\nvalid_ids = [s.index_id for s in storage_context.index_store.index_structs()]\nindex = load_index_from_storage(storage_context, index_id=valid_ids[0])","handlingStrategy":"validation","validationCode":"valid_ids = {s.index_id for s in storage_context.index_store.index_structs()}\nassert index_id in valid_ids, f\"{index_id} not in persisted ids: {valid_ids}\"\nindex = load_index_from_storage(storage_context, index_id=index_id)","typeGuard":null,"tryCatchPattern":"try:\n    index = load_index_from_storage(storage_context, index_id=index_id)\nexcept ValueError as e:\n    if \"Failed to load index with ID\" in str(e):\n        valid = [s.index_id for s in storage_context.index_store.index_structs()]\n        raise RuntimeError(f\"index_id stale; available: {valid}\") from e\n    raise","preventionTips":["Read index ids from index_store.index_structs() instead of hardcoding.","Persist index_id metadata with your storage artifacts.","Treat index_id as environment-scoped: never share ids across dev/prod dirs."],"tags":["llama-index","storage","loading","index-id","validation"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}