Skip to content

Commit

Permalink
fix(community): Add id in chroma search result (#7120)
Browse files Browse the repository at this point in the history
Co-authored-by: jacoblee93 <[email protected]>
  • Loading branch information
kwei-zhang and jacoblee93 authored Nov 5, 2024
1 parent 2e19277 commit fcef784
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions libs/langchain-community/src/vectorstores/chroma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ export class Chroma extends VectorStore {
new Document({
pageContent: firstDocuments?.[i] ?? "",
metadata,
id: firstIds[i],
}),
firstDistances[i],
]);
Expand Down
19 changes: 19 additions & 0 deletions libs/langchain-community/src/vectorstores/tests/chroma.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,23 @@ describe("Chroma", () => {
});
expect(results).toHaveLength(5);
});

test("should return id properly when adding documents", async () => {
const document1 = {
pageContent: "Document 1",
metadata: { source: "https://example.com" },
};

const documents = [document1];

const chroma = new Chroma(new FakeEmbeddings(), {
collectionName: "new-test-collection",
index: mockClient,
});

await chroma.addDocuments(documents, { ids: ["0"] });
const result = await chroma.similaritySearch(document1.pageContent, 1);

expect(result[0]).toHaveProperty("id", "0");
});
});

0 comments on commit fcef784

Please sign in to comment.