Skip to content
Snippets Groups Projects
Commit a07a9410 authored by Yi Ding's avatar Yi Ding
Browse files

more persistence

parent a7cc8020
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,7 @@ import { ...@@ -23,6 +23,7 @@ import {
} from "../BaseIndex"; } from "../BaseIndex";
import { BaseRetriever } from "../../Retriever"; import { BaseRetriever } from "../../Retriever";
import { ResponseSynthesizer } from "../../ResponseSynthesizer"; import { ResponseSynthesizer } from "../../ResponseSynthesizer";
import { BaseDocumentStore } from "../../storage/docStore/types";
/** /**
* The VectorStoreIndex, an index that stores the nodes only according to their vector embedings. * The VectorStoreIndex, an index that stores the nodes only according to their vector embedings.
...@@ -61,7 +62,8 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> { ...@@ -61,7 +62,8 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
indexStruct = await VectorStoreIndex.buildIndexFromNodes( indexStruct = await VectorStoreIndex.buildIndexFromNodes(
options.nodes, options.nodes,
serviceContext, serviceContext,
vectorStore vectorStore,
docStore
); );
} }
...@@ -112,7 +114,8 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> { ...@@ -112,7 +114,8 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
static async buildIndexFromNodes( static async buildIndexFromNodes(
nodes: BaseNode[], nodes: BaseNode[],
serviceContext: ServiceContext, serviceContext: ServiceContext,
vectorStore: VectorStore vectorStore: VectorStore,
docStore: BaseDocumentStore
): Promise<IndexDict> { ): Promise<IndexDict> {
const embeddingResults = await this.getNodeEmbeddingResults( const embeddingResults = await this.getNodeEmbeddingResults(
nodes, nodes,
...@@ -121,6 +124,13 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> { ...@@ -121,6 +124,13 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
vectorStore.add(embeddingResults); vectorStore.add(embeddingResults);
if (!vectorStore.storesText) {
await docStore.addDocuments(
embeddingResults.map((result) => result.node),
true
);
}
const indexDict = new IndexDict(); const indexDict = new IndexDict();
for (const { node } of embeddingResults) { for (const { node } of embeddingResults) {
indexDict.addNode(node); indexDict.addNode(node);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment