jimkang / annoy-node Goto Github PK
View Code? Open in Web Editor NEWNode bindings for Annoy, an efficient Approximate Nearest Neighbors implementation written in C++.
Node bindings for Annoy, an efficient Approximate Nearest Neighbors implementation written in C++.
Hello,
I'm trying to install annoy-node with Node 14.16.1 and NPM 7.11.0 but the compilation failed.
npm i annoy
npm ERR! code 1
npm ERR! path /home/maxime/workspace/intents/node_modules/annoy
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! make: Entering directory '/home/maxime/workspace/intents/node_modules/annoy/build'
npm ERR! CXX(target) Release/obj.target/addon/addon.o
npm ERR! CXX(target) Release/obj.target/addon/annoyindexwrapper.o
npm ERR! make: Leaving directory '/home/maxime/workspace/intents/node_modules/annoy/build'
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | linux | x64
npm ERR! gyp info find Python using Python version 3.6.8 found at "/home/maxime/.pyenv/versions/3.6.8/bin/python3"
npm ERR! gyp info spawn /home/maxime/.pyenv/versions/3.6.8/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args '/home/maxime/.nvm/versions/node/v14.16.1/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args 'binding.gyp',
npm ERR! gyp info spawn args '-f',
npm ERR! gyp info spawn args 'make',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/home/maxime/workspace/intents/node_modules/annoy/build/config.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/home/maxime/.nvm/versions/node/v14.16.1/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/home/maxime/.cache/node-gyp/14.16.1/include/node/common.gypi',
npm ERR! gyp info spawn args '-Dlibrary=shared_library',
npm ERR! gyp info spawn args '-Dvisibility=default',
npm ERR! gyp info spawn args '-Dnode_root_dir=/home/maxime/.cache/node-gyp/14.16.1',
npm ERR! gyp info spawn args '-Dnode_gyp_dir=/home/maxime/.nvm/versions/node/v14.16.1/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args '-Dnode_lib_file=/home/maxime/.cache/node-gyp/14.16.1/<(target_arch)/node.lib',
npm ERR! gyp info spawn args '-Dmodule_root_dir=/home/maxime/workspace/intents/node_modules/annoy',
npm ERR! gyp info spawn args '-Dnode_engine=v8',
npm ERR! gyp info spawn args '--depth=.',
npm ERR! gyp info spawn args '--no-parallel',
npm ERR! gyp info spawn args '--generator-output',
npm ERR! gyp info spawn args 'build',
npm ERR! gyp info spawn args '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! ../annoyindexwrapper.cc: In static member function ‘static void AnnoyIndexWrapper::Init(v8::Local<v8::Object>)’:
npm ERR! ../annoyindexwrapper.cc:52:90: error: no matching function for call to ‘v8::Object::Set(v8::Local<v8::String>, v8::Local<v8::Function>)’
npm ERR! exports->Set(Nan::New("Annoy").ToLocalChecked(), Nan::GetFunction(tpl).ToLocalChecked());
npm ERR! ^
npm ERR! In file included from /home/maxime/.cache/node-gyp/14.16.1/include/node/node.h:67:0,
npm ERR! from ../../nan/nan.h:56,
npm ERR! from ../annoyindexwrapper.h:4,
npm ERR! from ../annoyindexwrapper.cc:1:
npm ERR! /home/maxime/.cache/node-gyp/14.16.1/include/node/v8.h:3670:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, v8::Local<v8::Value>, v8::Local<v8::Value>)
npm ERR! V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
npm ERR! ^~~
npm ERR! /home/maxime/.cache/node-gyp/14.16.1/include/node/v8.h:3670:37: note: candidate expects 3 arguments, 2 provided
npm ERR! /home/maxime/.cache/node-gyp/14.16.1/include/node/v8.h:3673:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, uint32_t, v8::Local<v8::Value>)
npm ERR! V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
npm ERR! ^~~
npm ERR! /home/maxime/.cache/node-gyp/14.16.1/include/node/v8.h:3673:37: note: candidate expects 3 arguments, 2 provided
npm ERR! ../annoyindexwrapper.cc: In static member function ‘static void AnnoyIndexWrapper::getSupplementaryGetNNsParams(const Nan::FunctionCallbackInfo<v8::Value>&, int&, int&, bool&)’:
npm ERR! ../annoyindexwrapper.cc:246:84: error: no matching function for call to ‘v8::Value::BooleanValue(v8::Local<v8::Context>&)’
npm ERR! includeDistances = info[3]->IsUndefined() ? false : info[3]->BooleanValue(context).FromJust();
npm ERR! ^
npm ERR! In file included from /home/maxime/.cache/node-gyp/14.16.1/include/node/node.h:67:0,
npm ERR! from ../../nan/nan.h:56,
npm ERR! from ../annoyindexwrapper.h:4,
npm ERR! from ../annoyindexwrapper.cc:1:
npm ERR! /home/maxime/.cache/node-gyp/14.16.1/include/node/v8.h:2858:8: note: candidate: bool v8::Value::BooleanValue(v8::Isolate*) const
npm ERR! bool BooleanValue(Isolate* isolate) const;
npm ERR! ^~~~~~~~~~~~
npm ERR! /home/maxime/.cache/node-gyp/14.16.1/include/node/v8.h:2858:8: note: no known conversion for argument 1 from ‘v8::Local<v8::Context>’ to ‘v8::Isolate*’
npm ERR! ../annoyindexwrapper.cc: In static member function ‘static void AnnoyIndexWrapper::setNNReturnValues(int, bool, const std::vector<int>&, const std::vector<float>&, const Nan::FunctionCallbackInfo<v8::Value>&)’:
npm ERR! ../annoyindexwrapper.cc:273:76: error: no matching function for call to ‘v8::Object::Set(v8::Local<v8::String>, v8::Local<v8::Array>&)’
npm ERR! jsResultObject->Set(Nan::New("neighbors").ToLocalChecked(), jsNNIndexes);
npm ERR! ^
npm ERR! In file included from /home/maxime/.cache/node-gyp/14.16.1/include/node/node.h:67:0,
npm ERR! from ../../nan/nan.h:56,
npm ERR! from ../annoyindexwrapper.h:4,
npm ERR! from ../annoyindexwrapper.cc:1:
npm ERR! /home/maxime/.cache/node-gyp/14.16.1/include/node/v8.h:3670:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, v8::Local<v8::Value>, v8::Local<v8::Value>)
npm ERR! V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
npm ERR! ^~~
npm ERR! /home/maxime/.cache/node-gyp/14.16.1/include/node/v8.h:3670:37: note: candidate expects 3 arguments, 2 provided
npm ERR! /home/maxime/.cache/node-gyp/14.16.1/include/node/v8.h:3673:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, uint32_t, v8::Local<v8::Value>)
npm ERR! V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
npm ERR! ^~~
npm ERR! /home/maxime/.cache/node-gyp/14.16.1/include/node/v8.h:3673:37: note: candidate expects 3 arguments, 2 provided
npm ERR! ../annoyindexwrapper.cc:274:81: error: no matching function for call to ‘v8::Object::Set(v8::Local<v8::String>, v8::Local<v8::Array>&)’
npm ERR! jsResultObject->Set(Nan::New("distances").ToLocalChecked(), jsDistancesArray);
npm ERR! ^
npm ERR! In file included from /home/maxime/.cache/node-gyp/14.16.1/include/node/node.h:67:0,
npm ERR! from ../../nan/nan.h:56,
npm ERR! from ../annoyindexwrapper.h:4,
npm ERR! from ../annoyindexwrapper.cc:1:
npm ERR! /home/maxime/.cache/node-gyp/14.16.1/include/node/v8.h:3670:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, v8::Local<v8::Value>, v8::Local<v8::Value>)
npm ERR! V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
npm ERR! ^~~
npm ERR! /home/maxime/.cache/node-gyp/14.16.1/include/node/v8.h:3670:37: note: candidate expects 3 arguments, 2 provided
npm ERR! /home/maxime/.cache/node-gyp/14.16.1/include/node/v8.h:3673:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, uint32_t, v8::Local<v8::Value>)
npm ERR! V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
npm ERR! ^~~
npm ERR! /home/maxime/.cache/node-gyp/14.16.1/include/node/v8.h:3673:37: note: candidate expects 3 arguments, 2 provided
npm ERR! ../annoyindexwrapper.cc: In static member function ‘static bool AnnoyIndexWrapper::getFloatArrayParam(const Nan::FunctionCallbackInfo<v8::Value>&, int, float*)’:
npm ERR! ../annoyindexwrapper.cc:302:27: error: no matching function for call to ‘v8::Array::Get(unsigned int&)’
npm ERR! val = jsArray->Get(i);
npm ERR! ^
npm ERR! In file included from /home/maxime/.cache/node-gyp/14.16.1/include/node/node.h:67:0,
npm ERR! from ../../nan/nan.h:56,
npm ERR! from ../annoyindexwrapper.h:4,
npm ERR! from ../annoyindexwrapper.cc:1:
npm ERR! /home/maxime/.cache/node-gyp/14.16.1/include/node/v8.h:3717:43: note: candidate: v8::MaybeLocal<v8::Value> v8::Object::Get(v8::Local<v8::Context>, v8::Local<v8::Value>)
npm ERR! V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
npm ERR! ^~~
npm ERR! /home/maxime/.cache/node-gyp/14.16.1/include/node/v8.h:3717:43: note: candidate expects 2 arguments, 1 provided
npm ERR! /home/maxime/.cache/node-gyp/14.16.1/include/node/v8.h:3720:43: note: candidate: v8::MaybeLocal<v8::Value> v8::Object::Get(v8::Local<v8::Context>, uint32_t)
npm ERR! V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
npm ERR! ^~~
npm ERR! /home/maxime/.cache/node-gyp/14.16.1/include/node/v8.h:3720:43: note: candidate expects 2 arguments, 1 provided
npm ERR! make: *** [addon.target.mk:112: Release/obj.target/addon/annoyindexwrapper.o] Error 1
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack at ChildProcess.onExit (/home/maxime/.nvm/versions/node/v14.16.1/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
npm ERR! gyp ERR! stack at ChildProcess.emit (events.js:315:20)
npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
npm ERR! gyp ERR! System Linux 5.8.0-50-generic
npm ERR! gyp ERR! command "/home/maxime/.nvm/versions/node/v14.16.1/bin/node" "/home/maxime/.nvm/versions/node/v14.16.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /home/maxime/workspace/intents/node_modules/annoy
npm ERR! gyp ERR! node -v v14.16.1
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok
I'm on Ubuntu 20.04 with g++ (Ubuntu 7.5.0-6ubuntu2) 7.5.0 and gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Can you please help me by supporting Node 14 ?
Thank you for your time,
Maxime
I'm trying a simple example adding a vector of size N
// angular | euclidean | manhattan | hamming | dot
var annoyIndex = new Annoy(5834, 'Angular');
annoyIndex.addItem(item_id,item_hcodes);
annoyIndex.build();
annoyIndex.save('./annoy-db.ann');
In this examples the size of vector N was 5834.
I have also tried to increase node memory like --max_old_space_size=8000
The file annoy-db.ann
will be created but it is empty.
This issue is related to packages level
, leveldown
and causes errors in node v12.13.x
- see Level/leveldown#695
Thanks a lot for making this library!
(I know this is a binding to the c++ library)
Is there any limit on the vector length ?
Having the same exact example with a doubled length like:
annoyIndex1.addItem(0, [-5.0, -4.5, -3.2, -2.8, -2.1, -1.5, -0.34, 0, 3.7, 6, -4.5, -3.2, -2.8, -2.1, -1.5, -0.34, 0, 3.7, 6]);
annoyIndex1.addItem(1, [5.0, 4.5, 3.2, 2.8, 2.1, 1.5, 0.34, 0, -3.7, -6, 4.5, 3.2, 2.8, 2.1, 1.5, 0.34, 0, -3.7, -6]);
annoyIndex1.addItem(2, [0, 0, 0, 0, 0, -1, -1, -0.2, 0.1, 0.8, 0, 0, 0, 0, -1, -1, -0.2, 0.1, 0.8]);
results in
*** stack smashing detected ***: terminated
Aborted (core dumped)
and in my example with length equals 300 (big embedding), I'm having:
Segmentation fault (core dumped)
and when lowering the length to exactly 19 elements, it works fine !! with an index of 50000 elements and beyond !
Thanks a lot !!!
installing on windows gives:
` addon.cc
annoyindexwrapper.cc
win_delay_load_hook.cc
...\node_modules\annoy\annoylib.h(46): fatal error C1083: Cannot open include file: 'mman.h': No such file or directory (compiling source file ..\addon.cc) [...node_modules\annoy\build\addon.vcxproj]
...\node_modules\annoy\annoylib.h(46): fatal error C1083: Cannot open include file: 'mman.h': No such file or directory (compiling source file ..\annoyindexwrapper.cc) [...\node_modules\annoy\build\addon.vcxproj]`
which I understand to be linked to mman.h not being available on windows as per
https://stackoverflow.com/questions/29660492/windows-equivalent-for-sys-mman-h
Any chance this could be worked around ?
spotify/annoy#174 named a solution for when one wants to add items after the DB has been built. It would be super if this functionality was enabled in the nodeJS bindings as well.
Hi,
Thanks for writing this library!
I want to use your bindings but AFAIU it contains two years old version of annoy and I need some recent feature (Manhatan . Are you interested in upgrading (we want to provide PR's)?
I'm not an node.js expert, but I wonder if we could move annoy code outside of this bindings (like downloading it during installation), so it will be clear which version we are building against and the update path would be somewhat easier (making diffs between annoy versions etc.). Do you think this is good idea?
Hello,
Following from this issue
#18
I tried to change the type of the vector to an array of Strings like:
v = ["0.00281","0.783933"...]
And It doesn't crash until a little longer array (between 20 and 100) I guess.
It would be nice to add in README specification of how Numbers of JavaScript are bound to the binary Annoy.
There are types like Array of numbers but there is also Float64Array
, so ..
Thanks a lot 😁
It looks like all methods are currently sync/blocking, which means that many concurrent search requests will have poor performance and block the event loop.
Have you thought about making the methods async?
I might try to create a PR for that, but I have little experience with the C++ add-on code. Do you maybe have any hints or background information that might help?
Getting below error on getNNsByVector call.
Index size is not a multiple of vector size. Ensure you are opening using the same metric you used to create the index.: Resource temporarily unavailable (11)
Hi,
Have you planned to support Node version >=18 ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.