1use git_vdb::{open, Document, Embedder, Result};
2
3#[derive(Clone, Debug)]
4struct ExampleEmbedder;
5
6impl Embedder for ExampleEmbedder {
7 fn model_id(&self) -> &str {
8 "example/compass@1"
9 }
10
11 fn embed(&self, input: &[String]) -> Result<Vec<Vec<f32>>> {
12 Ok(input
13 .iter()
14 .map(|text| {
15 if text.to_lowercase().contains("north") {
16 vec![0.0, 1.0]
17 } else {
18 vec![1.0, 0.0]
19 }
20 })
21 .collect())
22 }
23}
24
25fn main() -> git_vdb::Result<()> {
26 let temporary = tempfile::TempDir::new()?;
27 let db = open(temporary.path().join("documents.git"))?;
28 let docs = db.text_collection("docs", ExampleEmbedder)?;
29 docs.upsert_documents([
30 Document::new("east", "A document about the east"),
31 Document::new("north", "A document about the north"),
32 ])?;
33 assert_eq!(
34 docs.search_text("north wind", 1)?[0].id.to_string(),
35 "north"
36 );
37 Ok(())
38}