Data framework for your LLM application
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Persistent storage backends for documents, indices, and vector data across different storage systems in LlamaIndex.TS.
import { StorageContext, SimpleDocumentStore, SimpleVectorStore } from "llamaindex";The storage system provides persistent backends for documents, indices, and vector data, enabling data persistence across application restarts and scalable storage solutions.
class StorageContext {
static fromDefaults(options?: {
docStore?: BaseDocumentStore;
indexStore?: BaseIndexStore;
vectorStore?: BaseVectorStore;
persistDir?: string;
}): StorageContext;
persist(persistDir?: string): Promise<void>;
docStore: BaseDocumentStore;
indexStore: BaseIndexStore;
vectorStore: BaseVectorStore;
}interface BaseDocumentStore {
addDocuments(documents: Document[]): Promise<void>;
getDocument(docId: string): Promise<Document | undefined>;
getAllDocuments(): Promise<Document[]>;
deleteDocument(docId: string): Promise<void>;
}
class SimpleDocumentStore implements BaseDocumentStore {
constructor();
addDocuments(documents: Document[]): Promise<void>;
getDocument(docId: string): Promise<Document | undefined>;
getAllDocuments(): Promise<Document[]>;
deleteDocument(docId: string): Promise<void>;
persist(persistPath: string): Promise<void>;
static fromPersistDir(persistDir: string): Promise<SimpleDocumentStore>;
}import { StorageContext, VectorStoreIndex } from "llamaindex";
// Create persistent storage
const storageContext = StorageContext.fromDefaults({
persistDir: "./storage",
});
// Create index with persistent storage
const index = await VectorStoreIndex.fromDocuments(documents, {
storageContext,
});
// Persist to disk
await storageContext.persist("./storage");
// Load from disk
const loadedContext = StorageContext.fromDefaults({
persistDir: "./storage",
});