-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add batch add api (to rust) * Update readme and add docs * Add docs * Add in_memory example * fix CI * add more docs
- Loading branch information
Showing
8 changed files
with
214 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#[tokio::main(flavor = "current_thread")] | ||
async fn main() { | ||
use victor_db::memory::{Db, DirectoryHandle}; | ||
|
||
let mut victor = Db::new(DirectoryHandle::default()); | ||
|
||
victor.clear_db().await.unwrap(); | ||
|
||
victor | ||
.add_many( | ||
vec!["Pineapple", "Rocks"], // documents | ||
vec!["PizzaToppings"], // tags (only used for filtering) | ||
) | ||
.await; | ||
|
||
victor.add("Cheese pizza", vec![]).await; // Add another entry with no tags | ||
|
||
// read the 10 closest results from victor that are tagged with "tags" | ||
// (only 2 will be returned because we only inserted two embeddings) | ||
let nearest = victor | ||
.search("Hawaiian pizza", vec!["PizzaToppings"], 10) | ||
.await | ||
.first() | ||
.unwrap() | ||
.content | ||
.clone(); | ||
assert_eq!(nearest, "Pineapple".to_string()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,31 @@ | ||
use std::path::PathBuf; | ||
|
||
use victor_db::native::Db; | ||
|
||
#[tokio::main(flavor = "current_thread")] | ||
async fn main() { | ||
use std::path::PathBuf; | ||
|
||
use victor_db::native::Db; | ||
|
||
let _ = std::fs::create_dir("./victor_test_data"); | ||
let mut victor = Db::new(PathBuf::from("./victor_test_data")); | ||
|
||
victor.clear_db().await.unwrap(); | ||
|
||
victor | ||
.add_embedding( | ||
"Test Vector 1", | ||
vec![1.0, 0.0, 0.0], | ||
vec!["Test".to_string()], | ||
) | ||
.await; | ||
victor | ||
.add_embedding( | ||
"Test Vector 2", | ||
vec![0.0, 1.0, 0.0], | ||
vec!["Test".to_string()], | ||
.add_many( | ||
vec!["Pineapple", "Rocks"], // documents | ||
vec!["PizzaToppings"], // tags (only used for filtering) | ||
) | ||
.await; | ||
|
||
victor.add("Cheese pizza", vec![]).await; // Add another entry with no tags | ||
|
||
// read the 10 closest results from victor that are tagged with "tags" | ||
// (only 2 will be returned because we only inserted two embeddings) | ||
let nearest = victor | ||
.search_embedding(vec![0.9, 0.0, 0.0], vec!["Test".to_string()], 10) | ||
.search("Hawaiian pizza", vec!["PizzaToppings"], 10) | ||
.await | ||
.first() | ||
.unwrap() | ||
.content | ||
.clone(); | ||
assert_eq!(nearest, "Test Vector 1".to_string()); | ||
assert_eq!(nearest, "Pineapple".to_string()); | ||
} |
Oops, something went wrong.