[BUG] LLMTrulensScoring breaks equal-score ties by document text rather than retrieval order
Intended recipient: maintainers of Cinnamon/kotaemon.
Description
Before scoring, run sorts by doc.get_content(). The score sort is stable, so equal scores keep that order. Distinct strings therefore come out in lexicographic order, independent of retrieval order; equal content strings retain their incoming relative order.
Version and environment
Checked on 17 November 2026 at commit 9ad3e4e49aa35b8acddd235918a5d9753c1cfdf9 on macOS, Python 3.11.16, using the restored pinned audit dependencies. The target implementation was imported from that checkout without modifying its code. The accompanying kotaemon_trulens_rerank_repro.zip contains the unchanged saved scripts, dependency record and run instructions. All judge responses are local deterministic stubs; no paid model or external inference service was used.
Reproduction steps
- Extract
kotaemon_trulens_rerank_repro.zipand follow itsREADME.mdto connect an existing compatible environment and the checkout at the commit above. - From the extracted lane directory, run
work/venv/bin/python out/repro/repro_order_cut_flag.pywith the source-import environment specified in that README. - Inspect
H4b_tiesin the output.
Observed result
With sequential execution and a deterministic judge giving every item 5/10, input ["echo passage", "charlie passage", "alpha passage"] returns ["alpha passage", "charlie passage", "echo passage"], all with score 0.5. The sequential six-item permutation control produces one fixed output ordering across 720 permutations.
Expected behaviour
Preserve the incoming retrieval order among equal scores, or explicitly document and expose the intended secondary sort. If content sorting is needed for scheduling, retain original indices for the final tie break.
Code and scope
Relevant implementation: libs/kotaemon/kotaemon/indices/rankings/llm_trulens.py:121.
This is a tie-policy/contract issue: alphabetical order is not intrinsically invalid, but it removes upstream ranking information without an explicit score difference. No answer-quality loss is measured. Sequential execution isolates it from the separately reported concurrency race.
Related reports
Issue #876 concerns the concurrent late-binding closure; #858 concerns duplicate retrieval results. Neither is this deterministic equal-score ordering behaviour.
AI assistance was used to inspect the code, run the saved local reproductions and prepare this report. The figures above describe those bounded reproductions, not a measurement of effects on a published leaderboard or production workload.