Add retrieval-provider rerank capability (0060a)#205
Merged
Conversation
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.
There was a problem hiding this comment.
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
RerankProviderprotocol plusvalidate_rerank_input/validate_rerank_responseinvariants enforcement. - Introduce rerank response/config types (
RerankResponse,ScoredDocument,RerankUsage,RerankRuntimeConfig) and theCohereRerankProviderimplementation (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.
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.
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.
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
RerankProviderprotocol (ready()+rerank(query, documents, *, top_k=None, config=None)), withvalidate_rerank_input/validate_rerank_response(empty query/documents ortop_k <= 0givesprovider_invalid_request; out-of-range/duplicate index orlen(results) > top_kgivesprovider_invalid_response).RerankResponse/ScoredDocument/RerankUsage/RerankRuntimeConfig.usageisrecord | nullfrom the start (proposal 0093); no fabricated usage records.RerankEvent/RerankFailedEventon the observer event union, mirroring the embedding events (scalarfan_out_index/branch_name;output_resultspopulated on success per 0089).CohereRerankProvider, the Cohere-shape reference reranker (POST /v2/rerank): request body{model, query, documents, top_n}(max_tokens_per_docrides the extras bag; noreturn_documents, which is a no-op on the Cohere v2 wire), response parse + descending sort + the section 6 invariants.calls_rerankharness directive; protocol fixtures 006-012 un-deferred and passing.conformance.toml0060 moves topartial.Deferred to 0060b
The observer rendering (the OTel
openarmature.rerank.completespan, 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/rerankrequest 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