Open dejoma opened 4 weeks ago
To resolve the TypeScript type mismatch error (TS2322) when using Pinecone and Langchain packages with the latest versions, ensure that the pineconeIndex
property in PineconeStoreParams
is correctly typed as Index<RecordMetadata> | undefined
. The provided code already defines pineconeIndex
as an optional property of type PineconeIndex
in the PineconeStoreParams
interface:
export interface PineconeStoreParams extends AsyncCallerParams {
pineconeIndex?: PineconeIndex;
textKey?: string;
namespace?: string;
filter?: PineconeMetadata;
pineconeConfig?: {
indexName: ConstructorParameters<typeof PineconeIndex>[0];
config: ConstructorParameters<typeof PineconeIndex>[1];
namespace?: string;
indexHostUrl?: string;
additionalHeaders?: HTTPHeaders;
};
}
In the PineconeStore
class constructor, the pineconeIndex
is correctly assigned based on the provided parameters:
constructor(embeddings: EmbeddingsInterface, params: PineconeStoreParams) {
super(embeddings, params);
this.embeddings = embeddings;
const {
namespace,
pineconeIndex,
textKey,
filter,
pineconeConfig,
...asyncCallerArgs
} = params;
this.namespace = namespace;
if (!pineconeIndex && !pineconeConfig) {
throw new Error("pineconeConfig or pineconeIndex must be provided.");
}
if (pineconeIndex && pineconeConfig) {
throw new Error(
"Only one of pineconeConfig or pineconeIndex can be provided."
);
}
if (pineconeIndex) {
this.pineconeIndex = pineconeIndex;
} else if (pineconeConfig) {
this.pineconeIndex = new PineconeIndex(
pineconeConfig.indexName,
{
...pineconeConfig.config,
sourceTag: "langchainjs",
},
pineconeConfig.namespace,
pineconeConfig.indexHostUrl,
pineconeConfig.additionalHeaders
);
}
this.textKey = textKey ?? "text";
this.filter = filter;
this.caller = new AsyncCaller(asyncCallerArgs);
}
Ensure that the PineconeIndex
type is correctly imported and used. The PineconeIndex
type should be imported from the @pinecone-database/pinecone
package:
import { Index as PineconeIndex } from "@pinecone-database/pinecone";
Additionally, refer to the test cases provided in the libs/langchain-pinecone/src/tests/vectorstores.test.ts
file to ensure that your implementation aligns with the expected usage. For example, the test cases show how to instantiate PineconeStore
with the pineconeIndex
property:
const store = new PineconeStore(embeddings, { pineconeIndex: client as any });
Make sure that the PineconeIndex
type is correctly defined in the @pinecone-database/pinecone
package and that you are using the latest versions of both Pinecone and Langchain packages. If the error persists, it might be due to a version mismatch or an incorrect type definition in the Pinecone package [1][2].
To continue talking to Dosu, mention @dosu.
Hey @dejoma, sorry you're running into this - could you share your lockfile? I'm unable to repro with my local setup.
Additionally (a bit of a shot in the dark) - can you try explicitly resolving your @langchain/core
to a single version?
https://js.langchain.com/v0.2/docs/how_to/installation/#installing-integration-packages
Checklist
Issue with current documentation:
If you update all pinecone/langchain packages to their latest versions:
Then the following code starts failing (in build-time):
Error with custom type:
Error without custom type:![image](https://github.com/langchain-ai/langchainjs/assets/48984220/16a32313-c2aa-44c3-a584-2abf3ee8a452)
Idea or request for content:
No response