Skip to main content

Module cost_model

Module cost_model 

Source
Expand description

Per-index cost formulas for vector search query optimization.

Each formula reflects the asymptotic search cost of a specific approximate nearest-neighbour index, expressed as expected number of distance computations for a single k-NN query. Distance computations dominate query latency for vector search, so distance-count is a robust proxy for wall-clock time.

The formulas implemented here are:

  • HNSW: O(log n × M × ef)ef * (M * log n) expected probes through the hierarchy.
  • IVF: O(n / nprobe + n_clusters)n_clusters for coarse centroid selection, then n / nprobe for fine search inside the probed cells.
  • LSH: O(L × bucket_size + K × L × dim)K * L * dim for hash evaluation and L * bucket_size for candidate scoring.
  • PQ: O(centroids × subquantizers + n × subquantizers) — codebook lookup table build then asymmetric distance against every encoded vector.

Each cost is multiplied by a tunable per-index weight obtained from historical statistics, enabling online cost-model adaptation when actual latency measurements drift from the static formula.

All costs are expressed in abstract distance-equivalent units. Higher is more expensive; the dispatcher picks the lowest-cost index that meets the requested recall.

Structs§

CostEstimate
One row of cost-model output: family + estimated cost + estimated recall.
CostModel
Cost-model entrypoint used by the optimizer dispatcher.
CostWeights
Online-learnable weights applied to each per-index formula output.
IndexParameters
Tunable per-index parameters that affect the cost formula.
WorkloadProfile
Workload characteristics the cost model needs to estimate per-index cost.

Enums§

IndexFamily
Index families recognised by the optimizer cost model.