Skip to content

Commit

Permalink
fix: setDocumentHash should be async (run-llama#868)
Browse files Browse the repository at this point in the history
  • Loading branch information
pserrer1 authored Jun 3, 2024
1 parent da1f025 commit a29d835
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .changeset/twelve-bottles-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"llamaindex": minor
"docs": minor
---

setDocumentHash should be async
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ custom_edit_url: null

### setDocumentHash

`Abstract` **setDocumentHash**(`docId`, `docHash`): `void`
`Abstract` **setDocumentHash**(`docId`, `docHash`): `Promise`<`void`\>

#### Parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ custom_edit_url: null

### setDocumentHash

`Abstract` **setDocumentHash**(`docId`, `docHash`): `void`
`Abstract` **setDocumentHash**(`docId`, `docHash`): `Promise`<`void`\>

#### Parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ custom_edit_url: null

### setDocumentHash

`Abstract` **setDocumentHash**(`docId`, `docHash`): `void`
`Abstract` **setDocumentHash**(`docId`, `docHash`): `Promise`<`void`\>

#### Parameters

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/indices/BaseIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export abstract class BaseIndex<T> {
[nodeParserFromSettingsOrContext(this.serviceContext)],
);
await this.insertNodes(nodes);
this.docStore.setDocumentHash(document.id_, document.hash);
await this.docStore.setDocumentHash(document.id_, document.hash);
}

abstract insertNodes(nodes: BaseNode[]): Promise<void>;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/indices/keyword/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export class KeywordTableIndex extends BaseIndex<KeywordTable> {

await docStore.addDocuments(documents, true);
for (const doc of documents) {
docStore.setDocumentHash(doc.id_, doc.hash);
await docStore.setDocumentHash(doc.id_, doc.hash);
}

const nodes = serviceContext.nodeParser.getNodesFromDocuments(documents);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/indices/summary/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class SummaryIndex extends BaseIndex<IndexList> {

await docStore.addDocuments(documents, true);
for (const doc of documents) {
docStore.setDocumentHash(doc.id_, doc.hash);
await docStore.setDocumentHash(doc.id_, doc.hash);
}

const nodes =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class DuplicatesStrategy implements TransformComponent {

for (const node of nodes) {
if (!(node.hash in hashes) && !currentHashes.has(node.hash)) {
this.docStore.setDocumentHash(node.id_, node.hash);
await this.docStore.setDocumentHash(node.id_, node.hash);
nodesToRun.push(node);
currentHashes.add(node.hash);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/storage/docStore/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export abstract class BaseDocumentStore {
abstract documentExists(docId: string): Promise<boolean>;

// Hash
abstract setDocumentHash(docId: string, docHash: string): void;
abstract setDocumentHash(docId: string, docHash: string): Promise<void>;

abstract getDocumentHash(docId: string): Promise<string | undefined>;

Expand Down

0 comments on commit a29d835

Please sign in to comment.