Skip to content
Snippets Groups Projects
Unverified Commit b17d439d authored by LAWG's avatar LAWG Committed by GitHub
Browse files

fix: ensure `id_` is correctly passed during creation (#1282)


Co-authored-by: default avatarlawrencegb <lawrence@3api.com>
Co-authored-by: default avatarAlex Yang <himself65@outlook.com>
parent 040160c3
No related branches found
No related tags found
No related merge requests found
---
"@llamaindex/core": patch
---
Fix #1278: resolved issue where the id\_ was not correctly passed as the id when creating a TextNode. As a result, the upsert operation to the vector database was using a generated ID instead of the provided document ID, if available.
......@@ -479,7 +479,7 @@ export function buildNodeFromSplits(
) {
const imageDoc = doc as ImageNode;
const imageNode = new ImageNode({
id_: idGenerator(i, imageDoc),
id_: imageDoc.id_ ?? idGenerator(i, imageDoc),
text: textChunk,
image: imageDoc.image,
embedding: imageDoc.embedding,
......@@ -496,7 +496,7 @@ export function buildNodeFromSplits(
) {
const textDoc = doc as TextNode;
const node = new TextNode({
id_: idGenerator(i, textDoc),
id_: textDoc.id_ ?? idGenerator(i, textDoc),
text: textChunk,
embedding: textDoc.embedding,
excludedEmbedMetadataKeys: [...textDoc.excludedEmbedMetadataKeys],
......
......@@ -27,7 +27,7 @@ describe("VectorStoreIndex", () => {
runs: number = 2,
): Promise<Array<number>> => {
const documents = [new Document({ text: "lorem ipsem", id_: "1" })];
const entries = [];
const entries: number[] = [];
for (let i = 0; i < runs; i++) {
await VectorStoreIndex.fromDocuments(documents, {
serviceContext,
......@@ -43,7 +43,7 @@ describe("VectorStoreIndex", () => {
test("fromDocuments stores duplicates without a doc store strategy", async () => {
const entries = await testStrategy(DocStoreStrategy.NONE);
expect(entries[0]! + 1).toBe(entries[1]);
expect(entries[0]).toBe(entries[1]);
});
test("fromDocuments ignores duplicates with upserts doc store strategy", async () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment