tantaraio / voy

🕸️🦀 A WASM vector similarity search written in Rust
https://www.npmjs.com/package/voy-search
Apache License 2.0
884 stars 32 forks source link

NodeJS Support #32

Closed jlarmstrongiv closed 1 year ago

jlarmstrongiv commented 1 year ago

I checked a couple weeks ago, but the example in the readme does not work in Node.js:

import { TextModel } from "@visheratin/web-ai";

const voy = await import("voy-search");

const phrases = [
  "That is a very happy Person",
  "That is a Happy Dog",
  "Today is a sunny day",
];
const query = "That is a happy person";

// Create text embeddings
const model = await (await TextModel.create("gtr-t5-quant")).model;
const processed = await Promise.all(phrases.map((q) => model.process(q)));

// Index embeddings with voy
const data = processed.map(({ result }, i) => ({
  id: String(i),
  title: phrases[i],
  url: `/path/${i}`,
  embeddings: result,
}));
const resource = { embeddings: data };
const index = voy.index(resource);

// Perform similarity search for a query embeddings
const q = await model.process(query);
const result = voy.search(index, q.result, 1);

// Display search result
result.neighbors.forEach((result) =>
  console.log(`✨ voy similarity search result: "${result.title}"`)
);

I’m not sure if that’s due to getting the typescript compiler settings wrong or if @visheratin/web-ai is incompatible with Node.js

DawChihLiou commented 1 year ago

Thanks for reporting @jlarmstrongiv. I'll have a look.

visheratin commented 1 year ago

Hi, @jlarmstrongiv! For some time, Web AI didn't have proper Node.js support. But now there is one! You just need a special package for that - https://www.npmjs.com/package/@visheratin/web-ai-node

Here is a small demo of batched feature extraction.

jlarmstrongiv commented 1 year ago

That”s exciting 🎉 Thank you for the demo @visheratin