Skip to content

Multi-shard search: Rust merges#3752

Open
jotare wants to merge 26 commits into
mainfrom
multi-shard-search
Open

Multi-shard search: Rust merges#3752
jotare wants to merge 26 commits into
mainfrom
multi-shard-search

Conversation

@jotare

@jotare jotare commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Description

This is the first part of a series of PRs to improve how internal gRPC search requests are done through the cluster. We currently send 1 gRPC request per shard, but we could instead send 1 per searcher (containing a KB shard).

In this PR, we implement multi-shard requests and shard response merging in Rust, although Python will still request 1 per shard.

The change on the proto is bw/c compatible (see https://protobuf.dev/programming-guides/proto3/#wire-safe-changes). Python sends 1 shard id string as a string/list and nidx parses 1 shard id string as a string/list.

How was this PR tested?

New Rust tests on merging

@jotare jotare requested review from a team as code owners June 22, 2026 15:30
@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.04433% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.97%. Comparing base (d67d324) to head (7f810ce).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
nidx/src/searcher/shard_merge.rs 97.55% 19 Missing ⚠️
nucliadb/src/nucliadb/search/requesters/utils.py 84.00% 4 Missing ⚠️
nucliadb/src/nucliadb/search/search/shards.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3752      +/-   ##
==========================================
- Coverage   85.47%   82.97%   -2.50%     
==========================================
  Files         563      565       +2     
  Lines       48861    49809     +948     
  Branches    14351    15127     +776     
==========================================
- Hits        41763    41330     -433     
- Misses       6463     7846    +1383     
+ Partials      635      633       -2     
Flag Coverage Δ
nucliadb 66.57% <83.33%> (-7.67%) ⬇️
nucliadb-ingest 43.77% <26.66%> (+0.03%) ⬆️
nucliadb-reader 43.77% <26.66%> (-0.02%) ⬇️
nucliadb-search 55.01% <76.66%> (+0.10%) ⬆️
nucliadb-standalone 46.14% <26.66%> (-0.02%) ⬇️
nucliadb-train 44.75% <26.66%> (-0.01%) ⬇️
nucliadb-writer 47.13% <26.66%> (-0.02%) ⬇️
nucliadb_dataset 72.84% <ø> (ø)
nucliadb_models 69.70% <ø> (ø)
nucliadb_telemetry 85.67% <ø> (-0.03%) ⬇️
nucliadb_utils 80.90% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread nidx/src/searcher/grpc.rs Outdated
Comment thread nidx/src/searcher/shard_merge.rs Outdated
Comment thread nidx/src/searcher/shard_merge.rs Outdated
Comment thread nidx/src/searcher/grpc.rs Outdated
LOCAL => shard_search::search(Arc::clone(&self.index_cache), message.clone()).await,
REMOTE => search

if message.shard_ids.len() == 1 {

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.

Maybe this should only be for the merge itself?

like, always iterate all queries and then do an if to run the merge code or just return the first result?

Comment thread nidx/src/searcher/grpc.rs Outdated
// Distributed query across multiple shards
let mut responses = Vec::with_capacity(message.shard_ids.len());

for shard_id in &message.shard_ids {

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.

We probably want to run all task concurrently (with a JoinSet or similar). Otherwise the query time is linear to the number of shards. I think Python already sent all queries in parallel, so this would be a regression.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Next PR. We can merge them and have it all here

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.

2 participants