Skip to main content

BatchedReranker

Struct BatchedReranker 

Source
pub struct BatchedReranker { /* private fields */ }
Expand description

Concurrent rerank coalescer.

Wraps a CrossEncoder and serializes concurrent recall reranks through a single worker thread. The worker buffers up to max_batch requests or waits up to max_wait_ms (whichever first), then issues one rerank_batch call. The Mutex around the BERT model is held for the whole batch instead of once per (query, candidate) — the throughput fix mandated by G9.

Single-request latency: the worker flushes immediately when the queue is empty after pulling the first job, so a lone request only pays one recv_timeout(0) round-trip — no artificial waiting.

Implementations§

Source§

impl BatchedReranker

Source

pub fn new(encoder: CrossEncoder) -> Self

Wrap an existing CrossEncoder with the default batching parameters (max_batch = 32, max_wait_ms = 5).

Source

pub fn with_params( encoder: CrossEncoder, max_batch: usize, max_wait_ms: u64, ) -> Self

Wrap an existing CrossEncoder with custom batching parameters.

Source

pub fn with_reflection_boost( encoder: CrossEncoder, boost: ReflectionBoostConfig, ) -> Self

v0.7.0 L2-8 — wrap an existing CrossEncoder with a custom reflection-boost config alongside default batching parameters. Used by the recall integration tests to pin specific boost shapes (e.g. disabled() for the regression test).

Source

pub fn with_score_floor( encoder: CrossEncoder, floor: RerankerScoreFloor, ) -> Self

v0.7.0 #1319 — wrap a CrossEncoder with a post-blend score floor. The reflection-boost knob is left at the daemon default (1.2); use Self::with_full_params to set both at once. Default constructors leave the floor Off — flipping it on here is an explicit operator-opt-in.

Source

pub fn rerank( &self, query: &str, candidates: Vec<(Memory, f64)>, ) -> Vec<(Memory, f64)>

Submit a single rerank request. Blocks until the result is available.

#1579 B10 — auto-select. The wrapper keeps BOTH execution paths and picks per call via use_batched_rerank_path:

  • Direct (no worker round-trip) when the encoder is lexical / degraded-lexical (no shared-model mutex to amortise — criterion proved the coalescing flush window made the batched path 12× slower at N=8: ~7.6 ms vs ~0.65 ms), or when fewer than BATCHED_RERANK_MIN_CONCURRENCY requests are in flight (nothing to coalesce with).
  • Coalesced (worker thread, one rerank_batch per flush) for neural encoders under real concurrency — the G9 win (~3× at N=8 neural) is preserved.

If the worker is unavailable for any reason (channel closed), falls back to a direct rerank call on the underlying encoder (with the wrapper’s configured reflection boost applied).

Source

pub fn rerank_coalesced( &self, query: &str, candidates: Vec<(Memory, f64)>, ) -> Vec<(Memory, f64)>

#1579 B10 — force the COALESCED (worker) path regardless of the auto-select. Kept public so the throughput bench (benches/reranker_throughput.rs) and regression tests can keep measuring the raw batched machinery after rerank started auto-selecting away from it at small N. Applies the same post-blend score floor as Self::rerank.

Source

pub fn worker_submissions(&self) -> usize

#1579 B10 — lifetime count of jobs submitted to the coalescing worker. Observability hook for the auto-select regression tests (“lexical traffic never reaches the worker”) and operator diagnostics.

Source

pub fn score_floor(&self) -> RerankerScoreFloor

v0.7.0 #1319 — accessor for the configured score floor, used by operator-facing diagnostics. NOTE (n22): the memory_capabilities envelope does not currently surface this value; wiring the floor through config and exposing it in capabilities is tracked under #1319 / n14.

Source

pub fn reflection_boost(&self) -> &ReflectionBoostConfig

v0.7.0 L2-8 — expose the configured boost for the memory_capabilities reporter.

Source

pub fn encoder(&self) -> &CrossEncoder

Direct access to the wrapped encoder. Useful for callers that want to bypass the coalescer (tests, benchmarks).

Source

pub fn is_neural(&self) -> bool

Convenience shortcut for self.encoder().is_neural(). Most callers in the recall pipeline only need to check the variant for capability reporting.

Source

pub fn is_degraded_lexical(&self) -> bool

v0.7.0 R3-S2 — shortcut for self.encoder().is_degraded_lexical(). The recall path reads this to drive the in-band reranker_used signal exposed via RecallMeta.

Trait Implementations§

Source§

impl Drop for BatchedReranker

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more