-
Notifications
You must be signed in to change notification settings - Fork 295
/
StorageContext.ts
55 lines (51 loc) · 1.53 KB
/
StorageContext.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { GenericFileSystem } from "./FileSystem";
import { DEFAULT_FS, DEFAULT_NAMESPACE } from "./constants";
import { SimpleDocumentStore } from "./docStore/SimpleDocumentStore";
import { BaseDocumentStore } from "./docStore/types";
import { SimpleIndexStore } from "./indexStore/SimpleIndexStore";
import { BaseIndexStore } from "./indexStore/types";
import { SimpleVectorStore } from "./vectorStore/SimpleVectorStore";
import { VectorStore } from "./vectorStore/types";
export interface StorageContext {
docStore: BaseDocumentStore;
indexStore: BaseIndexStore;
vectorStore: VectorStore;
}
type BuilderParams = {
docStore?: BaseDocumentStore;
indexStore?: BaseIndexStore;
vectorStore?: VectorStore;
persistDir?: string;
fs?: GenericFileSystem;
};
export async function storageContextFromDefaults({
docStore,
indexStore,
vectorStore,
persistDir,
fs,
}: BuilderParams): Promise<StorageContext> {
if (!persistDir) {
docStore = docStore || new SimpleDocumentStore();
indexStore = indexStore || new SimpleIndexStore();
vectorStore = vectorStore || new SimpleVectorStore();
} else {
fs = fs || DEFAULT_FS;
docStore =
docStore ||
(await SimpleDocumentStore.fromPersistDir(
persistDir,
DEFAULT_NAMESPACE,
fs,
));
indexStore =
indexStore || (await SimpleIndexStore.fromPersistDir(persistDir, fs));
vectorStore =
vectorStore || (await SimpleVectorStore.fromPersistDir(persistDir, fs));
}
return {
docStore,
indexStore,
vectorStore,
};
}