feat(rerank): observe max_chars_per_doc truncation via operation metrics - #3001
Open
chethanuk wants to merge 2 commits into
Open
feat(rerank): observe max_chars_per_doc truncation via operation metrics#3001chethanuk wants to merge 2 commits into
chethanuk wants to merge 2 commits into
Conversation
chethanuk
force-pushed
the
feat/2880-rerank-truncation-counter
branch
from
July 4, 2026 02:56
15d4f82 to
603a53c
Compare
Contributor
Author
|
Please review cc: @qin-ctx @ZaynJarvis @zhoujh01 @yufeng201 @chenjw - Please let me know if you require any changes, or if the project is currently accepting contributions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to the
max_chars_per_doccap (#2880). A too-tight cap silently reshapes reranker input; this PR makes it visible in production.When the cap actually shortens documents inside
_rerank_scores, the retriever emits two operation-scoped telemetry counters —rerank.docs_truncated(documents shortened) andrerank.chars_trimmed(characters removed) — which flow through the existing operation-telemetry summary into the Prometheus bridge, mirroring the existingvector.*counters exactly.How it works
flowchart LR A["_rerank_scores (cap > 0)"] --> B["_record_truncation(documents, cap)"] B -- "only if docs_truncated > 0" --> C["telemetry.count(<br/>rerank.docs_truncated,<br/>rerank.chars_trimmed)"] C --> D["operation telemetry summary<br/>(new rerank section)"] D --> E["Prometheus bridge<br/>curated allowlist, emits when value > 0"] E --> F["openviking_rerank_docs_truncated_total<br/>openviking_rerank_chars_trimmed_total"] F --> G["PromQL: series ABSENT when nothing truncated<br/>coalesce with '... or vector(0)'"]Notes
0) or an untriggered cap stays silent (no metric noise). Because the bridge emits only whenvalue > 0, an untruncated run leaves the series absent (not0) — documented, with theor vector(0)PromQL idiom for alerts.get_current_telemetry()returns a disabled no-op collector whosecount()is guarded.openviking_rerank_*metrics (which useaccount_id/provider/model_namelabels) — no name/registration collision.Tests / docs
Wired end-to-end with coverage at each hop: retriever counters (emit / silent-when-disabled / silent-when-untriggered / sum-across-docs), counter→summary mapping, and the Prometheus bridge render. Metrics-doc rows added (
docs/en|zh/concepts/12-metrics.md). Unit suite green;ruffclean.Review
Four inline review-bot comments triaged and independently verified. Valid ones fixed (metrics docs corrected to "emitted only on truncation; series absent, not
0" + PromQL note; docstring corrected to name both counters);cap or 0and a micro-optimization "duplicate scan" declined with rationale (the field is neverNone; the extra pass over ~20 short abstracts is negligible and the readable split is preferable). No production logic changed.