pub struct Scored<D, S> { /* private fields */ }Expand description
One search result: what matched, and the score it matched at.
A named type rather than a (D, S), so a reader takes data_ref and
score_ref instead of remembering which half of a pair is which. The tuple
is still reachable, at the one point it costs nothing to be one:
into_components, where the hit is being taken apart anyway.
§The score’s SHAPE is a parameter, and NOTHING defaults it
Every scoring node answers in its own currency: a cosine or L2 DISTANCE (lower is closer), an
inner product, a BM25 relevance (unbounded above), a fused rank. S has no default, so the
currency is SPELLED by whoever produces the hit — a seam names it as an associated type and a
backend fills that in with what its engine measures in.
The default that is not here would have been f32, and what it bought is the reason there is
none: a signature reading Vec<Scored<R::Key>> reads NEUTRAL over the whole family while
pinning one engine’s arithmetic. f32 is BM25’s shape and the shape a cosine face reports in;
it is not the shape a quantised backend, a fused rank or a posterior arrives in, and the first
member to answer in another one would have had to move every signature that had been reading as
though it did not care. A parameter spelled at every site is the same fact with nowhere left for
it to hide.
Spelling Scored<D, Score> is the MARKED form. Score IS the closed unit
interval, so writing it is a claim that something normalised the value, made at the place the
normalising happened rather than assumed by a later reader of an f32.
The dividend lands at the layer above: two hit lists at different S do not merge, and making
them merge is a conversion somebody writes down. Normalisation stops being an undocumented
convention about what an f32 means here and becomes an act with a type.
§D is what matched, which is not always a key
An index answers with ADDRESSES, which is why VectorRead::knn
returns Scored<Self::Address, Self::Score> — identity and score, never the payload. A fusion
layer ranks
whatever it is holding, hydrated records included, so the field is the DATA and
Scored<Record, S> is spellable without a second type being born to say it.
§No bound on either parameter
Ordering is not a property of a hit. It is what a sort or a merge asks for, so the
PartialOrd-class bound belongs at that call site, spent by the body that needs it — and no
such site exists yet.
§The accessors are the emitted pair, under this type’s own names
A generated column is handed out as x_ref(&self) -> &T, with x(&self) -> T beside it where
the column is copy — the borrow always, the copy in addition. Both halves here follow it:
data_ref and score_ref are always there, and
data and score sit beside them behind a Copy gate written on
the METHOD.
On the method rather than on the parameter, which is what keeps a shape that cannot be copied
from being locked out of the type: a String key or a composite fused score is stored, borrowed
and decomposed exactly as an f32 is, and the only thing it refuses is being handed back by
value for free — E0277 at that call and nowhere else. Binding Copy on D or S would have
made the whole type unavailable to them to spare two methods.
Implementations§
Source§impl<D, S> Scored<D, S>
impl<D, S> Scored<D, S>
Sourcepub const fn new(data: D, score: S) -> Self
pub const fn new(data: D, score: S) -> Self
Pair what matched with the score the search gave it.
Sourcepub const fn data_ref(&self) -> &D
pub const fn data_ref(&self) -> &D
What matched, BORROWED.
The half every shape can answer, which is why nothing is required of D for it.
Sourcepub const fn data(&self) -> Dwhere
D: Copy,
pub const fn data(&self) -> Dwhere
D: Copy,
What matched, BY VALUE, where it is Copy — a bare row id, a u64 key.
Sourcepub const fn score_ref(&self) -> &S
pub const fn score_ref(&self) -> &S
The score, BORROWED, in the scoring node’s own currency and direction.
The half every score shape can answer: a composite fused score that is no more Copy than a
String is comes back through here.
Sourcepub const fn score(&self) -> Swhere
S: Copy,
pub const fn score(&self) -> Swhere
S: Copy,
The score, BY VALUE, where it is Copy — the raw f32 and a Score both are.
Sourcepub fn into_data(self) -> D
pub fn into_data(self) -> D
Take what matched, dropping the score — for a caller that has finished ranking and now hydrates.
into_components.0 says the same thing; this is the name for the
case that is only ever that, and it is the call the hydration sites already write.
Sourcepub fn into_components(self) -> (D, S)
pub fn into_components(self) -> (D, S)
Take both halves, neither cloned — for a caller that keeps the score as well: a merge writing a fused rank, a wire mapping rendering the pair, a normaliser building the marked hit its output declares.
Trait Implementations§
impl<D: PartialEq, S: PartialEq> StructuralPartialEq for Scored<D, S>
Auto Trait Implementations§
impl<D, S> Freeze for Scored<D, S>
impl<D, S> RefUnwindSafe for Scored<D, S>where
D: RefUnwindSafe,
S: RefUnwindSafe,
impl<D, S> Send for Scored<D, S>
impl<D, S> Sync for Scored<D, S>
impl<D, S> Unpin for Scored<D, S>
impl<D, S> UnsafeUnpin for Scored<D, S>where
D: UnsafeUnpin,
S: UnsafeUnpin,
impl<D, S> UnwindSafe for Scored<D, S>where
D: UnwindSafe,
S: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.impl<T> Fruit for T
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> ⓘ
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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.