Skip to content

feat(core): batch exact semantic queries - #53

Merged
seonghobae merged 2 commits into
docs/product-technical-gap-baselinefrom
codex/exact-index-batch
Aug 31, 2026
Merged

feat(core): batch exact semantic queries#53
seonghobae merged 2 commits into
docs/product-technical-gap-baselinefrom
codex/exact-index-batch

Conversation

@seonghobae

@seonghobae seonghobae commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • rank multiple ordered queries against one identical packed authorization with one exact matrix traversal
  • preserve per-query scores, ordering, input digests, and output digests exactly; eliminate only bit-identical query common subexpressions within the batch lifetime
  • retain a reproducible Accelerate f64 profile and keep it unavailable because 13,007/26,312 dot products fail bitwise parity
  • repair the current stacked-base Ruff line-length failure

Validation

  • cargo +1.97.1 fmt --all -- --check
  • cargo +1.97.1 clippy --workspace --all-targets -- -D warnings
  • cargo +1.97.1 llvm-cov --package rankweave-core --fail-under-lines 100 --fail-under-functions 100 --fail-under-regions 100 (100% line/function/region)
  • uvx uv@0.12.1 run --frozen python -m ruff check .
  • uvx uv@0.12.1 run --frozen python -m coverage run -m pytest -q (692 passed)
  • real 6,578 x 3,072 owner benchmark: four identical queries batch p95 11.900 ms with exact report parity; four distinct queries remain above 20 ms
  • Accelerate dgemm benchmark: 3.291-3.584 ms, stable synthetic top-4, but bitwise parity failed; backend remains unavailable

Boundary

This is an exact owner prerequisite, not LineageWeave ADR 0272 or authenticated k6 acceptance. No approximate backend, threshold change, cache, or worker-count policy is introduced.

Signed-off-by: Seongho Bae seonghobae@users.noreply.github.com


Devin Review

Signed-off-by: Seongho Bae <me@seonghobae.me>
@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a7f7b516-183e-436b-8354-46ac03440d46

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Devin Review found 4 potential issues.

Devin Review

Comment on lines 329 to 330
if authorized_candidate_ids.is_empty() {
return Err(SemanticIndexError::EmptyAuthorization);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Single-query error precedence changes

When both inputs are invalid, rank_authorized_batch_refs validates authorization first. Existing single-query calls now return a different stable error code.

Prompt for agents
Restore the existing single-query validation precedence in crates/rankweave-core/src/semantic_index.rs. Before this change, rank_authorized and rank_authorized_packed validated model, then query dimension/finiteness/norm, then authorization contents. Their delegation through rank_authorized_batch_refs now validates authorization before the query. Refactor validation or delegation so the stable single-query APIs preserve their prior error codes while the new batch API retains clearly defined validation semantics. Add regression tests where both the query and authorization are invalid.
Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +55 to +56
An additive packed batch operation accepts two or more ordered query vectors
against one identical packed authorization buffer and immutable snapshot. It

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔍 Batch minimum is ambiguous

The ADR requires two or more queries, while rank_authorized_batch_packed accepts one. Align validation and documentation on the public contract.

Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +383 to +425
let best_by_query = authorized_indices
.par_iter()
.fold(
|| (vec![0.0; query_count], empty_best_maps(query_count)),
|(mut dots, mut best_by_query), index| {
dots.fill(0.0);
let start = index * dimension;
for coordinate in 0..dimension {
let candidate_value = self.normalized_vectors[start + coordinate];
let query_start = coordinate * query_count;
for (dot, query_value) in dots.iter_mut().zip(
&normalized_queries_by_coordinate
[query_start..query_start + query_count],
) {
*dot += query_value * candidate_value;
}
}
let (item_id, unit_id) = &self.candidate_ids[*index];
for (query_index, query) in unique_queries.iter().enumerate() {
let score = (dots[query_index] / (query.norm * self.vector_norms[*index]))
.clamp(0.0, 1.0);
retain_best_unit(&mut best_by_query[query_index], item_id, unit_id, score);
}
(dots, best_by_query)
},
)
.map(|(_, best_by_query)| best_by_query)
.reduce(
|| empty_best_maps(query_count),
|mut left, right| {
for (left_query, right_query) in left.iter_mut().zip(right) {
for result in right_query.into_values() {
retain_best_unit(
left_query,
&result.item_id,
&result.winning_unit_id,
result.score,
);
}
}
left
},
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📝 Info: Dot-product parity is preserved

Each dot product retains coordinate order and operand order. Rayon partitions candidates only, then combines completed item maxima without parallel floating-point summation.

Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +427 to +442
let unique_reports = unique_query_indices
.iter()
.zip(best_by_query)
.map(|(query_index, best_by_item)| {
self.finish_query_report(
&model_digest,
query_vectors[*query_index],
authorized_candidate_ids,
best_by_item,
)
})
.collect::<Vec<_>>();
Ok(original_to_unique
.into_iter()
.map(|unique_index| unique_reports[unique_index].clone())
.collect())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📝 Info: Duplicate evidence remains exact

Bit-identical queries share scoring only. finish_query_report builds evidence from the original bits before duplicates clone the equivalent report.

Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Signed-off-by: Seongho Bae <seonghobae@users.noreply.github.com>
@seonghobae
seonghobae merged commit 47b0dfb into docs/product-technical-gap-baseline Aug 31, 2026
7 of 8 checks passed
@seonghobae
seonghobae deleted the codex/exact-index-batch branch August 31, 2026 11:43
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.

1 participant