Skip to content
Snippets Groups Projects
Unverified Commit 0721a849 authored by Marcus Schiesser's avatar Marcus Schiesser Committed by GitHub
Browse files

fix: ignore empty vector store (#861)

parent 4d4bd854
Branches
Tags
No related merge requests found
...@@ -151,13 +151,20 @@ export class SimpleVectorStore ...@@ -151,13 +151,20 @@ export class SimpleVectorStore
async persist( async persist(
persistPath: string = path.join(DEFAULT_PERSIST_DIR, "vector_store.json"), 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> { ): Promise<void> {
const dirPath = path.dirname(persistPath); const dirPath = path.dirname(persistPath);
if (!(await exists(dirPath))) { if (!(await exists(dirPath))) {
await fs.mkdir(dirPath); await fs.mkdir(dirPath);
} }
await fs.writeFile(persistPath, JSON.stringify(this.data)); await fs.writeFile(persistPath, JSON.stringify(data));
} }
static async fromPersistPath( static async fromPersistPath(
...@@ -177,6 +184,11 @@ export class SimpleVectorStore ...@@ -177,6 +184,11 @@ export class SimpleVectorStore
console.error( console.error(
`No valid data found at path: ${persistPath} starting new store.`, `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(); const data = new SimpleVectorStoreData();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment