pub struct CostEstimator {
pub byte_budget: usize,
pub corpus: usize,
pub vector_bytes: usize,
}Expand description
Byte-budget cost model estimator for vector filter strategies (§5.3, D-007).
The 0.4.5–0.5.4 version of this type carried a byte_budget field it never
read and branched on candidate_count against two hard-coded thresholds
(500, 5000) — D-007’s interface with none of D-007’s mechanism. It now prices
both strategies in bytes and takes the minimum, and byte_budget is a hard
ceiling on the candidate set rather than an unused field.
Fields§
§byte_budget: usize§corpus: usizeCorpus size: how many vectors the model holds. Sets selectivity, and so the k′ inflation.
vector_bytes: usizeBytes per stored vector, from the model’s declared dimension (D-037).
Implementations§
Source§impl CostEstimator
impl CostEstimator
pub fn new(byte_budget: usize, corpus: usize, vector_bytes: usize) -> Self
Sourcepub fn k_prime(&self, k: usize, candidates: usize) -> usize
pub fn k_prime(&self, k: usize, candidates: usize) -> usize
The k′ PostFilter must request to expect k survivors.
Selectivity is candidates / corpus, so k′ = k × corpus / candidates.
Clamped to the corpus: asking the index for more rows than exist is not
an error but it is not an estimate either, and letting it run away makes
the cost comparison meaningless for tight filters — which is precisely
when the comparison matters.
Sourcepub fn estimate(
&self,
k: usize,
candidates: CandidateCount,
) -> Result<CostEstimate>
pub fn estimate( &self, k: usize, candidates: CandidateCount, ) -> Result<CostEstimate>
Price both strategies and take the minimum (§5.3, D-007).
| Strategy | Estimated bytes |
|---|---|
PostFilter | k′ × (vector_bytes + row_bytes) + the filter pass |
PreFilterCTE | the filtered scan + candidates × vector_bytes |
The filter pass is common to both — the traversal has to run either way — so it appears in both rows and cancels out of the comparison. It is included anyway, because the budget ceiling is checked against an absolute figure and a cost model that omits a term it “knows” cancels is a cost model that lies the moment someone adds a third strategy.
Trait Implementations§
Source§impl Clone for CostEstimator
impl Clone for CostEstimator
Source§fn clone(&self) -> CostEstimator
fn clone(&self) -> CostEstimator
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for CostEstimator
impl RefUnwindSafe for CostEstimator
impl Send for CostEstimator
impl Sync for CostEstimator
impl Unpin for CostEstimator
impl UnsafeUnpin for CostEstimator
impl UnwindSafe for CostEstimator
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> 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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request