Describe the bug
Cross-partition hybrid search queries (ORDER BY RANK RRF(VectorDistance(...), FullTextScore(...))) intermittently throw IndexOutOfBoundsException at HybridSearchDocumentQueryExecutionContext.lambda$computeRRFScores$3, e.g.:
java.lang.IndexOutOfBoundsException: Index 363 out of bounds for length 363
at java.util.ArrayList.get(ArrayList.java:428)
at com.azure.cosmos.implementation.query.HybridSearchDocumentQueryExecutionContext.lambda$computeRRFScores$3(HybridSearchDocumentQueryExecutionContext.java:343)
This is distinct from #46267 (already fixed via CosmosFullTextScoreScope) — it still reproduces with CosmosFullTextScoreScope.LOCAL set, and is unrelated to full-text statistics scope.
Root cause
In hybridSearch(...), coalescedAndSortedResults (a Mono<List<HybridSearchQueryResult<Document>>>) is built once but subscribed to twice independently, without .cache():
Mono<List<HybridSearchQueryResult<Document>>> coalescedAndSortedResults = coalesceAndSortResults(componentQueryResults);
Mono<List<List<ScoreTuple>>> componentScoresList = retrieveComponentScores(coalescedAndSortedResults, componentWeights); // subscription #1
Mono<List<List<Integer>>> ranks = computeRanks(componentScoresList);
return computeRRFScores(ranks, coalescedAndSortedResults, componentWeights) // subscription #2, via zipWith
Since the upstream source merges results across many partitions over real network I/O, each independent subscription re-executes the whole cross-partition merge and can non-deterministically produce a different-sized result list. computeRRFScores then indexes into a ranks list sized from the other subscription, causing the exception. Confirmed still present on main (checked against HybridSearchDocumentQueryExecutionContext.java on the default branch as of 2026-07-15).
Suggested fix
Add .cache() to coalescedAndSortedResults so both consumers observe the same materialized result list:
Mono<List<HybridSearchQueryResult<Document>>> coalescedAndSortedResults = coalesceAndSortResults(componentQueryResults).cache();
To Reproduce
Cross-partition hybrid search with k large enough (empirically ~≥90-100 against our container) to increase the window for the two subscriptions' network timing to diverge. Not reliably reproducible with a small local dataset — occurs intermittently in production against a multi-partition container under normal query load.
Environment
- azure-cosmos 4.80.0
- Java 25
- Spring Boot 4.0.6
Describe the bug
Cross-partition hybrid search queries (
ORDER BY RANK RRF(VectorDistance(...), FullTextScore(...))) intermittently throwIndexOutOfBoundsExceptionatHybridSearchDocumentQueryExecutionContext.lambda$computeRRFScores$3, e.g.:This is distinct from #46267 (already fixed via
CosmosFullTextScoreScope) — it still reproduces withCosmosFullTextScoreScope.LOCALset, and is unrelated to full-text statistics scope.Root cause
In
hybridSearch(...),coalescedAndSortedResults(aMono<List<HybridSearchQueryResult<Document>>>) is built once but subscribed to twice independently, without.cache():Since the upstream source merges results across many partitions over real network I/O, each independent subscription re-executes the whole cross-partition merge and can non-deterministically produce a different-sized result list.
computeRRFScoresthen indexes into arankslist sized from the other subscription, causing the exception. Confirmed still present onmain(checked againstHybridSearchDocumentQueryExecutionContext.javaon the default branch as of 2026-07-15).Suggested fix
Add
.cache()tocoalescedAndSortedResultsso both consumers observe the same materialized result list:To Reproduce
Cross-partition hybrid search with
klarge enough (empirically ~≥90-100 against our container) to increase the window for the two subscriptions' network timing to diverge. Not reliably reproducible with a small local dataset — occurs intermittently in production against a multi-partition container under normal query load.Environment