Storage Context

LlamaIndex offers core abstractions around storage of Nodes, indices, and vectors. A key abstraction is the StorageContext - this contains the underlying BaseDocumentStore (for nodes), BaseIndexStore (for indices), and VectorStore (for vectors).

The Document/Node and index stores rely on a common KVStore abstraction, which is also detailed below.

We show the API references for the Storage Classes, loading indices from the Storage Context, and the Storage Context class itself below.

Loading Indices

class BaseDocumentStore, index_store: BaseIndexStore, vector_store: VectorStore)

Storage context.

The storage context container is a utility container for storing nodes, indices, and vectors. It contains the following: - docstore: BaseDocumentStore - index_store: BaseIndexStore - vector_store: VectorStore

classmethod from_defaults(docstore: Optional[BaseDocumentStore] = None, index_store: Optional[BaseIndexStore] = None, vector_store: Optional[VectorStore] = None, persist_dir: Optional[str] = None, fs: Optional[AbstractFileSystem] = None) StorageContext

Create a StorageContext from defaults.

  • docstore (Optional[BaseDocumentStore]) – document store

  • index_store (Optional[BaseIndexStore]) – index store

  • vector_store (Optional[VectorStore]) – vector store

classmethod from_dict(save_dict: dict) StorageContext

Create a StorageContext from dict.

persist(persist_dir: str = './storage', docstore_fname: str = 'docstore.json', index_store_fname: str = 'index_store.json', vector_store_fname: str = 'vector_store.json', fs: Optional[AbstractFileSystem] = None) None

Persist the storage context.


persist_dir (str) – directory to persist the storage context