Open DawChihLiou opened 1 year ago
Hey @josephrocca thanks for your question! Please check out https://github.com/tantaraio/voy/issues/6#issuecomment-1490426936 for more info.
Do you not intend to make it import-able with a simple import
statement in the browser? Or is this just a temporary workaround?
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!
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.
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).
@GarciaLnk sounds neat, would you be able to add a PR for this ?
@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>
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:
--experimental-wasm-modules
in order to correctly include .wasm
files."type":"module","main":"voy_search.js"
in the package.json in order to correctly import the module.
When I did this I could run some example code using Node environment.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.
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!
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?
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!
Hey @kwkr just came across your integration in LangChain.js. Amazing work! Is your issue resolved?
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.
@kwkr I'll work in a build for Node. Thanks for your suggestion!
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:
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