Web-optimized vector database (written in Rust).
npm install victor-db
```ts import { Db } from "victor";
const db = await Db.new();
const content = "My content!"; const tags = ["these", "are", "tags"]; const embedding = new Float64Array(/* your embedding here */);
// write to victor await db.insert(content, embedding, tags);
// read from victor const result = await db.search(embedding, ["tags"]); assert(result == content);
// clear database await db.clear(); ```
See www/
for a more complete example, including fetching embeddings from OpenAI.
cargo add victor-db
```ts use std::path::PathBuf;
use victor_db::native::Db;
let _ = std::fs::createdir("./victortestdata"); let mut victor = Db::new(PathBuf::from("./victortest_data"));
victor.clear_db().await.unwrap();
victor .write( "Test Vector 1", vec![1.0, 0.0, 0.0], vec!["Test".tostring()], ) .await; victor .write( "Test Vector 2", vec![0.0, 1.0, 0.0], vec!["Test".tostring()], ) .await;
let nearest = victor .findnearestneighbor(vec![0.9, 0.0, 0.0], vec![]) .await .unwrap() .content; asserteq!(nearest, "Test Vector 1".tostring()); ```
This example is also in the /examples
directory. If you've cloned this repository, you can run it with cargo run --example native_filesystem
.
Victor is written in Rust, and compiled to wasm with wasm-pack.
Install wasm pack with cargo install wasm-pack
or npm i -g wasm-pack
(https://rustwasm.github.io/wasm-pack/installer/)
Build Victor with wasm-pack build
Set up the example project, which is in www/
.
If you use nvm, you can just run cd www/ && nvm use
Then, npm i
.
From www/
, start the example project with npm run start
.
Relevant code at src/packed_vector.rs
.