Skip to content

Commit

Permalink
fix(pinecone): fix PineconeStore to support null or undefined pageCon…
Browse files Browse the repository at this point in the history
…tent (langchain-ai#6920)

Co-authored-by: Jacob Lee <[email protected]>
  • Loading branch information
sam-trost and jacoblee93 authored Oct 3, 2024
1 parent d3affce commit 5a4b926
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
30 changes: 29 additions & 1 deletion libs/langchain-pinecone/src/tests/vectorstores.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { jest, test, expect } from "@jest/globals";
import { expect, jest, test } from "@jest/globals";
import { FakeEmbeddings } from "@langchain/core/utils/testing";
import { PineconeStore } from "../vectorstores.js";

Expand Down Expand Up @@ -119,6 +119,34 @@ test("PineconeStore with string arrays", async () => {
]);
});

describe("PineconeStore with null pageContent", () => {
it("should handle null pageContent correctly in _formatMatches", async () => {
const mockQueryResponse = {
matches: [
{
id: "1",
score: 0.9,
metadata: { textKey: null, otherKey: "value" },
},
],
};

const client = {
namespace: jest.fn<any>().mockReturnValue({
query: jest.fn<any>().mockResolvedValue(mockQueryResponse),
}),
};
const embeddings = new FakeEmbeddings();

const store = new PineconeStore(embeddings, {
pineconeIndex: client as any,
});

const results = await store.similaritySearchVectorWithScore([], 0);
expect(results[0][0].pageContent).toEqual("");
});
});

test("PineconeStore can instantiate without passing in client", async () => {
const embeddings = new FakeEmbeddings();

Expand Down
2 changes: 1 addition & 1 deletion libs/langchain-pinecone/src/vectorstores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ export class PineconeStore extends VectorStore {
documentsWithScores.push([
new Document({
id,
pageContent: pageContent.toString(),
pageContent: pageContent?.toString() ?? "",
metadata,
}),
score,
Expand Down

0 comments on commit 5a4b926

Please sign in to comment.