Skip to content

feat(litellm): instrument rerank and arerank#323

Open
Abhijeet Prasad (AbhiPrasad) wants to merge 1 commit intomainfrom
abhi-feat-266-litellm-rerank-instrumentation
Open

feat(litellm): instrument rerank and arerank#323
Abhijeet Prasad (AbhiPrasad) wants to merge 1 commit intomainfrom
abhi-feat-266-litellm-rerank-instrumentation

Conversation

@AbhiPrasad
Copy link
Copy Markdown
Member

@AbhiPrasad Abhijeet Prasad (AbhiPrasad) commented Apr 17, 2026

Add LiteLLM rerank() / arerank() tracing, following the Cohere integration pattern. Both patch_litellm() (via _ALL_LITELLM_PATCHERS) and wrap_litellm() now produce a "Rerank" LLM span.

Tests are VCR-backed against cohere/rerank-english-v3.0, with cassettes for both the latest and 1.74.0 matrix entries. Adds unit coverage for the metrics-precedence and output-sanitization helpers.

Closes #266

Add LiteLLM `rerank()` / `arerank()` tracing, following the Cohere
integration pattern. Both `patch_litellm()` (via `_ALL_LITELLM_PATCHERS`)
and `wrap_litellm()` now produce a "Rerank" LLM span.

Span shape:
- input: { query, documents }
- metadata: provider=litellm, model, top_n, return_documents, rank_fields,
  custom_llm_provider, plus a derived document_count
- output: [{ index, relevance_score }, \u2026] (document payload dropped,
  same as the Cohere integration)
- metrics: parsed from meta.billed_units and meta.tokens, with
  billed_units winning on conflict; exposes search_units for Cohere-
  backed reranking

Tests are VCR-backed against `cohere/rerank-english-v3.0`, with
cassettes for both the `latest` and `1.74.0` matrix entries. Adds
unit coverage for the metrics-precedence and output-sanitization helpers.

Closes #266
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.

[bot] LiteLLM: rerank() / arerank() not instrumented

1 participant