← Back to Pull requests

feat: expose independent batch nearest search in C and C++ #92

Closed
unknown closed this pull request without merging on Sep 30, 2026 15:12 UTC
View on GitHub
unknown unknown commented on Sep 30, 2026 09:17 UTC
Author

Expose independent batch nearest-neighbor search through lance_scanner_nearest_batch and the C++ Scanner::nearest_batch overloads. A row-major matrix of N vectors produces up to K neighbors per query, identified by a zero-based query_index column, including a batch of one. This provides the binding needed for consumers such as apache/doris#68394.

The existing fixed-size-list query representation also describes multi-vector queries. Track the query mode explicitly so independent batches use Lance's native batch execution instead of the custom multi-vector scoring/window path. Single-vector, multi-vector, and batch queries share input-alignment validation before decoding typed buffers. No dependency changes are needed.

  • Copy and validate input before replacing the configured query. Support Float16/32/64, Int8, and UInt8 (Hamming), require matching column shape/type and finite floating-point values, and reject the reserved query_index dataset column.

  • Distinguish arithmetic overflow from byte-limit rejection, reporting dimension, query count, element width, and the computed size when representable. Unsupported decoded types return an input error.

  • Bound request size and candidate expansion: at most 128 queries, 64 MiB of query values, and num_queries k refine_factor <= 100000 (unset refinement counts as 1). These bounds do not cap total index/payload memory.

  • Share scanner filter, metric, index and tuning options across queries. Reject FTS and global scanner limit/offset in either configuration order; consumers must apply result windows separately per query. Distance ranges remain single-query-only; replacing a single query with a batch clears its bounds.

  • Reuse Arrow stream ownership and cancellation. Native shared scans remain conditional on Lance's execution-plan eligibility; this API makes no speedup guarantee.
  • Validation:

  • cargo test: 469 Rust tests passed.

  • cargo test --test compile_and_run_test -- --ignored: all 3 native consumer tests passed (C, C++, and static OSS transport); batch checks validate per-query ids, distances, counts, and stream ownership.

  • cargo clippy --locked --all-targets -- -D warnings, cargo check --locked --all-targets, formatting, and diff checks passed.

  • All 15 batch integration tests passed, including exact per-query IDs/distances for individually selected IVF_FLAT segments, Int8 L2 queries, and byte-limit diagnostics preserving the previous query.

  • The internal regression first failed on the previous matrix-based mode detection, then passed with explicit query modes. Coverage includes flat/IVF/refined plans, multiple fragments, fragment scope, projection/filtering/empty results, duplicate queries, all supported element types, arithmetic overflow and byte-limit boundaries, input alignment, invalid input preserving state, query replacement, and early stream release.
  • Diff: 360 lines (+270 / -90) across 4 files Reviewer: LuciferYang Review duration: 355m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 360 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.352
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #92"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.6% (MEDIUM) · Higher = larger blast radius
    42.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.8% · Safe to merge
    16.8%