pub struct PqRerank { /* private fields */ }Expand description
Object-safe RerankCodec wrapper around PqCodec.
The codec starts untrained. encode and prepare_query return
RerankError::NotTrained until train() has been called with a
representative sample of vectors.
from_codec accepts a pre-trained PqCodec (used when restoring from
a snapshot).
Implementations§
Source§impl PqRerank
impl PqRerank
Sourcepub fn new(dim: usize, m: usize, k: usize) -> Self
pub fn new(dim: usize, m: usize, k: usize) -> Self
Construct an untrained PQ codec configuration.
m is the number of subspaces; k is centroids per subspace.
Defaults used by higher-level callers: m = 8, k = 256.
encode / distance_prepared return RerankError::NotTrained until
train() has been called.
Sourcepub fn from_codec(codec: PqCodec) -> Self
pub fn from_codec(codec: PqCodec) -> Self
Construct from a pre-trained codec (used when restoring from snapshot).
Trait Implementations§
Source§impl RerankCodec for PqRerank
impl RerankCodec for PqRerank
Source§fn encode(&self, v: &[f32]) -> Result<Vec<u8>, RerankError>
fn encode(&self, v: &[f32]) -> Result<Vec<u8>, RerankError>
Encode a full-precision vector to PQ bytes (one centroid index per subspace).
The serialized form is the raw UnifiedQuantizedVector buffer
(as_bytes()): 32-byte QuantHeader followed by m code bytes.
Source§fn prepare_query(&self, q: &[f32]) -> Result<PreparedQuery, RerankError>
fn prepare_query(&self, q: &[f32]) -> Result<PreparedQuery, RerankError>
Prepare the query by precomputing the M×K asymmetric distance table.
The prepared form is PreparedQuery::Lut where lut[sub][centroid]
holds the squared L2 distance from the query’s sub-vector to each
centroid of subspace sub. This is the standard ADC lookup table.
Source§fn distance_prepared(
&self,
prepared: &PreparedQuery,
encoded: &[u8],
) -> Result<f32, RerankError>
fn distance_prepared( &self, prepared: &PreparedQuery, encoded: &[u8], ) -> Result<f32, RerankError>
Compute asymmetric ADC distance from a prepared query to a PQ-encoded candidate.
Expects PreparedQuery::Lut produced by prepare_query.
Source§fn train(&mut self, samples: &[&[f32]]) -> Result<(), RerankError>
fn train(&mut self, samples: &[&[f32]]) -> Result<(), RerankError>
Train PQ codebooks via k-means on a sample of vectors.
Validates that:
samplesis non-empty.- Every sample has length
self.dim. self.dim % self.m == 0(PQ requires divisible dimensionality).- At least
self.ksamples are provided (k-means needs ≥ k points).
On success, stores the trained codec and subsequent encode /
distance_prepared calls will succeed.
Auto Trait Implementations§
impl Freeze for PqRerank
impl RefUnwindSafe for PqRerank
impl Send for PqRerank
impl Sync for PqRerank
impl Unpin for PqRerank
impl UnsafeUnpin for PqRerank
impl UnwindSafe for PqRerank
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
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>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.