ewfian / faiss-node

Node.js bindings for faiss
https://www.npmjs.com/package/faiss-node
MIT License
107 stars 10 forks source link

Using Faiss-node in aws having problem working fine locally #25

Closed abgupta99 closed 1 year ago

abgupta99 commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

Environment:

To Reproduce Steps to reproduce the behavior:

Expected behavior should be run succesfully and store text in form of vector store

Screenshots "errorType": "Error", "errorMessage": "Could not import faiss-node. Please install faiss-node as a dependency with, e.g. npm install -S faiss-node and make sure you have libomp installed in your path.\n\nError: /opt/nodejs/node18/node_modules/faiss-node/build/Release/faiss-node.node: cannot open shared object file: No such file or directory", "trace": [ "Error: Could not import faiss-node. Please install faiss-node as a dependency with, e.g. npm install -S faiss-node and make sure you have libomp installed in your path.", "", "Error: /opt/nodejs/node18/node_modules/faiss-node/build/Release/faiss-node.node: cannot open shared object file: No such file or directory", " at FaissStore.importFaiss (file:///opt/nodejs/node18/node_modules/langchain/dist/vectorstores/faiss.js:207:19)", " at process.processTicksAndRejections (node:internal/process/task_queues:95:5)", " at async FaissStore.addVectors (file:///opt/nodejs/node18/node_modules/langchain/dist/vectorstores/faiss.js:60:37)", " at async FaissStore.fromDocuments (file:///opt/nodejs/node18/node_modules/langchain/dist/vectorstores/faiss.js:197:9)", " at async Runtime.handler (file:///var/task/index.mjs:57:19)" ] }

.

ewfian commented 1 year ago

@abgupta99 Thank you for the issue, I will try to reproduce and fix it

dmb0058 commented 1 year ago

This seems identical to the issue I have with HNSWlib-node. It might be coincidental, but in case this is a langchainjs issue, not faiss, see:

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

dmb0058 commented 1 year ago

Spent the day building test cases for this, and it's the same langchainjs error.

Most approaches end up with:

"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"

Currently I see that there is any route to using langchain with either faiss or hnswnlib on AWS Lambda.

manuel-84 commented 1 year ago

Having similar problem when deployed on Vercel, while on local dev is working fine

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","stack":"

ewfian commented 1 year ago

I have create a build for AWS Lambda in https://github.com/ewfian/faiss-node/pull/30

And is was works on my side: image

It has not been released yet, but you can try the version I built manually below: faiss-node-v0.2.2-aws-x64.zip

For other projects, please replace with the files under the path below: faiss-node-v0.2.2-aws-x64.zip/node_modules/faiss-node/build/Release

dmb0058 commented 1 year ago

Hi,

No luck my side I’m afraid: still missing libgomp.so.1:

{
  "errorType": "Error",
  "errorMessage": "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",
  "trace": [
    "Error: Could not import faiss-node. Please install faiss-node as a dependency with, e.g. `npm install -S faiss-node`.",
    "",
    "Error: libgomp.so.1: cannot open shared object file: No such file or directory",
    "    at FaissStore.importFaiss (/opt/nodejs/node_modules/langchain/dist/vectorstores/faiss.cjs:237:19)",
    "    at async readIndex (/opt/nodejs/node_modules/langchain/dist/vectorstores/faiss.cjs:141:37)",
    "    at async Promise.all (index 1)",
    "    at async FaissStore.load (/opt/nodejs/node_modules/langchain/dist/vectorstores/faiss.cjs:144:51)",
    "    at async query (/var/task/index.js:112:20)",
    "    at async exports.handler (/var/task/index.js:20:9)"
  ]
}

Also, after adding the Faiss layer I can't add anything much else as it's far too big:

Layers consume more than the available size of 262144000 bytes

David

ewfian commented 1 year ago

@dmb0058 I want to know whether it works properly if you directly upload the zip(faiss-node-v0.2.2-aws-x64.zip) I provided above to AWS.

Please confirm that you have replaced the files(node_modules/faiss-node/build/Release) in my zip above to the zip you finally want to upload to AWS.

I also made a demo for langchain here: https://github.com/hwchase17/langchainjs/issues/1930#issuecomment-1646500643 You can try to upload this demo directly to AWS.

dmb0058 commented 1 year ago

Yes, the demo zip (faiss-node-v0.2.2-aws-x64.zip) runs when I upload it as a lambda and gives the same results as you show above.

I can't create a layer though, so can't use this in practice:

 aws lambda publish-layer-version --layer-name my-faiss-layer \
        --description "My Faiss layer" \
        --license-info "MIT" \
        --zip-file fileb://my-faiss-node.zip \
        --compatible-runtimes nodejs18.x \
        --compatible-architectures "x86_64"
An error occurred (RequestEntityTooLargeException) when calling the PublishLayerVersion operation: Request must be smaller than 70167211 bytes for the PublishLayerVersion operation
ewfian commented 1 year ago

@dmb0058 Can you reduce the size of the zip to make it meet the limit first. The prebuilt binaries is too large under Linux was also mentioned in your previous issue(https://github.com/ewfian/faiss-node/issues/26). The binaries for AWS have shrunk a lot. The zip containing faiss-node is only 7.5MB. And the zip containing langchain and faiss-node has 15.5MB. Which is far less than the limit of AWS. Please identify what content takes up space and try to reduce it.

dmb0058 commented 1 year ago

That sounds really good. Let me see if I can strip some of the other modules in the application.

On Sat, 22 Jul 2023, 16:10 Fan, @.***> wrote:

@dmb0058 https://github.com/dmb0058 Can you reduce the size of the zip to make it meet the limit first. The prebuilt binaries is too large under Linux was also mentioned in your previous issue(#26 https://github.com/ewfian/faiss-node/issues/26). The binaries for AWS have shrunk a lot. The zip containing faiss-node is only 7.5MB. And the zip containing langchain and faiss-node has 15.5MB. Which is far less than the limit of AWS. Please identify what content takes up space and try to reduce it.

— Reply to this email directly, view it on GitHub https://github.com/ewfian/faiss-node/issues/25#issuecomment-1646603955, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDXCQKCC5FK5EWNK5PSMC3XRPUN7ANCNFSM6AAAAAA2B4CLBY . You are receiving this because you were mentioned.Message ID: @.***>

ewfian commented 1 year ago

@dmb0058 You can also try this demo https://github.com/hwchase17/langchainjs/issues/1930#issuecomment-1646994780

ewfian commented 1 year ago

The new version was released, To use faiss-node in AWS, you can download faiss-node-vX.X.X-aws-x64.zip from release. and upload to AWS as a layer. BTW. if you are using the faiss-node as layer, do NOT install faiss-node as npm package in your AWS Function, see the demo here: https://github.com/hwchase17/langchainjs/issues/1930#issuecomment-1646994780

rishi-raj-jain commented 10 months ago

This now works flawlessly with Fly.io, I had made a cool demo before and now I don't need to copy the zip folder over.

Thank you for maintaining and improving this 🙏🏻

rishi-raj-jain commented 10 months ago

@ewfian

I'm happy to pay you one time 30$ as the best I can for now. Can you share a buymeacoffee/paypal/stripe link? Thanks!

rishi-raj-jain commented 10 months ago

This is totally out of my respect for your work.

afsaints commented 5 months ago

The newer version is still cannot get through on the lambda layers, still having the same error which is { "errorType": "Error", "errorMessage": "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", "trace": [ "Error: Could not import faiss-node. Please install faiss-node as a dependency with, e.g. npm install -S faiss-node.", "", "Error: libgomp.so.1: cannot open shared object file: No such file or directory", " at FaissStore.importFaiss (/opt/nodejs/node_modules/langchain/dist/vectorstores/faiss.cjs:237:19)", " at async readIndex (/opt/nodejs/node_modules/langchain/dist/vectorstores/faiss.cjs:141:37)", " at async Promise.all (index 1)", " at async FaissStore.load (/opt/nodejs/node_modules/langchain/dist/vectorstores/faiss.cjs:144:51)", " at async query (/var/task/index.js:112:20)", " at async exports.handler (/var/task/index.js:20:9)" ] }