pub struct SparseVector {
pub indices: Vec<u32>,
pub values: Vec<f32>,
pub tokens: Option<Vec<String>>,
}Expand description
Represents a sparse vector using parallel arrays for indices and values.
On deserialization: accepts both old format {"indices": [...], "values": [...]}
and new format {"#type": "sparse_vector", "indices": [...], "values": [...]}.
On serialization: always includes #type field with value "sparse_vector".
Fields§
§indices: Vec<u32>Dimension indices
values: Vec<f32>Values corresponding to each index
tokens: Option<Vec<String>>Tokens corresponding to each index
Implementations§
Source§impl SparseVector
impl SparseVector
Sourcepub fn new(
indices: Vec<u32>,
values: Vec<f32>,
) -> Result<Self, SparseVectorLengthMismatch>
pub fn new( indices: Vec<u32>, values: Vec<f32>, ) -> Result<Self, SparseVectorLengthMismatch>
Create a new sparse vector from parallel arrays.
Sourcepub fn new_with_tokens(
indices: Vec<u32>,
values: Vec<f32>,
tokens: Vec<String>,
) -> Result<Self, SparseVectorLengthMismatch>
pub fn new_with_tokens( indices: Vec<u32>, values: Vec<f32>, tokens: Vec<String>, ) -> Result<Self, SparseVectorLengthMismatch>
Create a new sparse vector from parallel arrays.
Sourcepub fn from_pairs(pairs: impl IntoIterator<Item = (u32, f32)>) -> Self
pub fn from_pairs(pairs: impl IntoIterator<Item = (u32, f32)>) -> Self
Create a sparse vector from an iterator of (index, value) pairs.
Sourcepub fn from_triples(
triples: impl IntoIterator<Item = (String, u32, f32)>,
) -> Self
pub fn from_triples( triples: impl IntoIterator<Item = (String, u32, f32)>, ) -> Self
Create a sparse vector from an iterator of (string, index, value) pairs.
Sourcepub fn validate(&self) -> Result<(), MetadataValueConversionError>
pub fn validate(&self) -> Result<(), MetadataValueConversionError>
Validate the sparse vector
Trait Implementations§
Source§impl Clone for SparseVector
impl Clone for SparseVector
Source§fn clone(&self) -> SparseVector
fn clone(&self) -> SparseVector
Returns a duplicate of the value. Read more
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SparseVector
impl Debug for SparseVector
Source§impl<'de> Deserialize<'de> for SparseVector
impl<'de> Deserialize<'de> for SparseVector
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<&SparseVector> for CsVec<f32>
Convert SparseVector to sprs::CsVec for efficient sparse operations
impl From<&SparseVector> for CsVec<f32>
Convert SparseVector to sprs::CsVec for efficient sparse operations
Source§fn from(sparse: &SparseVector) -> Self
fn from(sparse: &SparseVector) -> Self
Converts to this type from the input type.
Source§impl From<SparseVector> for CsVec<f32>
impl From<SparseVector> for CsVec<f32>
Source§fn from(sparse: SparseVector) -> Self
fn from(sparse: SparseVector) -> Self
Converts to this type from the input type.
Source§impl From<SparseVector> for MetadataValue
impl From<SparseVector> for MetadataValue
Source§fn from(v: SparseVector) -> Self
fn from(v: SparseVector) -> Self
Converts to this type from the input type.
Source§impl From<SparseVector> for QueryVector
impl From<SparseVector> for QueryVector
Source§fn from(sparse: SparseVector) -> Self
fn from(sparse: SparseVector) -> Self
Converts to this type from the input type.
Source§impl From<SparseVector> for SparseVector
impl From<SparseVector> for SparseVector
Source§fn from(sparse: SparseVector) -> Self
fn from(sparse: SparseVector) -> Self
Converts to this type from the input type.
Source§impl From<SparseVector> for UpdateMetadataValue
impl From<SparseVector> for UpdateMetadataValue
Source§fn from(v: SparseVector) -> Self
fn from(v: SparseVector) -> Self
Converts to this type from the input type.
Source§impl Ord for SparseVector
impl Ord for SparseVector
Source§impl PartialEq for SparseVector
impl PartialEq for SparseVector
Source§impl PartialOrd for SparseVector
impl PartialOrd for SparseVector
Source§impl Serialize for SparseVector
impl Serialize for SparseVector
Source§impl TryFrom<SparseVector> for SparseVector
impl TryFrom<SparseVector> for SparseVector
Source§type Error = SparseVectorLengthMismatch
type Error = SparseVectorLengthMismatch
The type returned in the event of a conversion error.
impl Eq for SparseVector
impl StructuralPartialEq for SparseVector
Auto Trait Implementations§
impl Freeze for SparseVector
impl RefUnwindSafe for SparseVector
impl Send for SparseVector
impl Sync for SparseVector
impl Unpin for SparseVector
impl UnwindSafe for SparseVector
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.