Skip to content

Commit

Permalink
fix: ignore empty vector store
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusschiesser committed May 21, 2024
1 parent fb2c1fa commit ad26d6f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/core/src/storage/vectorStore/SimpleVectorStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,20 @@ export class SimpleVectorStore

async persist(
persistPath: string = path.join(DEFAULT_PERSIST_DIR, "vector_store.json"),
): Promise<void> {
await SimpleVectorStore.persistData(persistPath, this.data);
}

protected static async persistData(
persistPath: string,
data: SimpleVectorStoreData,
): Promise<void> {
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(
Expand All @@ -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();
Expand Down

0 comments on commit ad26d6f

Please sign in to comment.