langchain-ai / langchainjs

🦜🔗 Build context-aware reasoning applications 🦜🔗
https://js.langchain.com/docs/
MIT License
11.79k stars 1.97k forks source link

Error: Cannot read properties of undefined (reading 'embedDocuments') #5148

Open jiveshkalra opened 2 months ago

jiveshkalra commented 2 months ago

Checked other resources

Example Code


  const vectorStore = await HNSWLib.fromTexts( final_posts,new HuggingFaceTransformersEmbeddings({model: "mixedbread-ai/mxbai-embed-large-v1"}));

Error Message and Stack Trace (if applicable)

Unhandled Runtime Error
Error: Cannot read properties of undefined (reading 'embedDocuments')

Source
app\actions\chatbot_action.jsx (43:36) @ fromTexts

  41 | 
  42 | 
> 43 | const vectorStore = await HNSWLib.fromTexts( final_posts,new HuggingFaceTransformersEmbeddings({model: "mixedbread-ai/mxbai-embed-large-v1",}));
     |                                  ^
  44 | const retriever = vectorStore.asRetriever();```

### Description

I am trying to set up a simple RAG with HNSWLib , I have my documents in final_post and I cant use OpenAI So I am going for opensource embedding model ,but I am unable to use that 

### System Info

Platform Windows
Node v20.9.0
langchain info ->
```markdown
langchain@0.1.34 | MIT | deps: 17 | versions: 265
Typescript bindings for langchain
https://github.com/langchain-ai/langchainjs/tree/main/langchain/

keywords: llm, ai, gpt3, chain, prompt, prompt engineering, chatgpt, machine learning, ml, openai, embeddings, vectorstores

dist
.tarball: https://registry.npmjs.org/langchain/-/langchain-0.1.34.tgz
.shasum: 3c28a6bde69c5f4ac3931376d34187de0e44e43a
.integrity: sha512-4TVH2mzhITrLPOeyfGucfqo1+360DJMl4+ItG56ApxVY1krO4hV0EkqcRLAxW06W6sIue8mIU70WbyhBYH68Ug==
.unpackedSize: 4.1 MB

dependencies:
@anthropic-ai/sdk: ^0.9.1     binary-extensions: ^2.2.0     langchainhub: ~0.0.8          p-retry: 4                    zod: ^3.22.4
@langchain/community: ~0.0.47 js-tiktoken: ^1.0.7           langsmith: ~0.1.7             uuid: ^9.0.0
@langchain/core: ~0.1.56      js-yaml: ^4.1.0               ml-distance: ^4.0.0           yaml: ^2.2.1
@langchain/openai: ~0.0.28    jsonpointer: ^5.0.1           openapi-types: ^12.1.3        zod-to-json-schema: ^3.22.3

maintainers:
- nfcampos <nuno@boringbits.io>
- jacoblee93 <jacoblee93@gmail.com>
- andrewnguonly <andrewnguonly@gmail.com>
- davidduong <david@duong.cz>
- hwchase17 <hw.chase.17@gmail.com>
- basproul <braceasproul@gmail.com>

dist-tags:
latest: 0.1.34     next: 0.1.29-rc.0

published 16 hours ago by jacoblee93 <jacoblee93@gmail.com>
dosubot[bot] commented 2 months ago

The error you're encountering, "Cannot read properties of undefined (reading 'embedDocuments')", indicates that the HuggingFaceTransformersEmbeddings object you're passing to HNSWLib.fromTexts might not be correctly instantiated or does not have the embedDocuments method defined. This method is essential for converting texts to vectors, which are then added to the HNSW index.

To resolve this issue, ensure that HuggingFaceTransformersEmbeddings is properly implemented and instantiated. It should adhere to the EmbeddingsInterface, which requires an embedDocuments method that takes an array of documents as input and returns a promise resolving to an array of vectors for each document.

Here's a quick checklist:

If after these checks the issue persists, it might be helpful to review the documentation or source code of HuggingFaceTransformersEmbeddings to ensure it's being used as intended.

Sources

#### About Dosu 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.
jiveshkalra commented 2 months ago

Also using Memory Vector store gives me even weirder error -> image

ror: (0 , _xenova_transformers__WEBPACK_IMPORTED_MODULE_0__.pipeline) is not a function

Source
app\actions\chatbot_action.jsx (44:46) @ fromDocuments

  42 | 
  43 | 
> 44 | const vectorStore = await MemoryVectorStore.fromDocuments(final_posts,new HuggingFaceTransformersEmbeddings({model: "mixedbread-ai/mxbai-embed-large-v1",}));
     |                                            ^

in code I just only changed a one word in the code



  const vectorStore = await MemoryVectorStore.fromDocuments(final_posts,new HuggingFaceTransformersEmbeddings({model: "mixedbread-ai/mxbai-embed-large-v1",}));```