Closed sandeep2569 closed 1 month ago
The error you're encountering suggests there's an issue with the structure of the docs
object passed to PineconeStore.fromDocuments
, specifically that elements within docs
are missing the expected text
property. To resolve this, you should first verify the structure of docs
after splitting the documents. Ensure each element has a text
property by inspecting the output of textSplitter.splitDocuments(rawDocs)
.
If the structure doesn't match expectations, you may need to adjust docs
before passing it to PineconeStore.fromDocuments
. For example, if docs
is supposed to be an array of objects with a text
property but isn't formatted correctly, you'll need to transform docs
to ensure each object contains a text
key with the appropriate value.
Here's a quick way to debug and potentially adjust the docs
structure:
Log the structure of docs
to confirm each element contains a text
property:
console.log('split docs', JSON.stringify(docs, null, 2));
If the structure is incorrect, adjust docs
accordingly:
const adjustedDocs = docs.map(doc => ({
text: doc.someOtherProperty // Replace `someOtherProperty` with the actual property name
}));
Then, use adjustedDocs
in place of docs
when calling PineconeStore.fromDocuments
.
This approach should help you resolve the "TypeError: Cannot read properties of undefined (reading 'text')" error by ensuring the data passed to PineconeStore.fromDocuments
is correctly structured.
To continue the conversation, mention @dosu.
Tried all the solution but still facing this issue please help here is my Code ⬇️
import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter'; import { OpenAIEmbeddings } from "@langchain/openai"; import { PineconeStore } from "@langchain/pinecone"; import { pinecone } from '@/utils/pinecone-client'; import { PDFLoader } from 'langchain/document_loaders/fs/pdf'; import { PINECONE_INDEX_NAME, PINECONE_NAME_SPACE } from '@/config/pinecone'; import { DirectoryLoader } from 'langchain/document_loaders/fs/directory';
/ Name of directory to retrieve your files from Make sure to add your PDF files inside the 'docs' folder / const filePath = 'docs';
export const run = async () => { try { /load raw docs from the all files in the directory / const directoryLoader = new DirectoryLoader(filePath, { '.pdf': (path) => new PDFLoader(path), });
} catch (error) { throw new Error('Failed to ingest your data'); } };
(async () => { await run(); console.log('ingestion complete'); })();