Closed sam-trost closed 1 month ago
Hey there, @sam-trost! I'm here to help you with any bugs, questions, or contributions. Let's work on solving the issue together.
I found a similar discussion regarding the "TypeError: Cannot read properties of undefined (reading 'toString')" error in the PineconeStore when handling null pageContent
. The issue is that the current implementation assumes pageContent
is always defined, which can lead to this error if it is null.
To resolve this, you can modify the code in the _formatMatches
method to handle null pageContent
by providing a default value. Here's a possible solution:
private _formatMatches(
matches: ScoredPineconeRecord<RecordMetadata>[] = []
): [Document, number][] {
const documentsWithScores: [Document, number][] = [];
for (const record of matches) {
const {
id,
score,
metadata: { [this.textKey]: pageContent, ...metadata } = {
[this.textKey]: "",
},
} = record;
if (score) {
documentsWithScores.push([
new Document({
id,
pageContent: pageContent ? pageContent.toString() : "", // Provide a default empty string if pageContent is null
metadata,
}),
score,
]);
}
}
return documentsWithScores;
}
This modification ensures that if pageContent
is null, an empty string is used instead, preventing the toString
method from being called on an undefined value [1].
To continue talking to Dosu, mention @dosu.
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
TypeError: Cannot read properties of undefined (reading 'toString')
Description
The current version of the pinecone vector store assumes a property named pageContent will be set on each record. This was not previously required when ingesting content.
System Info
ββ langchain@workspace:langchain ββ Instances: 1 ββ Version: 0.3.2 β ββ Dependencies ββ @faker-js/faker@npm:^7.6.0 β npm:7.6.0 ββ @jest/globals@npm:^29.5.0 β npm:29.5.0 ββ @langchain/core@workspace: β workspace:langchain-core ββ @langchain/scripts@>=0.1.0 <0.2.0 β workspace:libs/langchain-scripts ββ @tsconfig/recommended@npm:^1.0.2 β npm:1.0.2 ββ @types/handlebars@npm:^4.1.0 β npm:4.1.0 ββ @types/html-to-text@npm:^9 β npm:9.0.0 ββ @types/js-yaml@npm:^4 β npm:4.0.5 ββ @types/jsdom@npm:^21.1.1 β npm:21.1.1 ββ @types/uuid@npm:^9 β npm:9.0.1 ββ @types/ws@npm:^8 β npm:8.5.8 ββ axios@npm:^0.26.0 β npm:0.26.1 ββ cheerio@npm:1.0.0-rc.12 β npm:1.0.0-rc.12 ββ dotenv@npm:^16.0.3 β npm:16.0.3 ββ dpdm@patch:dpdm@npm%3A3.12.0#./.yarn/patches/dpdm-npm-3.12.0-0dfdd8e3b8.patch::locator=langchainjs%40workspace%3A. β patch:dpdm@npm%3A3.12.0#./.yarn/patches/dpdm-npm-3.12.0-0dfdd8e3b8.patch::version=3.12.0&hash=2406a8&locator=langchainjs%40workspace%3A. ββ eslint-plugin-no-instanceof@npm:^1.0.1 β npm:1.0.1 ββ eslint@npm:^8.33.0 β npm:8.35.0 ββ handlebars@npm:^4.7.8 β npm:4.7.8 ββ jest-environment-node@npm:^29.6.4 β npm:29.6.4 ββ js-tiktoken@npm:^1.0.12 β npm:1.0.12 ββ js-yaml@npm:^4.1.0 β npm:4.1.0 ββ jsonpointer@npm:^5.0.1 β npm:5.0.1 ββ openai@npm:^4.41.1 β npm:4.42.0 ββ openapi-types@npm:^12.1.3 β npm:12.1.3 ββ p-retry@npm:4 β npm:4.6.2 ββ peggy@npm:^3.0.2 β npm:3.0.2 ββ prettier@npm:^2.8.3 β npm:2.8.4 ββ release-it@npm:^17.6.0 β npm:17.6.0 ββ rimraf@npm:^5.0.1 β npm:5.0.1 ββ rollup@npm:^3.19.1 β npm:3.19.1 ββ typescript@patch:typescript@~5.1.6#~builtin<compat/typescript> β patch:typescript@npm%3A5.1.6#~builtin<compat/typescript>::version=5.1.6&hash=77c9e2 ββ uuid@npm:^10.0.0 β npm:10.0.0 ββ wikipedia@npm:^2.1.2 β npm:2.1.2 ββ yaml@npm:^2.2.1 β npm:2.2.1 ββ zod@npm:3.23.8 β npm:3.23.8 ββ @langchain/anthropic@workspace: β workspace:libs/langchain-anthropic [773c0] ββ @langchain/aws@workspace: β workspace:libs/langchain-aws [773c0] ββ @langchain/cohere@workspace: β workspace:libs/langchain-cohere [773c0] ββ @langchain/google-genai@workspace: β workspace:libs/langchain-google-genai [773c0] ββ @langchain/google-vertexai@workspace: β workspace:libs/langchain-google-vertexai [773c0] ββ @langchain/groq@workspace: β workspace:libs/langchain-groq [773c0] ββ @langchain/mistralai@workspace: β workspace:libs/langchain-mistralai [773c0] ββ @langchain/ollama@workspace: β workspace:libs/langchain-ollama [773c0] ββ @langchain/openai@workspace: β workspace:libs/langchain-openai [773c0] ββ @langchain/textsplitters@workspace:* β workspace:libs/langchain-textsplitters [773c0] ββ @swc/core@npm:^1.3.90 β npm:1.3.90 [6dbfd] ββ @swc/jest@npm:^0.2.29 β npm:0.2.29 [6dbfd] ββ @typescript-eslint/eslint-plugin@npm:^5.58.0 β npm:5.58.0 [6d556] ββ @typescript-eslint/parser@npm:^5.58.0 β npm:5.58.0 [6d556] ββ eslint-config-airbnb-base@npm:^15.0.0 β npm:15.0.0 [6d556] ββ eslint-config-prettier@npm:^8.6.0 β npm:8.7.0 [6dbfd] ββ eslint-plugin-import@npm:^2.27.5 β npm:2.27.5 [6d556] ββ eslint-plugin-jest@npm:^27.6.0 β npm:27.6.0 [6d556] ββ eslint-plugin-prettier@npm:^4.2.1 β npm:4.2.1 [6dbfd] ββ jest@npm:^29.5.0 β npm:29.7.0 [6dbfd] ββ langsmith@npm:^0.1.56 β npm:0.1.56 [0b9fc] ββ ts-jest@npm:^29.1.0 β npm:29.1.0 [221f6] ββ typeorm@npm:^0.3.20 β npm:0.3.20 [3a972] ββ zod-to-json-schema@npm:^3.22.3 β npm:3.22.3 [221f6]