Skip to main content

filtering/
filtering.rs

1use git_vdb::{open, Condition, Filter, Point, Query};
2use serde_json::json;
3
4fn main() -> git_vdb::Result<()> {
5    let temporary = tempfile::TempDir::new()?;
6    let docs = open(temporary.path().join("vectors.git"))?.collection("docs");
7    docs.upsert([
8        Point::new("guide", [1.0, 0.0]).with_metadata(json!({"kind": "docs"}))?,
9        Point::new("code", [0.9, 0.1]).with_metadata(json!({"kind": "source"}))?,
10    ])?;
11    let result = docs.advanced()?.query(
12        Query::new([1.0, 0.0], 5)
13            .with_filter(Filter::must([Condition::matches("kind", "docs")]))
14            .with_payload(),
15    )?;
16    assert_eq!(result.points[0].id.to_string(), "guide");
17    Ok(())
18}