pub struct ScoreFn(pub Arc<dyn Fn(f32, &RecordBatch) -> f32 + Send + Sync>);Expand description
Injectable per-result scoring function for hybrid ranking.
Called after HNSW retrieval with the HNSW distance and a single-row
RecordBatch containing all Parquet columns for that result. Returns a
replacement score (lower = better rank, same convention as distance).
Typical use: combine HNSW distance with recency and importance signals
from the episodic_columns for agent memory tables:
use ailake_core::{hybrid_score, episodic_columns};
use ailake_query::scanner::ScoreFn;
use arrow_array::{RecordBatch, cast::AsArray};
use arrow_array::types::Float32Type;
let score_fn = ScoreFn::new(|distance, row| {
let recency = row
.column_by_name(episodic_columns::RECENCY_WEIGHT)
.and_then(|c| c.as_primitive_opt::<Float32Type>())
.and_then(|a| a.iter().next().flatten())
.unwrap_or(1.0);
let importance = row
.column_by_name(episodic_columns::IMPORTANCE_SCORE)
.and_then(|c| c.as_primitive_opt::<Float32Type>())
.and_then(|a| a.iter().next().flatten())
.unwrap_or(1.0);
hybrid_score(distance, recency, importance)
});Tuple Fields§
§0: Arc<dyn Fn(f32, &RecordBatch) -> f32 + Send + Sync>Implementations§
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for ScoreFn
impl !UnwindSafe for ScoreFn
impl Freeze for ScoreFn
impl Send for ScoreFn
impl Sync for ScoreFn
impl Unpin for ScoreFn
impl UnsafeUnpin for ScoreFn
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
Mutably borrows from an owned value. Read more
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> 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 more