import itzma
from itzma import attr
store = itzma.Store("memory://")
schema = itzma.Schema(dim=3, metric=itzma.Metric.COSINE, attrs={"year": itzma.AttrType.NUMBER})
ns = itzma.Namespace.create(store, "articles", schema)
ns.upsert([
{"id": "intro", "vector": [0.9, 0.1, 0.0], "attrs": {"year": 2024}},
{"id": "faq", "vector": [0.0, 1.0, 0.2], "attrs": {"year": 2021}},
])
hits = ns.query([1.0, 0.0, 0.0], top_k=2, filter=attr("year") >= 2022)
print(hits.ids, hits.distances)
let store = Arc::new(InMemory::new());
let schema = Schema::new(3, Metric::Cosine)
.with_attrs(AttrSchema::new().field("title", AttrType::Text));
let ns = Namespace::create(store.clone(), "articles", schema).await?;
let seq = ns
.upsert(vec![
Document {
id: "intro".into(),
vector: vec![0.9, 0.1, 0.0],
attrs: Some(serde_json::json!({ "title": "Introduction" })),
sparse: None,
},
Document {
id: "faq".into(),
vector: vec![0.0, 1.0, 0.2],
attrs: None,
sparse: None,
},
])
.await?;
assert_eq!(seq, 1);
let hits = ns.query(&[1.0, 0.0, 0.0], 2).await?;