or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

agents.mdchat-engines.mddocument-processing.mdembeddings.mdindex.mdllm-integration.mdquery-engines.mdresponse-synthesis.mdsettings.mdstorage.mdtools.mdvector-indexing.md
tile.json

storage.mddocs/

0

# Storage System

1

2

Persistent storage backends for documents, indices, and vector data across different storage systems in LlamaIndex.TS.

3

4

## Import

5

6

```typescript

7

import { StorageContext, SimpleDocumentStore, SimpleVectorStore } from "llamaindex";

8

```

9

10

## Overview

11

12

The storage system provides persistent backends for documents, indices, and vector data, enabling data persistence across application restarts and scalable storage solutions.

13

14

## Storage Context

15

16

```typescript { .api }

17

class StorageContext {

18

static fromDefaults(options?: {

19

docStore?: BaseDocumentStore;

20

indexStore?: BaseIndexStore;

21

vectorStore?: BaseVectorStore;

22

persistDir?: string;

23

}): StorageContext;

24

25

persist(persistDir?: string): Promise<void>;

26

27

docStore: BaseDocumentStore;

28

indexStore: BaseIndexStore;

29

vectorStore: BaseVectorStore;

30

}

31

```

32

33

## Document Stores

34

35

```typescript { .api }

36

interface BaseDocumentStore {

37

addDocuments(documents: Document[]): Promise<void>;

38

getDocument(docId: string): Promise<Document | undefined>;

39

getAllDocuments(): Promise<Document[]>;

40

deleteDocument(docId: string): Promise<void>;

41

}

42

43

class SimpleDocumentStore implements BaseDocumentStore {

44

constructor();

45

46

addDocuments(documents: Document[]): Promise<void>;

47

getDocument(docId: string): Promise<Document | undefined>;

48

getAllDocuments(): Promise<Document[]>;

49

deleteDocument(docId: string): Promise<void>;

50

51

persist(persistPath: string): Promise<void>;

52

static fromPersistDir(persistDir: string): Promise<SimpleDocumentStore>;

53

}

54

```

55

56

## Basic Usage

57

58

```typescript

59

import { StorageContext, VectorStoreIndex } from "llamaindex";

60

61

// Create persistent storage

62

const storageContext = StorageContext.fromDefaults({

63

persistDir: "./storage",

64

});

65

66

// Create index with persistent storage

67

const index = await VectorStoreIndex.fromDocuments(documents, {

68

storageContext,

69

});

70

71

// Persist to disk

72

await storageContext.persist("./storage");

73

74

// Load from disk

75

const loadedContext = StorageContext.fromDefaults({

76

persistDir: "./storage",

77

});

78

```