#[non_exhaustive]pub enum IndexKind {
Range,
Unique,
Text,
Ann,
Agg,
}Expand description
Index kind (KIND range|unique).
use kevy_index::IndexKind;
assert_eq!(IndexKind::parse(b"UNIQUE"), Some(IndexKind::Unique));
assert_eq!(IndexKind::parse(IndexKind::Agg.tag().as_bytes()), Some(IndexKind::Agg));
assert_eq!(IndexKind::parse(b"hash"), None);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Range
Ordered scan over (value, key) pairs.
use kevy_index::{IndexValue, Segment};
let mut seg = Segment::new();
seg.apply(b"u:1", None, Some(IndexValue::I64(30)));
seg.apply(b"u:2", None, Some(IndexValue::I64(20)));
let (hits, _) = seg.range(&IndexValue::I64(0), &IndexValue::I64(99), None, 10);
assert_eq!(hits[0].0, b"u:2", "value order, not key order");Unique
Point lookup by value; duplicates recorded (declarative fence: uniqueness is verified, not write-enforced).
use kevy_index::{IndexValue, Segment};
let mut seg = Segment::new();
seg.apply(b"u:1", None, Some(IndexValue::Str(b"a@x".to_vec())));
seg.apply(b"u:2", None, Some(IndexValue::Str(b"a@x".to_vec())));
// the second write is not refused; the lookup shows the duplicate
assert_eq!(seg.eq(&IndexValue::Str(b"a@x".to_vec()), 10).len(), 2);Text
Full-text: the field tokenizes into an inverted segment
(kevy-text); queried with MATCH, BM25-ranked.
use kevy_index::{FieldSpec, IndexKind, IndexSpec, ValType};
let fields = vec![FieldSpec::new("title").with_weight(2.0), FieldSpec::new("body")];
let text = IndexSpec::builder("posts", "post:", IndexKind::Text, ValType::Str)
.with_fields(fields)
.build()?;
assert_eq!(text.fields().len(), 2, "only text serves several fields");Ann
ANN: the field holds an f32 LE vector indexed in an HNSW
graph (kevy-vector); queried with KNN, distance-ranked.
use kevy_index::{AnnSpec, IndexKind, IndexSpec, ValType};
let b = IndexSpec::builder("emb", "doc:", IndexKind::Ann, ValType::Vector).with_field("v");
assert!(b.clone().build().is_err(), "an ANN index needs its parameters");
assert_eq!(b.with_ann(AnnSpec::new(128)).build()?.ann(), Some(AnnSpec::new(128)));Agg
Aggregate: per-group count/sum/min/max of the field,
grouped by IndexSpec::group_by; queried with GROUP/GROUPS.
use kevy_index::{IndexKind, IndexSpec, ValType};
let spend = IndexSpec::builder("spend", "o:", IndexKind::Agg, ValType::F64)
.with_field("total")
.with_group_by("region")
.build()?;
assert_eq!(spend.group_by(), Some(&b"region"[..]));Implementations§
Trait Implementations§
impl Copy for IndexKind
impl Eq for IndexKind
impl StructuralPartialEq for IndexKind
Auto Trait Implementations§
impl Freeze for IndexKind
impl RefUnwindSafe for IndexKind
impl Send for IndexKind
impl Sync for IndexKind
impl Unpin for IndexKind
impl UnsafeUnpin for IndexKind
impl UnwindSafe for IndexKind
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more