How to beginner · 3 min read

How to load LlamaIndex index from disk

Quick answer
To load a saved LlamaIndex index from disk, use the load_from_disk method from the llama_index library. This method restores the index object so you can query or update it in your Python application.

PREREQUISITES

  • Python 3.8+
  • pip install llama-index>=0.6.0
  • Basic familiarity with LlamaIndex usage

Setup

Install the llama-index package if you haven't already. This package provides the load_from_disk method to restore saved indexes.

Set up your Python environment and ensure you have an index saved on disk as a JSON or similar file.

bash
pip install llama-index>=0.6.0

Step by step

Use the following Python code to load a LlamaIndex index from disk and query it. Replace your_index.json with your saved index file path.

python
from llama_index import GPTSimpleVectorIndex

# Path to your saved index file
index_path = "your_index.json"

# Load the index from disk
index = GPTSimpleVectorIndex.load_from_disk(index_path)

# Example query
response = index.query("What is LlamaIndex?")
print(response.response)
output
LlamaIndex is a Python library that helps you build and query indices over your documents.

Common variations

  • You can also use StorageContext and load_index_from_storage for more complex index types or storage setups.
  • For async usage, wrap loading and querying in async functions if your environment supports it.
  • Different index classes like GPTListIndex or GPTTreeIndex have similar load_from_disk methods.
python
from llama_index import StorageContext, load_index_from_storage

storage_context = StorageContext.from_defaults(persist_dir="./storage")
index = load_index_from_storage(storage_context)

response = index.query("Explain LlamaIndex.")
print(response.response)
output
LlamaIndex provides flexible data structures to build and query indices over documents.

Troubleshooting

  • If you get a FileNotFoundError, verify the path to your saved index file or directory.
  • Ensure the llama-index package version supports your index format.
  • If the index fails to load, check if the index was saved with a compatible version of the library.

Key Takeaways

  • Use load_from_disk to restore a LlamaIndex index saved on disk.
  • Different index types support similar loading methods for flexibility.
  • Verify file paths and library versions to avoid loading errors.
Verified 2026-04
Verify ↗