langchainjs: Langchain doesn't work on AWS Lambda with either faiss or hnswlib

The current version is broken on AWS lambda, both with Faiss and HNSWlib. I’ve spent the last few days building test cases on both platforms, but haven’t dived into the langchain code.

The typical outcome is:

“Could not import faiss-node. Please install faiss-node as a dependency with, e.g. npm install -S faiss-node.\n\nError: libgomp.so.1: cannot open shared object file: No such file or directory”

Same with HNSWlib (substitute hnswlib for faiss in the error above).

Also see

https://github.com/hwchase17/langchainjs/issues/943 https://github.com/hwchase17/langchainjs/issues/1764

Hope this helps - langchain is amazing, and if it worked on AWS it would be even better 😃

David

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 3
  • Comments: 25 (4 by maintainers)

Most upvoted comments

There is a document on how to run hnswlib-node on AWS lambda. I managed to deploy it using this dockerfile:

FROM public.ecr.aws/lambda/nodejs:18 as builder
WORKDIR /usr/app

# install python
RUN yum install -y python3 make gcc-c++ && \
    yum clean all && \
    rm -rf /var/cache/yum

# install pnpm
RUN npm i -g pnpm

# install dependencies
COPY package.json pnpm-lock.yaml ./
RUN pnpm install

# build
COPY index.ts ./
RUN pnpm run build


FROM public.ecr.aws/lambda/nodejs:18
WORKDIR ${LAMBDA_TASK_ROOT}

COPY foo.dat ./
COPY --from=builder /usr/app ./
COPY --from=builder /usr/app/dist/* ./

CMD ["index.handler"]

Looking for a lambda layer solution, since I don’t want to deploy using Docker images.

🤖

Based on the error messages you’ve shared, it seems like the AWS Lambda environment is missing some shared libraries required by faiss-node and hnswlib. Specifically, the errors mention libgomp.so.1 and /lib64/libm.so.6: version GLIBC_2.27.

One possible workaround is to create a custom AWS Lambda layer that includes these missing shared libraries. Here’s a general outline of the steps:

  1. Create a Dockerfile that uses the Amazon Linux image (which is the same environment that AWS Lambda runs on). In this Dockerfile, install the necessary dependencies and build the shared object files.

  2. Use the Dockerfile to build a Docker image and run a Docker container.

  3. Inside the Docker container, create a zip file that contains the shared object files and dependencies.

  4. Upload the zip file to AWS S3.

  5. Create a new AWS Lambda layer and point it to the zip file in S3.

  6. Add the new layer to your AWS Lambda function.

Please note that the exact steps and code will depend on the specific shared object files and dependencies that are missing.

In the context of LangChain, you would need to ensure that the AWS Lambda environment has the necessary dependencies to run Faiss or HNSWlib, and that the shared object files are included in the AWS Lambda layer.

Unfortunately, without more specific information about the shared object files and dependencies required by Faiss and HNSWlib, I can’t provide more specific steps or code. You might need to consult the documentation or community for these libraries to get this information.

As for the issue with GLIBC_2.27, it seems like AWS Lambda’s Amazon Linux 2 environment only includes GLIBC_2.26. This might be causing the unmet dependencies issue. One possible solution is to wait for AWS to update the version of glibc in their environment, or to find a version of faiss-node that is compatible with GLIBC_2.26.

I hope this helps! If you have any more questions or need further clarification, feel free to ask.

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.

@jacoblee93 There is also a related issue on faiss-node side. I’ll do some research and try to find a solution.

Are you using the edge runtime? faiss-node is Node only 😦