pub struct Schema {
pub dim: usize,
pub metric: Metric,
pub attrs: AttrSchema,
}Expand description
The shape every document in a namespace must have.
Fixed when the namespace is created and stored in its manifest, and again in
schema.json, which is written once and never changed. It cannot be
changed afterwards; make a new namespace instead.
Fields§
§dim: usizeNumber of components in every vector. Must be at least 1.
metric: MetricDistance metric used by queries.
attrs: AttrSchemaThe typed attribute fields. Empty means the namespace takes no attributes. A schemaless value has none declared and stays free-form; nothing public can build that state.
Implementations§
Source§impl Schema
impl Schema
Sourcepub const fn new(dim: usize, metric: Metric) -> Self
pub const fn new(dim: usize, metric: Metric) -> Self
A schema with no attribute fields: documents may carry no attrs.
Declare fields with with_attrs.
Sourcepub fn with_attrs(self, attrs: AttrSchema) -> Self
pub fn with_attrs(self, attrs: AttrSchema) -> Self
This schema with the attribute fields attrs.
Sourcepub fn validate(&self, vector: &[f32]) -> Result<()>
pub fn validate(&self, vector: &[f32]) -> Result<()>
Check a vector against this schema without touching storage.
Used on every document written and on every query vector.
§Errors
ItzmaError::DimensionMismatchifvector.len() != self.dim.ItzmaError::InvalidVectorif any component is NaN or infinite, or if the metric isMetric::Cosineand every component is zero.
§Examples
use itzma_core::{Metric, Schema};
let schema = Schema::new(2, Metric::Cosine);
assert!(schema.validate(&[1.0, 0.5]).is_ok());
assert!(schema.validate(&[1.0]).is_err());
assert!(schema.validate(&[0.0, 0.0]).is_err());Trait Implementations§
Source§impl<'de> Deserialize<'de> for Schema
impl<'de> Deserialize<'de> for Schema
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Schema
impl StructuralPartialEq for Schema
Auto Trait Implementations§
impl Forget for Schema
impl Freeze for Schemawhere
*const LeafNode<String, FieldDecl> is !null: Freeze,
PhantomData<(Owned, LeafOrInternal)>: Freeze,
PhantomData<Box<(String, FieldDecl)>>: Freeze,
impl Move for Schema
impl RefUnwindSafe for Schema
impl Send for Schema
impl Sync for Schema
impl Unpin for Schema
impl UnsafeUnpin for Schemawhere
*const LeafNode<String, FieldDecl> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(String, FieldDecl)>>: UnsafeUnpin,
impl UnwindSafe for Schema
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more