Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of undefined (reading embedQuery) #2549

Closed
darshanhande11 opened this issue Sep 7, 2023 · 5 comments
Closed

Cannot read properties of undefined (reading embedQuery) #2549

darshanhande11 opened this issue Sep 7, 2023 · 5 comments
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@darshanhande11
Copy link

darshanhande11 commented Sep 7, 2023

I am getting the following error when I am using VectorDBQAChain as a tool to the agent.

TypeError: Cannot read properties of undefined (reading 'embedQuery')
at HNSWLib.similaritySearch (/Users/darshanhande/Documents/opensource/Application/node_modules/langchain/dist/vectorstores/base.cjs:107:90)
at VectorStoreRetriever._getRelevantDocuments (/Users/darshanhande/Documents/opensource/Application/node_modules/langchain/dist/vectorstores/base.cjs:71:33)     
at VectorStoreRetriever.getRelevantDocuments (/Users/darshanhande/Documents/opensource/Application/node_modules/langchain/dist/schema/retriever.cjs:72:40)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at RetrievalQAChain._call (/Users/darshanhande/Documents/opensource/Application/node_modules/langchain/dist/chains/retrieval_qa.cjs:58:22)
at RetrievalQAChain.call (/Users/darshanhande/Documents/opensource/Application/node_modules/langchain/dist/chains/base.cjs:104:28)
at RetrievalQAChain.run (/Users/darshanhande/Documents/opensource/Application/node_modules/langchain/dist/chains/base.cjs:69:30)
at ChainTool.call (/Users/darshanhande/Documents/opensource/Application/node_modules/langchain/dist/tools/base.cjs:50:22)
at /Users/darshanhande/Documents/opensource/Application/node_modules/langchain/dist/agents/executor.cjs:113:23
at async Promise.all (index 0)
at AgentExecutor._call (/Users/darshanhande/Documents/opensource/Application/node_modules/langchain/dist/agents/executor.cjs:109:30)
at AgentExecutor.call (/Users/darshanhande/Documents/opensource/Application/node_modules/langchain/dist/chains/base.cjs:104:28)

Following is the code which I have used.

const vectorStore = await HNSWLib.load("./src/vector_store");
const chain = VectorDBQAChain.fromLLM(model, vectorStore);
const qaTool = new ChainTool({
    name: "course-data-qa",
    description: "Course Data QA - useful to generate actionable steps for improvement based on the course data after going through the given question and answer ",
    chain,
})
const tools = [
    qaTool,
];
const executor = await initializeAgentExecutorWithOptions(tools, model, {
    agentType: 'chat-conversational-react-description'
  });
const agentInput = `
  Based on the question and the answer, provide relevant feedback and actionable steps to get better at communicating.
  Question : ${ques}
  Answer : ${ans}
  Provide response in HTML Document format.
`;
  const agentResponse = await executor.call({ input: agentInput });
  console.log(agentResponse);
@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label Sep 7, 2023
@dosubot
Copy link

dosubot bot commented Sep 7, 2023

🤖

Hello,

The error you're encountering, "Cannot read properties of undefined (reading 'embedQuery')", is likely due to the OpenAIEmbeddings class not being properly initialized. In the context you've provided, it seems you're only providing timeout as an option while initializing the OpenAIEmbeddings class. However, other necessary parameters such as modelName, batchSize, stripNewLines, maxConcurrency, azureOpenAIApiKey, azureOpenAIApiInstanceName, azureOpenAIApiDeploymentName, azureOpenAIApiVersion, and azureOpenAIBasePath are missing.

Here's how you should initialize the OpenAIEmbeddings class:

const embeddings = new OpenAIEmbeddings({
  modelName: 'text-embedding-ada-002',
  batchSize: 512,
  stripNewLines: true,
  timeout: 1000,
  azureOpenAIApiKey: 'your-azure-openai-api-key',
  azureOpenAIApiInstanceName: 'your-azure-openai-api-instance-name',
  azureOpenAIApiDeploymentName: 'your-azure-openai-api-deployment-name',
  azureOpenAIApiVersion: 'your-azure-openai-api-version',
  azureOpenAIBasePath: 'your-azure-openai-base-path',
  maxConcurrency: 1,
});

/* Embed queries */
const res = await embeddings.embedQuery("Hello world");
console.log(res);
/* Embed documents */
const documentRes = await embeddings.embedDocuments([
  "Hello world",
  "Bye bye",
]);
console.log({ documentRes });

Please replace 'your-azure-openai-api-key', 'your-azure-openai-api-instance-name', 'your-azure-openai-api-deployment-name', 'your-azure-openai-api-version', and 'your-azure-openai-base-path' with your actual Azure OpenAI API key, instance name, deployment name, version, and base path respectively.

As for the function of the embedQuery method in the OpenAIEmbeddings class, it's used to convert raw text data into numerical vectors that can be processed by the HNSWLib vector store. This is done by passing the text data to the OpenAI API, which returns the corresponding embeddings.

I hope this helps! If you have any other questions, feel free to ask.

Best,
Dosu

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@darshanhande11
Copy link
Author

@dosu-bot Please take a look at the update description of the issue and let me know how to fix the issue.

@dosubot
Copy link

dosubot bot commented Sep 7, 2023

🤖

Hello,

The error you're encountering, "Cannot read properties of undefined (reading 'embedQuery')", suggests that the object on which you're trying to call the 'embedQuery' method is undefined. In your case, you're using the 'embedQuery' method on an instance of OpenAIEmbeddings.

The 'embedQuery' method in the OpenAIEmbeddings class in the LangChain codebase is used to generate embeddings for a given text query. These embeddings are numerical representations of the input text, which can be used for various natural language processing tasks.

Based on the context provided, it seems like you're missing the embeddings object when loading a vector store with HNSWLib.load(). The embeddings object is used to convert raw text data into numerical vectors that can be processed by the HNSWLib vector store.

Here's how you can modify your code:

const embeddings = new OpenAIEmbeddings();
const vectorStore = await HNSWLib.load("./src/vector_store", embeddings);

In the above code, an instance of OpenAIEmbeddings is created and passed to the HNSWLib.load() function. This should resolve the issue you're facing.

If the issue persists, please provide more context or code snippets where the error is occurring. Also, ensure that the 'embedQuery' method exists on the OpenAIEmbeddings class. If the method doesn't exist or is not accessible, you will encounter this error.

I hope this helps! Let me know if you have any other questions.

Best,
Dosu

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@darshanhande11
Copy link
Author

darshanhande11 commented Sep 7, 2023

thanks @dosu-beta The above fixes helped, closing the issue.

@dosubot
Copy link

dosubot bot commented Sep 7, 2023

🤖

I'm glad to hear that your issue has been resolved and you're closing the issue. However, for future reference and to help other users who might encounter the same problem, it would be beneficial if you could provide some details about the issue you were facing and how you resolved it.

From the context provided, it seems you were using version 0.0.4 of LangChain when you encountered the issue. But the specifics of the issue, your environment setup, and the steps taken to resolve it weren't clear.

If you could share these details, it would greatly contribute to the LangChain community. Thank you for your understanding and cooperation.

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant