Customizing Storage

By default, LlamaIndex hides away the complexities and let you query your data in under 5 lines of code:

from llama_index import VectorStoreIndex, SimpleDirectoryReader

documents = SimpleDirectoryReader('data').load_data()
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()
response = query_engine.query("Summarize the documents.")

Under the hood, LlamaIndex also supports a swappable storage layer that allows you to customize where ingested documents (i.e., Node objects), embedding vectors, and index metadata are stored.

Low-Level API

To do this, instead of the high-level API,

index = VectorStoreIndex.from_documents(documents)

we use a lower-level API that gives more granular control:

from import SimpleDocumentStore
from import SimpleIndexStore
from llama_index.vector_stores import SimpleVectorStore
from llama_index.node_parser import SimpleNodeParser

# create parser and parse document into nodes
parser = SimpleNodeParser.from_defaults()
nodes = parser.get_nodes_from_documents(documents)

# create storage context using default stores
storage_context = StorageContext.from_defaults(

# create (or load) docstore and add nodes

# build index
index = VectorStoreIndex(nodes, storage_context=storage_context)

# save index

# can also set index_id to save multiple indexes to the same folder
index.set_index_id = "<index_id>"

# to load index later, make sure you setup the storage context
# this will loaded the persisted stores from persist_dir
storage_context = StorageContext.from_defaults(

# then load the index object
from llama_index import load_index_from_storage
loaded_index = load_index_from_storage(storage_context)

# if loading an index from a persist_dir containing multiple indexes
loaded_index = load_index_from_storage(storage_context, index_id="<index_id>")

# if loading multiple indexes from a persist dir
loaded_indicies = load_index_from_storage(storage_context, index_ids=["<index_id>", ...])

You can customize the underlying storage with a one-line change to instantiate different document stores, index stores, and vector stores. See Document Stores, Vector Stores, Index Stores guides for more details.

For saving and loading a graph/composable index, see the full guide here.

Vector Store Integrations and Storage

Most of our vector store integrations store the entire index (vectors + text) in the vector store itself. This comes with the major benefit of not having to exlicitly persist the index as shown above, since the vector store is already hosted and persisting the data in our index.

The vector stores that support this practice are:

  • CognitiveSearchVectorStore

  • ChatGPTRetrievalPluginClient

  • CassandraVectorStore

  • ChromaVectorStore

  • EpsillaVectorStore

  • DocArrayHnswVectorStore

  • DocArrayInMemoryVectorStore

  • LanceDBVectorStore

  • MetalVectorStore

  • MilvusVectorStore

  • MyScaleVectorStore

  • OpensearchVectorStore

  • PineconeVectorStore

  • QdrantVectorStore

  • RedisVectorStore

  • WeaviateVectorStore

A small example using Pinecone is below:

import pinecone
from llama_index import VectorStoreIndex, SimpleDirectoryReader
from llama_index.vector_stores import PineconeVectorStore

# Creating a Pinecone index
api_key = "api_key"
pinecone.init(api_key=api_key, environment="us-west1-gcp")
index = pinecone.Index("quickstart")

# construct vector store
vector_store = PineconeVectorStore(pinecone_index=index)

# create storage context
storage_context = StorageContext.from_defaults(vector_store=vector_store)

# load documents
documents = SimpleDirectoryReader("./data").load_data()

# create index, which will insert documents/vectors to pinecone
index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)

If you have an existing vector store with data already loaded in, you can connect to it and directly create a VectorStoreIndex as follows:

index = pinecone.Index("quickstart")
vector_store = PineconeVectorStore(pinecone_index=index)
loaded_index = VectorStoreIndex.from_vector_store(vector_store=vector_store)