Closed dejoma closed 2 months ago
To resolve the TypeScript type mismatch error when passing Pinecone.Index
to PineconeStore.fromExistingIndex
, ensure that the pineconeIndex
parameter in the PineconeStoreParams
interface is of type PineconeIndex
. The PineconeStore.fromExistingIndex
method expects a PineconeStoreParams
object, which includes the pineconeIndex
property of type PineconeIndex
.
Here is an example of how you can correctly pass the PineconeIndex
to PineconeStore.fromExistingIndex
:
import { PineconeIndex } from "@pinecone-database/pinecone";
import { PineconeStore } from "path-to-your-pinecone-store";
import { EmbeddingsInterface } from "@langchain/core/embeddings";
// Assuming you have an instance of PineconeIndex
const pineconeIndex: PineconeIndex = new PineconeIndex("your-index-name", { /* your config */ });
// Your embeddings instance
const embeddings: EmbeddingsInterface = /* your embeddings instance */;
// Configuration for PineconeStore
const dbConfig = {
pineconeIndex: pineconeIndex,
textKey: "text",
namespace: "your-namespace",
};
// Create PineconeStore from existing index
PineconeStore.fromExistingIndex(embeddings, dbConfig)
.then((pineconeStore) => {
console.log("PineconeStore created successfully", pineconeStore);
})
.catch((error) => {
console.error("Error creating PineconeStore", error);
});
Ensure that the pineconeIndex
you are passing is indeed an instance of PineconeIndex
and that it matches the expected type in the PineconeStoreParams
interface.
Additionally, you can refer to the test cases in the libs/langchain-pinecone/src/tests/vectorstores.test.ts
file for more examples of how to instantiate and use PineconeStore
. For instance, the test cases show how to mock a Pinecone client and use it with PineconeStore
:
import { jest, test, expect } from "@jest/globals";
import { FakeEmbeddings } from "@langchain/core/utils/testing";
import { PineconeStore } from "../vectorstores.js";
test("PineconeStore with external ids", async () => {
const upsert = jest.fn();
const client = {
namespace: jest.fn<any>().mockReturnValue({
upsert,
query: jest.fn<any>().mockResolvedValue({
matches: [],
}),
}),
};
const embeddings = new FakeEmbeddings();
const store = new PineconeStore(embeddings, { pineconeIndex: client as any });
expect(store).toBeDefined();
await store.addDocuments(
[
{
pageContent: "hello",
metadata: {
a: 1,
b: { nested: [1, { a: 4 }] },
},
},
],
["id1"]
);
expect(upsert).toHaveBeenCalledTimes(1);
expect(upsert).toHaveBeenCalledWith([
{
id: "id1",
metadata: { a: 1, "b.nested.0": 1, "b.nested.1.a": 4, text: "hello" },
values: [0.1, 0.2, 0.3, 0.4],
},
]);
const results = await store.similaritySearch("hello", 1);
expect(results).toHaveLength(0);
});
These examples should help you understand how to correctly configure and use PineconeStore
with the updated packages [1][2].
To continue talking to Dosu, mention @dosu.
Closing as a duplicate of #5685
Checked other resources
Example Code
Package updates that trigger fail
If you update all pinecone/langchain packages to their latest versions:
Code
Then the following code starts failing (in build-time):
Error messages
Error with custom type:
Error without custom type:![image](https://github.com/langchain-ai/langchainjs/assets/48984220/16a32313-c2aa-44c3-a584-2abf3ee8a452)
Error Message and Stack Trace (if applicable)
No response
Description
This is the code that works with the version numbers before upgrading.
System Info
I am using bun 1.1.12 Node v20 Build fails