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

HNSW Lib does not work even after installing hnswlib-node #3782

Closed
adityadafe opened this issue Dec 24, 2023 · 6 comments
Closed

HNSW Lib does not work even after installing hnswlib-node #3782

adityadafe opened this issue Dec 24, 2023 · 6 comments
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@adityadafe
Copy link

After Installing hnswlib-node the issue persists-
image

Copy link

dosubot bot commented Dec 24, 2023

🤖

Hey @KaKashi1210! I'm Dosu, a friendly bot here to lend a hand with bugs, answer questions, and guide you to be an awesome contributor. While we're waiting for a human maintainer, I'm here to help. Let's dive into this together. 😊

The error you're encountering might be due to the way hnswlib-node is being imported in the HNSWLib class. The error message suggests that the hnswlib-node library is not found, which could be due to a number of reasons:

  1. The hnswlib-node library is not installed. You can install it using npm install hnswlib-node.

  2. The hnswlib-node library is installed, but it's not in the correct location where the code is looking for it. Make sure that the hnswlib-node library is in the node_modules directory of your project.

  3. There might be an issue with the way the hnswlib-node library is being imported. The hnswlib-node library is being imported using a dynamic import statement, which might not be supported in your environment. You can try changing the dynamic import statement to a static import statement at the top of your file.

Here is the part of the code that might be causing the issue:

static async imports(): Promise<{
    HierarchicalNSW: typeof HierarchicalNSWT;
  }> {
    try {
      const {
        default: { HierarchicalNSW },
      } = await import("hnswlib-node");

      return { HierarchicalNSW };
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
    } catch (err: any) {
      throw new Error(
        `Could not import hnswlib-node. Please install hnswlib-node as a dependency with, e.g. \`npm install -S hnswlib-node\`.\n\nError: ${err?.message}`
      );
    }
  }

You can try changing the dynamic import statement to a static import statement like this:

import { HierarchicalNSW } from "hnswlib-node";

And then use HierarchicalNSW directly in your code without the need to import it dynamically.

You can find this code in the libs/langchain-community/src/vectorstores/hnswlib.ts file.

If you're still encountering issues, could you please provide more details about the error message you're seeing and the steps you're taking when the error occurs? This will help me better understand the issue and provide a more accurate solution.

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.

@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label Dec 24, 2023
@mo29cg
Copy link

mo29cg commented Dec 25, 2023

same here

@jacoblee93
Copy link
Collaborator

It looks like you're using bun - can you try with just base node?

It might be worth opening an issue/PR on the HNSW package for bun support.

@adityadafe
Copy link
Author

@jacoblee93 thanks for the idea much appreciated <3

@ddosakura
Copy link

use bun 1.1.0+

@cshaxu
Copy link

cshaxu commented May 26, 2024

same here, but I am using Node 18.18.0 - any recommendations please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

5 participants