Vscode Extension failed because it can not locate bindings file when importing faiss-node
Describe the bug I am just trying to use the code provided in documentation inside the VSCODE extrension but I get the error below:
Code:
const { IndexFlatL2 } = require('faiss-node');
const dimension = 2;
const Faissindex = new IndexFlatL2(dimension);
console.log(Faissindex.getDimension()); // 2
console.log(Faissindex.isTrained()); // true
console.log(Faissindex.ntotal()); // 0
// inserting data into index.
Faissindex.add([1, 0]);
Faissindex.add([1, 2]);
Faissindex.add([1, 3]);
Faissindex.add([1, 1]);
console.log(Faissindex.ntotal()); // 4
const k = 4;
const results = Faissindex.search([1, 0], k);
console.log(results.labels); // [ 0, 3, 1, 2 ]
console.log(results.distances); // [ 0, 1, 4, 9 ]
Error:
Activating extension 'Extension.extension' failed: Could not locate the bindings file. Tried:
→ /home/matheus/Projects/Extension/build/faiss-node.node
→ /home/matheus/Projects/Extension/build/Debug/faiss-node.node
→ /home/matheus/Projects/Extension/build/Release/faiss-node.node
→ /home/matheus/Projects/Extension/out/Debug/faiss-node.node
→ /home/matheus/Projects/Extension/Debug/faiss-node.node
→ /home/matheus/Projects/Extension/out/Release/faiss-node.node
→ /home/matheus/Projects/Extension/Release/faiss-node.node
→ /home/matheus/Projects/Extension/build/default/faiss-node.node
→ /home/matheus/Projects/Extension/compiled/16.14.2/linux/x64/faiss-node.node
→ /home/matheus/Projects/Extension/addon-build/release/install-root/faiss-node.node
→ /home/matheus/Projects/Extension/addon-build/debug/install-root/faiss-node.node
→ /home/matheus/Projects/Extension/addon-build/default/install-root/faiss-node.node
→ /home/matheus/Projects/Extension/lib/binding/node-v106-linux-x64/faiss-node.node.
Environment:
- Operating system: [e.g. Linux]
- Nodejs Version: [e.g. v18.15.0]
- Package Version: [e.g. v0.1.0]
- Using inside VSCODE Extenson
To Reproduce Steps to reproduce the behavior:
- Put the code i suggested in the simplest possible vscode extension app (https://code.visualstudio.com/api/get-started/your-first-extension) and this error will appear when you hit F5 to test it.
Expected behavior Faiss node should be imported
Screenshots If applicable, add screenshots to help explain your problem.
Additional context Add any other context about the problem here.
@masasso Thank you for reporting the issue. I tried the above steps but didn't reproduce. From the runtime error logs, it seems that the compiled binary was not found.
Please try these options
- Create a blank nodejs project, install
faiss-node, and run the given code see if it works. This is to confirm whether the problem is related to VS Code Extension. - Provide detailed
npm install faiss-node --verboselogs to troubleshoot whether the installation of prebuild packages failed. - Please provide the smallest reproducible VS Code project for investigation.
- Try to compile the binary locally.
@masasso I got similar problems with OSX setup. I tried clean install and tested the example. I got an error indicating there is something "missing".... Library not loaded: '/usr/local/opt/libomp/lib/libomp.dylib' After "brew install libomp"... example works as expected. Note I've OSX not pure linux,... I hope this helps.
@masasso I got similar problems with OSX setup. I tried clean install and tested the example. I got an error indicating there is something "missing".... Library not loaded: '/usr/local/opt/libomp/lib/libomp.dylib' After "brew install libomp"... example works as expected. Note I've OSX not pure linux,... I hope this helps.
@tro9999 libomp is a dependency under OSX, I have bundled it in https://github.com/ewfian/faiss-node/pull/5 and a new version will be released.
I just ran into this issue too because bindings seemed to be looking for the .node file starting from the wrong directory as shown in the first comment. After digging through a bunch of other issues on google this one from node-bindings lead to a working solution https://github.com/TooTallNate/node-bindings/issues/43
Just add faiss-node as an external in the webpack config.
externals: {
// modules added here also need to be added in the .vscodeignore file
"faiss-node": "commonjs faiss-node",
},
then the sample code above and my own code using Faiss worked fine in a VSCode extension.