diff --git a/examples/README.md b/examples/README.md index fdacd89..e72800b 100644 --- a/examples/README.md +++ b/examples/README.md @@ -11,3 +11,5 @@ - This example shows a semantic search application, using `chromem-go` as vector database for finding semantically relevant search results. - Loads and searches across ~5,000 arXiv papers in the "Computer Science - Computation and Language" category, which is the relevant one for Natural Language Processing (NLP) related papers. - Uses OpenAI for creating the embeddings +4. [WebAssembly](webassembly) + - This example shows how `chromem-go` can be compiled to WebAssembly and then used from JavaScript in a browser diff --git a/examples/webassembly/README.md b/examples/webassembly/README.md new file mode 100644 index 0000000..2b73106 --- /dev/null +++ b/examples/webassembly/README.md @@ -0,0 +1,13 @@ +# WebAssembly (WASM) + +Go can compile to WebAssembly, which you can then use from JavaScript in a Browser or similar environments (Node, Deno, Bun etc.). You could also target WASI (WebAssembly System Interface) and run it in a standalone runtime (wazero, wasmtime, Wasmer), but in this example we focus on the Browser use case. + +1. Compile the `chromem-go` WASM binding to WebAssembly: + 1. `cd /path/to/chromem-go/wasm` + 2. `GOOS=js GOARCH=wasm go build -o ../examples/webassembly/chromem-go.wasm` +2. Copy Go's wrapper JavaScript: + 1. `cp $(go env GOROOT)/misc/wasm/wasm_exec.js ../examples/webassembly/wasm_exec.js` +3. Serve the files + 1. `cd ../examples/webassembly` + 2. `go run github.com/philippgille/serve@latest -b localhost -p 8080` or similar +4. Open in your browser diff --git a/examples/webassembly/index.html b/examples/webassembly/index.html new file mode 100644 index 0000000..c25ab9f --- /dev/null +++ b/examples/webassembly/index.html @@ -0,0 +1,69 @@ + + + + + + + + + + + + +

+ + + \ No newline at end of file