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

its not work on bunjs #187

Closed
ddosakura opened this issue Apr 2, 2024 · 3 comments
Closed

its not work on bunjs #187

ddosakura opened this issue Apr 2, 2024 · 3 comments

Comments

@ddosakura
Copy link

its not work on bunjs. Is it possible to be bun compatible?

also see:
langchain-ai/langchainjs#3782
nmslib/hnswlib#533

@yoshoku
Copy link
Owner

yoshoku commented Apr 6, 2024

@ddosakura
hnsw-node also work on Bun:

// index.ts

import { BruteforceSearch, HierarchicalNSW } from 'hnswlib-node'

const numDimensions = 8;
const maxElements = 10;

const index = new HierarchicalNSW('l2', numDimensions);
index.initIndex(maxElements);

for (let i = 0; i < maxElements; i++) {
  const point = new Array(numDimensions);
  for (let j = 0; j < numDimensions; j++) point[j] = Math.random();
  index.addPoint(point, i);
}

const query = new Array(numDimensions);
for (let j = 0; j < numDimensions; j++) query[j] = Math.random();

const numNeighbors = 3;
const result = index.searchKnn(query, numNeighbors);

console.table(result);
bun_hnswlib-node

Please read the error message carefully in the screenshot of the issue:

error: Could not import hnsw-node. Please install hnsw-node as a dependency with, e. g. `npm install -S hnswlib-node`

The error probably occurred because hnswlib-node was not installed.

@yoshoku
Copy link
Owner

yoshoku commented Apr 7, 2024

Since the original issues are closed, this issue is also closed. Thank you for your understanding.

@yoshoku yoshoku closed this as completed Apr 7, 2024
@ddosakura
Copy link
Author

Reasons for not work:

  1. Early versions of bunjs did not auto run node-gyp scripts

also see:

microsoft/node-pty#632 (comment)

This has been fixed in bun:1.1.0+:

oven-sh/bun#9289

  1. the official bunjs image not work

oven-sh/bun#9807

The issue has been closed, but the latest image still reports an error

docker run --interactive --tty --rm -v $PWD:$PWD --workdir $PWD oven/bun:1.1.3-debian /bin/bash

apt update
apt install python3

rm -rf node_modules/
bun i hnswlib-node
# gyp: name 'llvm_version' is not defined while evaluating condition 'llvm_version=="0.0"' in binding.gyp while trying to load binding.gyp

use nodejs image:

oven-sh/bun#9807 (comment)

docker run --interactive --tty --rm -v $PWD:$PWD --workdir $PWD node:20.12.1-slim /bin/bash

npm i -g bun

apt update
apt install python3 make g++

rm -rf node_modules/
bun i hnswlib-node

it works!

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

2 participants