1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! Mechanics of the bounded parallel fan-out.
//!
//! Owns the index arithmetic that partitions a corpus into chunks, the
//! order-restoring reassembly of out-of-order results, and the generic
//! semaphore-bounded execution engine shared by every batch entry point
//! (GAP-OPENROUTER-REST-CONCURRENCY / GAP-SG-147 / G42/S3).
/// DEFAULT number of texts sent per OpenRouter REST call inside the bounded
/// fan-out, when XDG `embedding.batch_size` supplies nothing.
///
/// Read it through [`fan_out_chunk`], never directly: the operator-facing knob
/// is the XDG key, and this constant is only its fallback.
///
/// Also the unit [`reassemble_ordered`] indexes on: chunk `i` covers
/// `[i * chunk, min((i + 1) * chunk, len))`.
pub const EMBED_FAN_OUT_CHUNK: usize = 32;
/// Effective texts-per-REST-call for the OpenRouter fan-out (GAP-SG-142).
///
/// Deliberately the SAME knob that [`crate::embedding_api::OpenRouterClient`]
/// uses to re-chunk a batch internally. The outer fan-out exists only to feed
/// that inner call, so two independent knobs could be set to values that cancel
/// each other: raising `embedding.batch_size` to 64 while the fan-out still
/// handed over 32 left the inner chunking with nothing to split, and the
/// operator kept 32-text requests with no signal that the setting was inert.
pub
/// Index ranges that partition `len` items into `chunk` sized pieces.
///
/// GAP-SG-147: mirrors `slice::chunks` exactly, but yields ranges instead of
/// borrowed slices so a spawned `'static` task can hold the range and index
/// into a shared [`Arc`] rather than owning a copy of the data.
pub
/// GAP-OPENROUTER-REST-CONCURRENCY: reassembles the flat vector list in
/// input order from chunk parts produced out-of-order by the bounded
/// `JoinSet` fan-out. Sorts by chunk index, then flattens, so the result
/// matches the original `texts` order exactly.
pub