-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
HNSWLib-node not found when using in a AWS Lambda function #943
Comments
@joaotextor If you found a solution please let me know as I am having a similar issue but in vite React js... |
I did some quick research and it looks like the error is a bit misleading. The original error that is being suppressed by a catch clause here is I found a way to resolve this issue by installing the library in some runtime similar to a Lambda one using Docker. This produces
this command produces the required |
Thanks for the reply. I will try this in a few days. If anyone tries it before me, please let us know here. |
Same error. Deleted node_modules, just to be sure, before running the command. Got this on CloudWatch:
|
I ran this using Node 18, x86_64 Lambda. Do you use the same one? You could also try adding console.log directly here in the |
My lambda function is running on Node 18 and x86_64 too. I added a console.log on Tried running the command again, and noticed some interesting warnings, like this one:
the command runs I'm trying to figure it out how to use the newer AWS Lambda base images that has support to nodejs18.x, as stated in the official Repository. If you figure it out how to make this command work using this base images, let me know. I'll try here too. Thank you very much so far. |
I'm using Vercel serverless functions, which under the hood utilize AWS Lambda. Interestingly this used to work for me fine, but it stopped working when I switched over to NextJS 13 Route Handlers, which is currently in beta. I'm pretty sure the new NextJS 13 app router also utilizes Lambda, so I don't know what changed compared to the old NextJS implementation specifically that is causing this to stop working. If anyone else has this working with NextJS Route handlers, let me know. |
I found the solution to this on Nextjs, user the following
|
@manduks Cheers mate! After a few days of headache with this issue, your solution worked for me as charm. Awesome stuff! Thank you again! |
Any chance of some more detail on how to do this for a docker newbie? So, can I "docker pull node" to get the latest version, then do some "docker run docker run --rm -v "$PWD":/var/task nodes npm install langchain hnswlib-node my_other_modules" magic to create a node_modules that I can zip up and use as a lambda layer? Thanks for any help, David |
Same issue here.
error:
|
Same error when trying to use vectorstores in a Netlify function:
error:
|
That worked for me, but when I'm dockerize the app the same error arises, not sure whats going on. |
worked perfectly for me as I had the same issue, thanks a lot mate |
also worked for me, |
Same issue happens to me when included in GastBY API also and I have been trying to fix it since 3 days now and still not able to resolve it. I try to deploy this function in netlify. |
No fix yet? |
@SimRunBot @fedematteis can you tell me what versions of HNSWLib and Langchain you are using? as I did the suggested change in next,.config.js but still having the same error! BTW, my versions of these libraries are: Thanks |
Guys Any Solution? |
@joaotextor try this this one works for me
|
This is the alternate I have been using and it works fine for my use case. // For creating a new vector from existing documents
import { MemoryVectorStore } from "langchain/vectorstores/memory";
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
const apiKey = process.env.OPEN_AI_API_KEY;
const embeddings = new OpenAIEmbeddings({ openAIApiKey: apiKey });
// You can use one of the following method to create a vector store based on data available
const vectorStore = await MemoryVectorStore.fromDocuments(docs, embeddings);
// or
const vectorStore = await MemoryVectorStore.fromTexts(textArray, metadataArray, embeddings);
// Once it is created you can persist the data as json file either in S3 or any other persistent storage
const jsonToStore = vectorStore.memoryVectors; // I saved this data as json file
// Next time when needed I load this file again using the following code.
const vectorStoreData = loadDataFromJsonFileStoredAbove();
const vectorStore = await MemoryVectorStore.fromExistingIndex(embeddings);
vectorStore.memoryVectors = vectorStoreData;
// Now do a similarity search
const result = await vectorStore.similaritySearch(query, 4); |
Same issue for me. It works if I run via
And my DockerFile:
Any suggestions on how to fix this? Packages versions: Docker version 24.0.6 |
I could get it to work by updating my docker files as the following: docker-compose:
Dockerfile:
Then on terminal I first ran
Then
I haven't dived deep to check if just a single part of this is enough or if everything is needed, though. But now it's working |
Hi, @joaotextor, I'm helping the langchainjs team manage their backlog and am marking this issue as stale. It looks like the issue involves the HNSWLib-node library not being found when the code is executed in an AWS Lambda function, despite being present in the node_modules folder. There were discussions about potential solutions, including the use of Docker to produce node_modules containing all the required libs, but it seems the error persisted for you and other users even after trying the suggested command. Some users found workarounds, while others are still seeking a resolution. Could you please confirm if this issue is still relevant to the latest version of the langchainjs repository? If it is, please let the langchainjs team 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! |
I'm not using it anymore, so I can't say if this is still an issue. |
Hi @joaotextor, Thank you for your response. We appreciate your input. Since you're no longer using it, we'll go ahead and close the issue. If you ever encounter similar issues in the future, feel free to reach out. Thank you again!
|
I recently made a simple Typescript function to create a VectorStore using HNSWLib-node.
It saves the vector store in a folder and then, in another script file, I load and execute a RetrievalQAChain using OpenAI.
Everything was working fine until I decided to put that in a AWS Lambda Function.
My package.json has the following dependencies:
Also, I double checked and the hnswlib-node folder is inside "node_modules" folder in my lambda function folder.
However, I keep getting the following error (from CloudWatch Logs):
Also, this error is not thrown on importing HNSWLib, but only in the following line of code:
This is my import:
const { HNSWLib } = require("langchain/vectorstores/hnswlib")
It seems I'm not the only one with this problem. See this post
Tried this and didn't work.
Expeted behavior: code would be executed properly, just like when executed on my local machine.
Actual behavior: the error pasted above.
The text was updated successfully, but these errors were encountered: