# hnswlib-node

> Node.js bindings for Hnswlib

Latest version **3.0.0** (published 2024-03-11) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install hnswlib-node
pnpm add hnswlib-node
yarn add hnswlib-node
bun add hnswlib-node
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2024-03-11 |
| First published | 2022-03-13 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 191.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 138 |
| Author | Atsushi Tatsuma |
| Maintainers | yoshoku |
| Keywords | hnswlib, approximate nearest neighbor search, machine learning |

## Links

- npm: https://www.npmjs.com/package/hnswlib-node
- Repository: https://github.com/yoshoku/hnswlib-node
- Issues: https://github.com/yoshoku/hnswlib-node/issues
- npm.io page: https://npm.io/package/hnswlib-node

## Dependencies (2)

- [bindings](https://npm.io/package/bindings.md) ^1.5.0
- [node-addon-api](https://npm.io/package/node-addon-api.md) ^8.0.0

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2024-03-11
- 2.1.1 — 2024-02-27
- 2.1.0 — 2023-12-16
- 2.0.0 — 2023-06-23
- 1.4.2 — 2023-03-10
- 1.4.1 — 2023-03-05
- 1.4.0 — 2023-02-26
- 1.3.0 — 2023-02-19
- 1.2.0 — 2022-11-26
- 1.1.0 — 2022-04-29
- 1.0.3 — 2022-04-19
- 1.0.2 — 2022-03-21
- 1.0.1 — 2022-03-19
- 1.0.0 — 2022-03-13

## README

# hnswlib-node

[![npm version](https://badge.fury.io/js/hnswlib-node.svg)](https://badge.fury.io/js/hnswlib-node)
[![Build Status](https://github.com/yoshoku/hnswlib-node/actions/workflows/build.yml/badge.svg)](https://github.com/yoshoku/hnswlib-node/actions/workflows/build.yml)
[![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/yoshoku/hnswlib-node/blob/main/LICENSE.txt)
[![Documentation](https://img.shields.io/badge/api-reference-blue.svg)](https://yoshoku.github.io/hnswlib-node/doc/)

hnswlib-node provides Node.js bindings for [Hnswlib](https://github.com/nmslib/hnswlib)
that implements approximate nearest-neghbor search based on
hierarchical navigable small world graphs.

## Installation

```sh
$ npm install hnswlib-node
```

## Documentation

* [hnswlib-node API Documentation](https://yoshoku.github.io/hnswlib-node/doc/)
* [How to run hnswlib-node on AWS Lambda](https://github.com/yoshoku/hnswlib-node/wiki/How-to-run-hnswlib-node-on-AWS-Lambda)

## Usage

Generating search index:

```typescript
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);
}

// saving index.
index.writeIndexSync('foo.dat');
```

Searching nearest neighbors:

```typescript
import { HierarchicalNSW } from 'hnswlib-node';

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

// preparing query data points.
const numDimensions = 8;
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);
```

## License

hnswlib-node is available as open source under the terms of the [Apache-2.0 License](https://www.apache.org/licenses/LICENSE-2.0).

## 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](https://contributor-covenant.org) code of conduct.

---
_Source: https://npm.io/package/hnswlib-node · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
