Skip to content

[core][c] Expose scored vector search over global row-ID ranges - #1522

Open
miomiocat wants to merge 1 commit into
apache:mainfrom
miomiocat:codex/scored-vector-row-ranges
Open

miomiocat wants to merge 1 commit into
apache:mainfrom
miomiocat:codex/scored-vector-row-ranges

Conversation

@miomiocat

Copy link
Copy Markdown

Purpose

Closes #1521.

Let a consumer retrieve row IDs and scores directly for its assigned row range. Filtering after Top-K can lose valid candidates whenever the table-wide best matches fall outside that range.

Brief change log

  • Intersect the inclusive global row-ID interval with any scalar or bitmap filter before ranking candidates.
  • Expose a scored C execution path that returns row_id and score as Arrow Int64 and Float32. Propagate the expected metric to indexed, raw and scheduled searches and reject incompatible metrics.

Tests

Added coverage for inclusive and invalid ranges, intersection with a scalar predicate, scored results, and distance-metric mismatches.

Local verification passed with cargo build --locked -p paimon-c --lib and cargo fmt --all -- --check. Test execution is left to upstream CI.

API and Format

Adds C builder calls to set a row range and expected distance metric and to execute a scored search. Global row ranges apply to global row IDs. Primary-key results have file-local positions.

Documentation

The C binding guide describes scored output, interval bounds, prefiltering and distance metrics.

Return row IDs and scores without fetching data columns. Intersect the
requested interval with scalar filters before Top-K and validate the
expected distance metric on indexed, raw and scheduled reads. Build local
bitmaps only for partially covered index shards.

Co-Authored-By: Codex <noreply@openai.com>
AI-Model: gpt-6
AI-Contributed/Feature: 524/524
AI-Contributed/UT: 0/0

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Range-scoped scored search addresses the use case in #1521. I verified the generated C header and ran all 109 C binding tests. In the core vector suite, 600 tests passed, including a probe where the unrestricted Top-1 lies outside the requested interval. A separate worker-compatibility probe reproduced the metric failure below.

field: String,
options: HashMap<String, String>,
#[serde(default)]
expected_distance_metric: Option<String>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Enforce the expected metric when merging scheduled search results. The task keeps its existing kind and version, so an older worker can ignore this optional field and return L2 scores for a query that requires cosine. The coordinator already receives the persisted metric, but its check only uses the existing query options and the MultiVector default. With a fully indexed L2 table, dropping this field in a test executor produced a successful result with scores [1.0, 0.5]. Local execution rejected the same query. Compare the worker-reported metric with the expected metric before merging, or version the work so a worker that cannot enforce it rejects the task.


pub(crate) fn ensure_distance_metric(&self, actual: &str) -> crate::Result<()> {
if let Some(expected) = &self.expected_distance_metric {
if expected != actual {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Use the same metric spelling rules for Rust callers on both search routes. with_expected_distance_metric("Inner-Product") goes through the PK metric parser and accepts this alias, while the Data Evolution route compares it verbatim and rejects the same persisted metric. Use the same parser on both routes.

Comment thread docs/src/c-binding.md

`paimon_vector_search_builder_execute_scored` returns global row IDs and scores
as Arrow Int64 and Float32 columns named `row_id` and `score`. An inclusive
interval supplied to `paimon_vector_search_builder_with_row_range` intersects

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Document the scalar fallback for scored searches. Without a usable scalar index, the range restricts the ANN candidates first, then the predicate filters the candidate shortlist. A selective predicate can leave fewer than K hits even when more matching rows exist in-range, as the SQL guide already describes. Please also state that execute_scored requires global row IDs. It errors for primary-key results, whose positions are file-local.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose scored vector search over an inclusive global row-ID range

2 participants