Coder Social home page Coder Social logo

Comments (2)

yoshoku avatar yoshoku commented on May 18, 2024

@iliane5 Thank you for having interest in this library. The hnswlib-node is a thin wrapper for hnswlib, so it supports similar operations. An example script would look like this:

import { HierarchicalNSW } from 'hnswlib-node'

const numDimensions = 4;
const maxElements = 5;

const index = new HierarchicalNSW('l2', numDimensions);
index.initIndex(maxElements);

index.addPoint([1, 2, 3, 1], 1);
index.addPoint([1, 2, 3, 2], 2);
index.addPoint([1, 2, 3, 3], 3);
index.addPoint([1, 2, 3, 4], 4);

const numNeighbors = 2
const query = [1, 2, 3, 5];
console.table(index.searchKnn(query, numNeighbors));

index.writeIndexSync('foo.dat');

// ---

const readedIndex = new HierarchicalNSW('l2', numDimensions);
readedIndex.readIndexSync('foo.dat');

// Adding new point closest to the query.
readedIndex.addPoint([1, 2, 3, 5], 5);

console.table(readedIndex.searchKnn(query, numNeighbors));

// Removing an indexed point.
readedIndex.markDelete(4);

console.table(readedIndex.searchKnn(query, numNeighbors));

Execution result:

$ yarn ts-node sample.ts
┌───────────┬───┬───┐
│  (index)  │ 0 │ 1 │
├───────────┼───┼───┤
│ distances │ 1 │ 4 │
│ neighbors │ 4 │ 3 │
└───────────┴───┴───┘
┌───────────┬───┬───┐
│  (index)  │ 0 │ 1 │
├───────────┼───┼───┤
│ distances │ 0 │ 1 │
│ neighbors │ 5 │ 4 │
└───────────┴───┴───┘
┌───────────┬───┬───┐
│  (index)  │ 0 │ 1 │
├───────────┼───┼───┤
│ distances │ 0 │ 4 │
│ neighbors │ 5 │ 3 │
└───────────┴───┴───┘

from hnswlib-node.

yoshoku avatar yoshoku commented on May 18, 2024

@iliane5 It has been two weeks since I responded, so I will close this issue. Search index algorithm based on graph structure adds new data as nodes and does not require rebuilding the index.

from hnswlib-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.