langchainjs
langchainjs copied to clipboard
Error initializing the application: TypeError: Cannot read properties of undefined (reading 'index')
`import { Chroma } from 'langchain/vectorstores'; import { OpenAIEmbeddings } from "langchain/embeddings";
import { CharacterTextSplitter } from 'langchain/text_splitter'; import { DirectoryLoader, PDFLoader } from 'langchain/document_loaders'; import { RetrievalQAChain } from 'langchain/chains'; import { OpenAI } from "langchain/llms"; import pdfjsLib from "pdfjs-dist-legacy";
pdfjsLib.GlobalWorkerOptions.workerSrc = "pdf.worker.js"; const model = new OpenAI();
async function main() {
const loader = new DirectoryLoader( "data", { ".pdf": (path) => new PDFLoader(path, {pdfjsLib}),
}
);
const documents = await loader.load();
const textSplitter = new CharacterTextSplitter({ chunkSize: 1000, chunkOverlap: 0 }); const texts = await textSplitter.splitDocuments(documents);
const embeddings = new OpenAIEmbeddings(); const docsearch = await Chroma.fromDocuments(texts, embeddings);
const qa = RetrievalQAChain.fromChainType({ llm: model, chainType: 'stuff', retriever: docsearch.asRetriever({ searchKwargs: { k: 1 } }), });
return qa; }
export default main; `
I am getting the error for Chroma running this in node.js
Hi, can you share the full error you're getting?
Hi, @hvardhan878! I'm here to help the LangChain team manage their backlog, and I wanted to let you know that we are marking this issue as stale.
From what I understand, you encountered a "TypeError: Cannot read properties of undefined (reading 'index')" error when running the code in Node.js. nfcampos has asked for more details about the error, but it seems that there hasn't been any further response or resolution to the issue.
Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself or it will be automatically closed in 7 days.
Thank you for your understanding and contribution to the LangChain project!