pub struct Document {
pub id: String,
pub vector: Vec<f32>,
pub attrs: Option<Value>,
pub sparse: Option<SparseVector>,
}Expand description
One stored item: an id, a vector, and optional free-form JSON.
The id is the identity. Upserting a document whose id already exists replaces it wholesale, vector and attributes together.
§JSON form
This is what appears inside WAL objects. attrs is left out when None:
{"id": "a", "vector": [0.1, 0.2], "attrs": {"title": "hello"}, "sparse": [[3, 0.9]]}Fields§
§id: StringCaller-chosen identifier, unique within a namespace. Any string.
vector: Vec<f32>Embedding. Its length must equal the namespace’s dim, and every
component must be finite.
attrs: Option<Value>Arbitrary JSON stored next to the vector and returned on every
Hit. It is checked against the namespace’s attribute
schema on write.
sparse: Option<SparseVector>An optional sparse vector, searched by
Namespace::query_sparse. A
namespace does not declare sparse support up front — some documents
carry one, some don’t, the same shape attrs has. None on a
document written before this field existed.
Implementations§
Source§impl Document
impl Document
Sourcepub fn validate_id(&self) -> Result<()>
pub fn validate_id(&self) -> Result<()>
Check this document’s id without touching storage. Called on every
upsert, before validate_sparse.
§Errors
ItzmaError::InvalidId if the id is empty or longer than
MAX_ID_BYTES.
Sourcepub fn validate_sparse(&self) -> Result<()>
pub fn validate_sparse(&self) -> Result<()>
Check this document’s sparse vector, if it has one, without touching
storage. Called on every upsert, after
Schema::validate.
§Errors
ItzmaError::InvalidVector if the same term id appears twice, a
weight is NaN or infinite, or there are more than MAX_SPARSE_TERMS
terms (the stored term count is a u16).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Document
impl<'de> Deserialize<'de> for Document
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 StructuralPartialEq for Document
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnsafeUnpin for Document
impl UnwindSafe for Document
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<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