diff --git a/packages/core/src/storage/vectorStore/SimpleVectorStore.ts b/packages/core/src/storage/vectorStore/SimpleVectorStore.ts index 35e801e46b..9676806ab6 100644 --- a/packages/core/src/storage/vectorStore/SimpleVectorStore.ts +++ b/packages/core/src/storage/vectorStore/SimpleVectorStore.ts @@ -151,13 +151,20 @@ export class SimpleVectorStore async persist( persistPath: string = path.join(DEFAULT_PERSIST_DIR, "vector_store.json"), + ): Promise { + await SimpleVectorStore.persistData(persistPath, this.data); + } + + protected static async persistData( + persistPath: string, + data: SimpleVectorStoreData, ): Promise { const dirPath = path.dirname(persistPath); if (!(await exists(dirPath))) { await fs.mkdir(dirPath); } - await fs.writeFile(persistPath, JSON.stringify(this.data)); + await fs.writeFile(persistPath, JSON.stringify(data)); } static async fromPersistPath( @@ -177,6 +184,11 @@ export class SimpleVectorStore console.error( `No valid data found at path: ${persistPath} starting new store.`, ); + // persist empty data, to ignore this error in the future + await SimpleVectorStore.persistData( + persistPath, + new SimpleVectorStoreData(), + ); } const data = new SimpleVectorStoreData();