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

Error "Please install hnswlib-node as a dependency with, e.g. npm install -S hnswlib-node" on M2 Chip #90

Open
clemenspeters opened this issue Jun 1, 2023 · 13 comments

Comments

@clemenspeters
Copy link

While the exact same docker image builds just fine on the linux AWS EC2 servers and in github actions, on my M2 Chip MacBook I get

#0 14.81 file:///app/node_modules/langchain/dist/vectorstores/hnswlib.js:172
#0 14.81             throw new Error("Please install hnswlib-node as a dependency with, e.g. `npm install -S hnswlib-node`");
#0 14.81                   ^
#0 14.81 
#0 14.81 Error: Please install hnswlib-node as a dependency with, e.g. `npm install -S hnswlib-node`
#0 14.81     at HNSWLib.imports (file:///app/node_modules/langchain/dist/vectorstores/hnswlib.js:172:19)
#0 14.81     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
#0 14.81     at async HNSWLib.getHierarchicalNSW (file:///app/node_modules/langchain/dist/vectorstores/hnswlib.js:35:37)
#0 14.81     at async HNSWLib.initIndex (file:///app/node_modules/langchain/dist/vectorstores/hnswlib.js:49:26)
#0 14.81     at async HNSWLib.addVectors (file:///app/node_modules/langchain/dist/vectorstores/hnswlib.js:68:9)
#0 14.81     at async HNSWLib.fromDocuments (file:///app/node_modules/langchain/dist/vectorstores/hnswlib.js:163:9)

when running HNSWLib.fromDocuments(docs, new OpenAIEmbeddings({...embeddingsOpts, openAIApiKey:OPENAI_API_KEY})); is called.

So it works on the server (luckily), but not on my local machine in docker 🤔 😕

Dockerfile:

FROM node:18-alpine AS BUILD_IMAGE

RUN apk update && \
    apk add -q make g++ python3
.
.
.
@mojalil
Copy link

mojalil commented Jun 6, 2023

I have the exact same issues and i'm on a mac m1 pro.

@duyhnguyen216
Copy link

Does not work on Azure :(

@JariHuomo
Copy link

Had this error on my Electron project, got it fixed it with import change:

static async imports() {
try {

       const HierarchicalNSW = require('hnswlib-node').HierarchicalNSW;
        
        return { HierarchicalNSW };
    }
    catch (err) {
        throw new Error(err);
    }
}

@dmb0058
Copy link

dmb0058 commented Jul 14, 2023

Doesn't work on AWS Lambda either ... maybe a problem with langchainjs but see langchain-ai/langchainjs#1930

@kasem-sm
Copy link

Had this error on my Electron project, got it fixed it with import change:

static async imports() { try {

       const HierarchicalNSW = require('hnswlib-node').HierarchicalNSW;
        
        return { HierarchicalNSW };
    }
    catch (err) {
        throw new Error(err);
    }
}

Thanks, man! I was trying to solve this for the past 5 hours (on electron).

@Lookbid
Copy link

Lookbid commented Jul 26, 2023

Having same issue

@HamzaElkotp
Copy link

HamzaElkotp commented Aug 29, 2023

Did anyone found a solution?

@dmb0058
Copy link

dmb0058 commented Aug 30, 2023

I had that problem on AWS Lambda with HNSWlib and Faiss due to missing dependencies. The Faiss developer fixed these so I switched Faiss in. However I can make that error appear if I attach the x86_64 Faiss layer to an arm64 based lambda. Possibly related, maybe not.

@Lukem121
Copy link

Lukem121 commented Sep 2, 2023

Think I figured it out, you need to install Visual Studio.

https://visualstudio.microsoft.com/downloads/

@alexomon018
Copy link

I had the same problem, but in the end I ended up using:
import { MemoryVectorStore } from 'langchain/vectorstores/memory';

const embeddings = new OpenAIEmbeddings();
const store = await MemoryVectorStore.fromDocuments(docs, embeddings);

Also tried installing Visual Studio and it didn't helped :/

@shridhar-tl
Copy link

shridhar-tl commented Oct 23, 2023

Hi @alexomon018, I'm facing same issue.

I am using it in GatsbyAPI and deploying it to Netlify. It doesn't work in local and in netlify as well.

I can try switching to MemoryVectorStore, but how can I serialize the data and use it for future again. I was able to do it in HNSWLib using save method.

[Update: I figured how to searilize MemoryVestorStore and use it. So I removed usage of HNSWLib and proceeded forward]

@Riyaancode
Copy link

I had the same problem, but in the end I ended up using: import { MemoryVectorStore } from 'langchain/vectorstores/memory';

const embeddings = new OpenAIEmbeddings(); const store = await MemoryVectorStore.fromDocuments(docs, embeddings);

Also tried installing Visual Studio and it didn't helped :/

@alexomon018 Thanks man it's worked for me

@cshaxu
Copy link

cshaxu commented May 26, 2024

having exactly the same issue... is it that langchain wasn't able to import this lib correctly somehow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests