tantaraio / voy

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

Demo #15

Open DawChihLiou opened 1 year ago

josephrocca commented 1 year ago

I've just tested the code in the readme on node.js and I'm getting a bunch of different import errors. I've also tried to get it working in the browser but am getting this:

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/wasm". Strict MIME type checking is enforced for module scripts per HTML spec.

I'm really only interested in getting it working in the browser - just tested in node.js after getting this wasm module loading error. Seems like wasm module loading via ESM syntax is only phase 2? https://github.com/WebAssembly/esm-integration/tree/main/proposals/esm-integration

DawChihLiou commented 1 year ago

Hey @josephrocca thanks for your question! Please check out https://github.com/tantaraio/voy/issues/6#issuecomment-1490426936 for more info.

josephrocca commented 1 year ago

Do you not intend to make it import-able with a simple import statement in the browser? Or is this just a temporary workaround?

DawChihLiou commented 1 year ago

Currently WASM modules requires dynamic import in browsers and node.js. I'll look into it to make it easier to import in browsers. Do you mind sharing your use case with me so I understand more about your needs? Thanks!

josephrocca commented 1 year ago

Use case: https://github.com/josephrocca/OpenCharacters - to handle character memory storage/recall

Currently I'm doing a brute force cosine similarity search - it'll be fine for short chats but might become slow if the character/agent accumulates thousands of memories.

GarciaLnk commented 1 year ago

The simplest solution to support browser imports would be building and bundling a version targeting browsers (as I suggested in #6) inside the current npm package and doing import * as voy from "voy-search/web" when needed, additionally you'd need to call await voy.default("voy_search_bg.wasm") before using voy.

The same would apply to a node version building against the nodejs target.

It's not a perfect solution, but it's better than the current options (my current solution is having a git submodule linked and running git -C voy pull && wasm-pack build -t web voy on pnpm preinstall).

MentalGear commented 1 year ago

@GarciaLnk sounds neat, would you be able to add a PR for this ?

DawChihLiou commented 1 year ago

@GarciaLnk have you tried https://github.com/tantaraio/voy/issues/6#issuecomment-1490426936? If it doesn't work, I'll work on the build for web.

<script src="https://www.unpkg.com/voy-search@0.6.1/voy_search.js" type="module"></script>
kwkr commented 1 year ago

Hi @DawChihLiou ! I'm currently working on integrating Voy into LangChain.js and I got a few questions while playing with the library. The environment that I was working with was mainly Node.js 18. First I tried to follow the example usage in the README but I quickly got into trouble with utilizing the dynamic import. Are the instructions contained there intended only for browsers? I'm not sure whether it might be useful to include it somewhere in the README, but from my perspective, this information could have potentially saved me some debugging time.

After some time I was able to run the code in the Node environment, although it needed some adjustments:

Do the changes that I've made make sense in my case or am I missing some easier way to run this? Would it be useful to you to have this information somewhere within the README? If so, if you would be willing to assist me with some hints and review it, I would be glad to create a PR for it.

DawChihLiou commented 1 year ago

Hey @kwkr thanks for the comment! The configuration besides the "main" property in your package.json should work. I'm more than happy to review if you'd like to creat a PR! Thanks so much!

kwkr commented 1 year ago

I wasn't precise with specifying which package.json I modified. I needed to modify the package.json of the voy-search inside node_modules. Should this work with Node without those modifications?

DawChihLiou commented 1 year ago

Yes that's correct. If it doesn't work, please let me know. I'm currently on vacation but I'll take a look at it as soon as I get back. Thanks!

DawChihLiou commented 12 months ago

Hey @kwkr just came across your integration in LangChain.js. Amazing work! Is your issue resolved?

kwkr commented 12 months ago

Yes, I managed to integrate it. The question is whether the information I needed in order to do that should be included in the README of your package as well because as I mentioned, I needed a few workarounds.

DawChihLiou commented 11 months ago

@kwkr I'll work in a build for Node. Thanks for your suggestion!