Compare commits

...

1 Commits

Author SHA1 Message Date
Marcus Schiesser ad26d6fc47 fix: ignore empty vector store 2024-05-21 15:16:08 +02:00
@@ -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(
@@ -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();