This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-vector-index.git
The following commit(s) were added to refs/heads/main by this push:
new ac16418 Remove automatic probe sizing from the centroid router (#133)
ac16418 is described below
commit ac164186ceff6dc9d3ae82117dbc6ff71255c0ce
Author: Jingsong Lee <[email protected]>
AuthorDate: Thu Nov 19 16:50:12 2026 +0800
Remove automatic probe sizing from the centroid router (#133)
---
core/src/autotune.rs | 52 +++++--------------
core/src/index.rs | 21 +-------
core/src/index/router.rs | 59 ----------------------
docs/api.html | 2 +-
.../apache/paimon/index/vector/CentroidRouter.java | 13 -----
.../paimon/index/vector/VectorIndexNative.java | 3 --
.../vector/VectorIndexCentroidShardingTest.java | 8 ++-
jni/src/router.rs | 35 -------------
8 files changed, 18 insertions(+), 175 deletions(-)
diff --git a/core/src/autotune.rs b/core/src/autotune.rs
index c42c960..fe534ec 100644
--- a/core/src/autotune.rs
+++ b/core/src/autotune.rs
@@ -148,22 +148,14 @@ pub fn infer_ivf_nprobe(
top_k: usize,
matching_count: Option<usize>,
) -> io::Result<usize> {
- infer_ivf_nprobe_with_limits(
- nlist,
- vector_count,
- top_k,
- matching_count,
- DEFAULT_IVF_MIN_NPROBE,
- None,
- )
+ infer_ivf_nprobe_with_filter_expansion_cap(nlist, vector_count, top_k,
matching_count, None)
}
-pub(crate) fn infer_ivf_nprobe_with_limits(
+pub(crate) fn infer_ivf_nprobe_with_filter_expansion_cap(
nlist: usize,
vector_count: usize,
top_k: usize,
matching_count: Option<usize>,
- min_nprobe: usize,
max_initial_filter_expansion_factor: Option<usize>,
) -> io::Result<usize> {
if nlist == 0 {
@@ -181,7 +173,7 @@ pub(crate) fn infer_ivf_nprobe_with_limits(
.checked_mul(DEFAULT_IVF_CANDIDATES_PER_RESULT)
.ok_or_else(|| invalid_input("automatic nprobe candidate count
overflows usize"))?;
let candidate_lists = candidate_rows.div_ceil(average_list_rows);
- let mut nprobe = min_nprobe
+ let mut nprobe = DEFAULT_IVF_MIN_NPROBE
.max(nlist.div_ceil(DEFAULT_IVF_LIST_FRACTION))
.max(candidate_lists)
.min(nlist);
@@ -429,6 +421,8 @@ mod tests {
#[test]
fn automatic_nprobe_scales_for_lists_topk_and_filters() {
+ assert_eq!(infer_ivf_nprobe(4, 25_000, 10, None).unwrap(), 4);
+ assert_eq!(infer_ivf_nprobe(8, 25_000, 10, None).unwrap(), 8);
assert_eq!(infer_ivf_nprobe(64, 1_000_000, 10, None).unwrap(), 8);
assert_eq!(infer_ivf_nprobe(1024, 1_000_000, 10, None).unwrap(), 64);
assert_eq!(
@@ -441,15 +435,8 @@ mod tests {
#[test]
fn automatic_nprobe_caps_initial_filter_expansion() {
assert_eq!(
- infer_ivf_nprobe_with_limits(
- 256,
- 2_560_000,
- 3,
- Some(256_000),
- DEFAULT_IVF_MIN_NPROBE,
- Some(4)
- )
- .unwrap(),
+ infer_ivf_nprobe_with_filter_expansion_cap(256, 2_560_000, 3,
Some(256_000), Some(4))
+ .unwrap(),
64
);
}
@@ -457,15 +444,8 @@ mod tests {
#[test]
fn automatic_nprobe_filter_expansion_cap_preserves_bounds() {
assert_eq!(
- infer_ivf_nprobe_with_limits(
- 256,
- 2_560_000,
- 3,
- Some(256_000),
- DEFAULT_IVF_MIN_NPROBE,
- Some(1)
- )
- .unwrap(),
+ infer_ivf_nprobe_with_filter_expansion_cap(256, 2_560_000, 3,
Some(256_000), Some(1))
+ .unwrap(),
16
);
assert_eq!(
@@ -473,23 +453,15 @@ mod tests {
160
);
assert_eq!(
- infer_ivf_nprobe_with_limits(
- 256,
- 2_560_000,
- 3,
- Some(5_120_000),
- DEFAULT_IVF_MIN_NPROBE,
- Some(4)
- )
- .unwrap(),
+ infer_ivf_nprobe_with_filter_expansion_cap(256, 2_560_000, 3,
Some(5_120_000), Some(4))
+ .unwrap(),
16
);
- assert!(infer_ivf_nprobe_with_limits(
+ assert!(infer_ivf_nprobe_with_filter_expansion_cap(
256,
2_560_000,
3,
Some(256_000),
- DEFAULT_IVF_MIN_NPROBE,
Some(0)
)
.is_err());
diff --git a/core/src/index.rs b/core/src/index.rs
index 0845933..715b050 100644
--- a/core/src/index.rs
+++ b/core/src/index.rs
@@ -17,8 +17,7 @@
use crate::autotune::{
default_training_vector_count, diskann_build_preset,
infer_diskann_l_search, infer_ivf_nlist,
- infer_ivf_nprobe_with_limits, infer_rq_bits, DiskAnnBuildPreset,
TuningObjective,
- DEFAULT_IVF_MIN_NPROBE,
+ infer_ivf_nprobe_with_filter_expansion_cap, infer_rq_bits,
DiskAnnBuildPreset, TuningObjective,
};
use crate::diskann::{
diskann_training_sample_limit, validate_diskann_format_configuration,
@@ -1244,29 +1243,13 @@ impl VectorSearchParams {
nlist: usize,
vector_count: usize,
matching_count: Option<usize>,
- ) -> io::Result<usize> {
- self.resolve_ivf_nprobe_with_min(
- nlist,
- vector_count,
- matching_count,
- DEFAULT_IVF_MIN_NPROBE,
- )
- }
-
- fn resolve_ivf_nprobe_with_min(
- self,
- nlist: usize,
- vector_count: usize,
- matching_count: Option<usize>,
- min_nprobe: usize,
) -> io::Result<usize> {
match self.search_width {
- SearchWidth::Auto => infer_ivf_nprobe_with_limits(
+ SearchWidth::Auto => infer_ivf_nprobe_with_filter_expansion_cap(
nlist,
vector_count,
self.top_k,
matching_count,
- min_nprobe,
self.max_initial_filter_expansion_factor,
),
SearchWidth::IvfNProbe if self.width > 0 =>
Ok(self.width.min(nlist)),
diff --git a/core/src/index/router.rs b/core/src/index/router.rs
index 31421de..cc59e71 100644
--- a/core/src/index/router.rs
+++ b/core/src/index/router.rs
@@ -106,23 +106,6 @@ impl CentroidRouter {
})
}
- /// Resolve the outer shard count, allowing small routers to prune whole
files.
- pub fn resolve_nprobe(
- &self,
- params: VectorSearchParams,
- total_vectors: usize,
- matching_vectors: Option<usize>,
- ) -> io::Result<usize> {
- params.validate()?;
- let nlist = self.nlist();
- let min_nprobe = match nlist {
- 4 => 3,
- 8 => 4,
- _ => DEFAULT_IVF_MIN_NPROBE,
- };
- params.resolve_ivf_nprobe_with_min(nlist, total_vectors,
matching_vectors, min_nprobe)
- }
-
fn routing_vector<'a>(&self, query: &'a [f32]) -> io::Result<Cow<'a,
[f32]>> {
let d = self.dimension();
validate_query(query, d)?;
@@ -189,48 +172,6 @@ impl CentroidRouter {
mod tests {
use super::*;
- #[test]
- fn outer_routing_uses_small_floors_before_candidate_and_filter_expansion()
{
- let auto = VectorSearchParams::automatic(10);
- for (nlist, expected) in [
- (3, 3),
- (4, 3),
- (5, 5),
- (7, 7),
- (8, 4),
- (9, 8),
- (16, 8),
- (256, 16),
- ] {
- let router = CentroidRouter::from_centers(1, MetricType::L2,
vec![0.; nlist]).unwrap();
- assert_eq!(router.resolve_nprobe(auto, 25_000, None).unwrap(),
expected);
- }
- for (nlist, filtered, large_k) in [(4, 4, 4), (8, 5, 7)] {
- let router = CentroidRouter::from_centers(1, MetricType::L2,
vec![0.; nlist]).unwrap();
- assert_eq!(
- router.resolve_nprobe(auto, 25_000, Some(20_000)).unwrap(),
- filtered
- );
- assert_eq!(
- router
- .resolve_nprobe(VectorSearchParams::automatic(5_000),
25_000, None)
- .unwrap(),
- large_k
- );
- assert_eq!(
- router.resolve_nprobe(auto, 25_000, Some(500)).unwrap(),
- nlist
- );
- assert_eq!(
- router
- .resolve_nprobe(VectorSearchParams::new(10, 1), 25_000,
Some(500))
- .unwrap(),
- 1
- );
- assert_eq!(auto.resolve_ivf_nprobe(nlist, 25_000, None).unwrap(),
nlist);
- }
- }
-
#[test]
fn router_payload_is_independent_of_shard_type_and_rejects_corruption() {
// Frozen routing format: two 2D cosine centers, including a tie on
[1, 1].
diff --git a/docs/api.html b/docs/api.html
index 845d333..a06b634 100644
--- a/docs/api.html
+++ b/docs/api.html
@@ -325,7 +325,7 @@ try (CentroidRouter router =
CentroidRouter.deserialize(payload)) {
int[] filesToProbe = router.findNearestCentroids(query, 8);
}</code></pre>
<p>Call <code>planTrainingSample(vectorCount)</code> on a fresh
IVF-FLAT trainer with the outer routing options for every shard type. It
returns zero-based input ordinals in reservoir slot order. A distributed job
can read those rows from its splits and feed them back in that order to
reproduce streaming IVF-FLAT training. DiskANN’s seed and memory budget apply
when training PQ and building the graph inside each shard. The serialized
router contains the metric, dimension and co [...]
- <p>In each shard, use <code>VectorIndexTrainer.create</code>,
<code>VectorIndexWriter.addVectors</code> and <code>writeIndex</code>. Use the
standard <code>VectorIndexReader</code> on the selected files and merge results
by score. The caller chooses the outer probe count explicitly or with
<code>router.resolveNprobe</code>. Local IVF probes and DiskANN graph search
width are independent. Keep the router and its center-to-file mapping in the
same index generation.</p>
+ <p>In each shard, use <code>VectorIndexTrainer.create</code>,
<code>VectorIndexWriter.addVectors</code> and <code>writeIndex</code>. Use the
standard <code>VectorIndexReader</code> on the selected files and merge results
by score. Pass the number of shards to search to
<code>findNearestCentroids</code>. The Paimon routed index reader chooses this
width for each row-ID range. Local IVF probes and DiskANN graph search width
are independent. Keep the router and its center-to-file [...]
<p>The corresponding Rust entry points are
<code>VectorIndexTrainer::new</code>,
<code>CentroidRouter::from_training</code>, and
<code>CentroidRouter::{serialize, deserialize, assign_centroid,
find_nearest_centroids}</code>. The wire format is documented in <a
href="../core/STORAGE_FORMAT.md">STORAGE_FORMAT.md</a>.</p>
</section>
diff --git
a/java/src/main/java/org/apache/paimon/index/vector/CentroidRouter.java
b/java/src/main/java/org/apache/paimon/index/vector/CentroidRouter.java
index 657e5a3..26de983 100644
--- a/java/src/main/java/org/apache/paimon/index/vector/CentroidRouter.java
+++ b/java/src/main/java/org/apache/paimon/index/vector/CentroidRouter.java
@@ -67,19 +67,6 @@ public final class CentroidRouter implements AutoCloseable {
return VectorIndexNative.findNearestCentroids(requireOpen(), query,
nprobe);
}
- /**
- * Resolves the initial number of shards to probe. Automatic routing
starts at three shards for
- * four centers and four shards for eight centers. Top-K and filter
selectivity can increase
- * the width. Pass -1 for matchingVectors when there is no row-ID filter.
- */
- public synchronized int resolveNprobe(
- VectorSearchParams params, long totalVectors, long
matchingVectors) {
- if (params == null) {
- throw new NullPointerException("params");
- }
- return VectorIndexNative.routerNprobe(requireOpen(), params,
totalVectors, matchingVectors);
- }
-
@Override
public synchronized void close() {
if (nativePtr != 0L) {
diff --git
a/java/src/main/java/org/apache/paimon/index/vector/VectorIndexNative.java
b/java/src/main/java/org/apache/paimon/index/vector/VectorIndexNative.java
index 38dcd25..9f05c38 100644
--- a/java/src/main/java/org/apache/paimon/index/vector/VectorIndexNative.java
+++ b/java/src/main/java/org/apache/paimon/index/vector/VectorIndexNative.java
@@ -69,9 +69,6 @@ final class VectorIndexNative {
static native void freeRouter(long ptr);
- static native int routerNprobe(
- long ptr, VectorSearchParams params, long totalVectors, long
matchingVectors);
-
static native int assignCentroid(long ptr, float[] vector);
static native int[] findNearestCentroids(long ptr, float[] query, int
nprobe);
diff --git
a/java/src/test/java/org/apache/paimon/index/vector/VectorIndexCentroidShardingTest.java
b/java/src/test/java/org/apache/paimon/index/vector/VectorIndexCentroidShardingTest.java
index b8d1a49..ba5c7e5 100644
---
a/java/src/test/java/org/apache/paimon/index/vector/VectorIndexCentroidShardingTest.java
+++
b/java/src/test/java/org/apache/paimon/index/vector/VectorIndexCentroidShardingTest.java
@@ -61,11 +61,9 @@ public final class VectorIndexCentroidShardingTest {
check(payload.length < CentroidRouter.maxSerializedBytes(),
"router size bound");
float[] query = Arrays.copyOf(rows, 4);
int selected = router.assignCentroid(query);
- check(router.findNearestCentroids(query, 1)[0] == selected,
"routing consistency");
- VectorSearchParams automatic = VectorSearchParams.automatic(10);
- check(router.resolveNprobe(automatic, 256, -1) == 3, "automatic
outer width");
- check(router.resolveNprobe(automatic, 256, 128) == 4, "filtered
outer width");
- check(router.resolveNprobe(VectorSearchParams.ivf(1, 2), 256, -1)
== 2, "outer width");
+ int[] nearest = router.findNearestCentroids(query, 2);
+ check(nearest.length == 2, "caller-selected routing width");
+ check(nearest[0] == selected, "routing consistency");
long[] ids = new long[256];
float[] vectors = new float[rows.length];
int count = 0;
diff --git a/jni/src/router.rs b/jni/src/router.rs
index 9ab4be4..caea1eb 100644
--- a/jni/src/router.rs
+++ b/jni/src/router.rs
@@ -18,41 +18,6 @@
use super::*;
use paimon_vindex_core::index::CentroidRouter;
-#[no_mangle]
-pub extern "system" fn
Java_org_apache_paimon_index_vector_VectorIndexNative_routerNprobe(
- env: JNIEnv,
- _class: JClass,
- ptr: jlong,
- params: JObject,
- total_vectors: jlong,
- matching_vectors: jlong,
-) -> jint {
- jni_call(env, |env| {
- if total_vectors < 0 || matching_vectors < -1 {
- return throw_and_return(env, "invalid vector count");
- }
- let params = match search_params(env, params) {
- Ok(p) => p,
- Err(e) => return throw_and_return(env, &e),
- };
- match router(ptr).and_then(|t| {
- t.resolve_nprobe(
- params,
- total_vectors as usize,
- if matching_vectors < 0 {
- None
- } else {
- Some(matching_vectors as usize)
- },
- )
- .map_err(|e| e.to_string())
- }) {
- Ok(nprobe) => nprobe as jint,
- Err(e) => throw_and_return(env, &e),
- }
- })
-}
-
fn router(ptr: jlong) -> Result<&'static CentroidRouter, String> {
if ptr == 0 {
return Err("null router pointer".into());