Skip to content
Snippets Groups Projects
Unverified Commit 72577519 authored by Thuc Pham's avatar Thuc Pham Committed by GitHub
Browse files

fix: empty store bugs (#592)

parent de6bfdb1
No related branches found
No related tags found
No related merge requests found
---
"llamaindex": patch
---
fixed removeRefDocNode and persist store on delete
import _, * as lodash from "lodash"; import _ from "lodash";
import type { BaseNode } from "../../Node.js"; import type { BaseNode } from "../../Node.js";
import { ObjectType } from "../../Node.js"; import { ObjectType } from "../../Node.js";
import { DEFAULT_NAMESPACE } from "../constants.js"; import { DEFAULT_NAMESPACE } from "../constants.js";
...@@ -123,10 +123,10 @@ export class KVDocumentStore extends BaseDocumentStore { ...@@ -123,10 +123,10 @@ export class KVDocumentStore extends BaseDocumentStore {
const refDocInfo = await this.kvstore.get(refDocId, this.refDocCollection); const refDocInfo = await this.kvstore.get(refDocId, this.refDocCollection);
if (!_.isNil(refDocInfo)) { if (!_.isNil(refDocInfo)) {
lodash.pull(refDocInfo.docIds, docId); !_.pull(refDocInfo.nodeIds, docId);
if (refDocInfo.docIds.length > 0) { if (refDocInfo.nodeIds.length > 0) {
this.kvstore.put(refDocId, refDocInfo.toDict(), this.refDocCollection); this.kvstore.put(refDocId, refDocInfo, this.refDocCollection);
} }
this.kvstore.delete(refDocId, this.metadataCollection); this.kvstore.delete(refDocId, this.metadataCollection);
} }
......
...@@ -54,6 +54,9 @@ export class SimpleKVStore extends BaseKVStore { ...@@ -54,6 +54,9 @@ export class SimpleKVStore extends BaseKVStore {
): Promise<boolean> { ): Promise<boolean> {
if (key in this.data[collection]) { if (key in this.data[collection]) {
delete this.data[collection][key]; delete this.data[collection][key];
if (this.persistPath) {
await this.persist(this.persistPath, this.fs);
}
return true; return true;
} }
return false; return false;
......
...@@ -82,6 +82,9 @@ export class SimpleVectorStore implements VectorStore { ...@@ -82,6 +82,9 @@ export class SimpleVectorStore implements VectorStore {
delete this.data.embeddingDict[textId]; delete this.data.embeddingDict[textId];
delete this.data.textIdToRefDocId[textId]; delete this.data.textIdToRefDocId[textId];
} }
if (this.persistPath) {
await this.persist(this.persistPath, this.fs);
}
return Promise.resolve(); return Promise.resolve();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment