Skip to content

Add retrieval-provider rerank capability (0060a)#205

Merged
chris-colinsky merged 2 commits into
mainfrom
feature/0060a-rerank-capability
Jul 2, 2026
Merged

Add retrieval-provider rerank capability (0060a)#205
chris-colinsky merged 2 commits into
mainfrom
feature/0060a-rerank-capability

Conversation

@chris-colinsky

Copy link
Copy Markdown
Member

Adds the rerank half of the retrieval-provider capability (proposal 0060), as the first of a two-PR split (0060a here, observability rendering in 0060b), mirroring the 0059a/0059b embedding split.

What's here

  • RerankProvider protocol (ready() + rerank(query, documents, *, top_k=None, config=None)), with validate_rerank_input / validate_rerank_response (empty query/documents or top_k <= 0 gives provider_invalid_request; out-of-range/duplicate index or len(results) > top_k gives provider_invalid_response).
  • Response types: RerankResponse / ScoredDocument / RerankUsage / RerankRuntimeConfig. usage is record | null from the start (proposal 0093); no fabricated usage records.
  • Typed RerankEvent / RerankFailedEvent on the observer event union, mirroring the embedding events (scalar fan_out_index / branch_name; output_results populated on success per 0089).
  • CohereRerankProvider, the Cohere-shape reference reranker (POST /v2/rerank): request body {model, query, documents, top_n} (max_tokens_per_doc rides the extras bag; no return_documents, which is a no-op on the Cohere v2 wire), response parse + descending sort + the section 6 invariants.
  • Conformance: the calls_rerank harness directive; protocol fixtures 006-012 un-deferred and passing.
  • conformance.toml 0060 moves to partial.

Deferred to 0060b

The observer rendering (the OTel openarmature.rerank.complete span, the Langfuse Retriever observation, and rerank metrics; fixtures 099-109 / 138 / 141 / 142). The bundled observers safe-skip the rerank events until then. The Cohere /v2/rerank request wire is implemented but live-untested; a live integration test lands with the Cohere wire mapping (0090), as the OpenAI embed test did with 0079.

Validation

  • Protocol fixtures 006-012 pass; full conformance + unit suites green
  • ruff + pyright clean

Add the RerankProvider protocol, the RerankResponse / ScoredDocument /
RerankUsage / RerankRuntimeConfig types, the typed RerankEvent /
RerankFailedEvent, and a Cohere-shape reference reranker
(CohereRerankProvider against POST /v2/rerank), mirroring the embedding
capability (0059). RerankResponse.usage is nullable from the start per
proposal 0093; the reference never fabricates a usage record and does
not send return_documents (a no-op on the Cohere v2 wire).

Wire the conformance harness (the calls_rerank directive) and un-defer
the protocol fixtures 006-012. Observability rendering (the OTel rerank
span and the Langfuse Retriever observation) defers to the 0060b
follow-on; the bundled observers safe-skip the rerank events for now.
conformance.toml 0060 moves to partial.
Copilot AI review requested due to automatic review settings July 2, 2026 17:57
Comment thread src/openarmature/retrieval/provider.py
Comment thread src/openarmature/retrieval/provider.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements the retrieval-provider rerank surface (proposal 0060a) in the Python runtime, including the provider protocol, response/runtime-config types, a Cohere-shaped reference provider, and conformance/unit test coverage. This fits alongside the existing embedding capability by adding rerank call/response normalization, validation, and typed observer events, while deferring observer rendering to a follow-up PR (0060b).

Changes:

  • Add RerankProvider protocol plus validate_rerank_input / validate_rerank_response invariants enforcement.
  • Introduce rerank response/config types (RerankResponse, ScoredDocument, RerankUsage, RerankRuntimeConfig) and the CohereRerankProvider implementation (POST /v2/rerank).
  • Extend conformance harness + tests to run rerank fixtures and to safely skip rerank events in bundled observers until rendering is implemented.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/unit/test_retrieval_provider.py Adds unit coverage for rerank validators, Cohere request/response behavior, and typed rerank event dispatch + observer safe-skip behavior.
tests/conformance/test_retrieval_provider.py Extends conformance runner to execute rerank fixtures (006–012) against CohereRerankProvider and assert rerank invariants/expected state.
tests/conformance/test_observability.py Updates deferral messaging to reflect rerank rendering deferred to 0060b (not the underlying rerank capability/events).
tests/conformance/test_fixture_parsing.py Adjusts parser deferrals now that calls_rerank is modeled; keeps only typed-event-collector-shape deferrals here.
tests/conformance/harness/directives.py Adds CallsRerankSpec and wires it into NodeSpec primary directives.
src/openarmature/retrieval/response.py Adds rerank response/config/usage models and updates module documentation/exports.
src/openarmature/retrieval/providers/cohere.py Introduces the Cohere-shaped reference rerank provider with request mapping, response parsing/sorting, validation, and typed-event dispatch.
src/openarmature/retrieval/provider.py Adds RerankProvider protocol and rerank input/response validators.
src/openarmature/retrieval/init.py Exports rerank protocols/types and CohereRerankProvider from the retrieval package surface.
src/openarmature/observability/otel/observer.py Adds type discrimination to safely skip rerank events until rerank span/metrics rendering lands (0060b).
src/openarmature/observability/langfuse/observer.py Adds type discrimination to safely skip rerank events until Langfuse retriever rendering lands (0060b).
src/openarmature/graph/observer.py Extends ObserverEvent union to include RerankEvent / RerankFailedEvent.
src/openarmature/graph/events.py Adds typed RerankEvent / RerankFailedEvent dataclasses to the observer event model.
conformance.toml Marks proposal 0060 as partial and documents what 0060a ships vs what is deferred to 0060b.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/openarmature/retrieval/providers/cohere.py Outdated
Comment thread src/openarmature/retrieval/response.py Outdated
Two doc-accuracy fixes from the PR #205 review:

- The cohere.py module docstring said ScoredDocument.document is null on
  every result, but the parser passes a document echo through when a
  response carries one (fixture 012 + unit tests). Reword to match.
- The response.py comment said undeclared extras are forwarded to the
  wire untouched, but the mapping reserves model / query / documents /
  top_n. Tighten to note the provider-reserved keys.
@chris-colinsky chris-colinsky merged commit 01f93d3 into main Jul 2, 2026
6 checks passed
@chris-colinsky chris-colinsky deleted the feature/0060a-rerank-capability branch July 2, 2026 18:26
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.

2 participants