JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 40746
  • Score
    100M100P100Q147370F
  • License Apache-2.0

Node.js bindings for Hnswlib

Package Exports

  • hnswlib-node
  • hnswlib-node/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (hnswlib-node) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

hnswlib-node

Build Status License

hnswlib-node provides Node.js bindings for Hnswlib that implements approximate nearest-neghbor search based on hierarchical navigable small world graphs.

Installation

$ npm install hnswlib-node

Usage

import { HierarchicalNSW } from 'hnswlib-node'

const numDimensions = 8 // the length of data point vector that will be indexed.
const maxElements = 10 // the maximum number of data points.

// declaring and intializing index.
const index = new HierarchicalNSW('l2', numDimensions);
index.initIndex(maxElements);

// inserting data points to index.
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);
}

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

// searching k-nearest neighbor data points.
const numNeighbors = 3
const result = index.searchKnn(query, numNeighbors);

console.table(result);

// saving index.
index.save('foo.dat');

// loading index.
const loadedIndex = new HierarchicalNSW('l2', 3);
loadedIndex.loadIndex('foo.dat');

License

The gem is available as open source under the terms of the Apache-2.0 License.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/hnswlib-node. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.