存储上下文

LlamaIndex提供了关于节点、索引和向量存储的核心抽象。关键的抽象是`StorageContext`-它包含底层的`BaseDocumentStore`(用于节点)、`BaseIndexStore`(用于索引)和`VectorStore`(用于向量)。

文档/节点和索引存储依赖于一个共同的`KVStore`抽象,详情参见下文。

我们在下面展示了存储类的API参考、从存储上下文加载索引以及存储上下文类本身的参考。



加载索引


class llama_index.storage.storage_context.StorageContext(docstore: 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