Hnswlib for React Native
npm install react-native-hnswlib
import { HierarchicalNSW } from 'react-native-hnswlib';
const numDimensions = 8; // the length of data point vector that will be indexed.
const maxElements = 10; // the maximum number of data points.
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);
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library
Built and maintained by BRICKS.