Apache 2.099 KBpip install

governed-rank Governed Reranking for Any Domain

Steer ranked lists toward policy objectives without breaking accuracy — orthogonalize, protect, project.

0.77→0.92

Fairness (COMPAS)

AIR improvement passing the 4/5ths rule

10x

Fraud Triage

Value captured in BLOCK tier vs base model

100%

RAG Safety

Injected docs removed from top-10

99 KB

Package

Minimal dependencies, Apache 2.0

01 Introduction

Every system that serves a ranked list faces the same tension: the base ranker optimizes for one objective, but the business has policy objectives too — reduce toxicity, increase fairness, triage high-value fraud, ensure RAG safety.

The naive approach is to add a policy signal to the base score. This degrades accuracy because policy signals correlate with base scores, creating interference that amplifies existing biases instead of correcting them.

governed-rank solves this. It steers any ranked list toward any policy objective without breaking the base ranker's accuracy. Three steps: orthogonalize the policy signal, protect confident decisions, project to the optimal constrained ranking. Every decision is auditable with per-item receipts.

99 KB. Minimal dependencies. Apache 2.0.

02 Why Naive Policy Injection Fails

The Ranked List Problem

Every ranked list — search results, product recommendations, content feeds, review queues — is optimized for a single objective. But organizations have multiple objectives:

  • Content platforms: Maximize relevance and reduce toxicity
  • Hiring/lending: Maximize quality and ensure demographic fairness
  • Fraud teams: Maximize fraud detection and prioritize high-value cases
  • RAG systems: Maximize retrieval similarity and block prompt injection

What Goes Wrong

The standard approach: add a weighted policy score to the base score.

final_score = base_score + λ * policy_score

This fails because policy signals are often correlated with the base score. When you add a correlated signal, you don't steer — you amplify. Items that were already ranked high get ranked higher. Items that need to move don't move.

In the COMPAS fairness tutorial, naive injection produces unpredictable ordering changes — some protected-group candidates move up, others move down, with no principled control. The adverse impact ratio barely improves.

The Missing Primitive

What's needed is a reranking primitive that:

  1. Removes interference between the policy signal and the base score
  2. Protects the base ranker's most confident decisions
  3. Solves for the maximum policy effect within those constraints
  4. Produces an auditable receipt for every item

governed-rank provides this primitive. It works with any base ranker, any policy signal, any item type. 3 arguments, 1 function call.

03 Three-Step Algorithm: Orthogonalize, Protect, Project

governed-rank implements a three-step pipeline that runs in O(N log N) time:

Base Scores + Steering Scores + Budget
         |
    [1. Orthogonalize]  →  Remove interference between steering and base
         |
    [2. Protect Edges]  →  Lock the base ranker's most confident decisions
         |
    [3. Project]        →  Constrained isotonic regression for final ranking
         |
    Reranked List + Per-Item Receipts

Step 1: Orthogonalization

The steering signal often correlates with base scores. Orthogonalization removes this correlation by projecting the steering vector into the null space of the base score direction.

u_perp = u - (u · s / s · s) * s

After orthogonalization, the steering signal can only move items in directions that the base ranker doesn't have an opinion about. It literally cannot hurt accuracy on the dimensions where the base ranker is confident.

Step 2: Budget-Controlled Edge Protection

The budget parameter (0.0 to 1.0) controls how much of the base ordering is protected. At budget=0.3, the 30% of adjacent-pair ordering decisions where the base ranker has the largest score gaps are locked.

These protected edges become hard constraints. No amount of steering can reverse them. This gives the base ranker team a single knob that controls risk.

Step 3: Constrained Isotonic Projection

The final step solves a constrained optimization: maximize the policy effect (from the orthogonalized steering signal) subject to the protected ordering constraints.

This uses the Pool Adjacent Violators (PAV) algorithm — the same algorithm used in probability calibration, adapted here for ranking with constraints.

The result is Pareto-optimal: you cannot improve policy compliance without worsening accuracy. This is a mathematical guarantee, not an empirical claim.

The govern() API

from mosaic import govern

result = govern(
    base_scores={"doc1": 0.9, "doc2": 0.8, "doc3": 0.7},
    steering_scores={"doc1": -0.5, "doc2": 0.3, "doc3": 0.8},
    budget=0.3,
)

result.ranked_items   # reranked order
result.receipts       # per-item audit trail

Three arguments. One function call. Runs on any ranked list.

04 Validated Across Domains

Tutorial Results

Each domain tutorial walks through a complete notebook with real data, showing governed-rank solving an actual steering problem.

Content Moderation

Toxic content is engaging — outrage drives clicks. Naive toxicity penalties kill engagement. The content moderation tutorial shows governed-rank demoting toxic content in the top-10 while preserving ranking quality through orthogonalization.

Fraud Detection

A fraud model ranks transactions by P(fraud), but a $50K wire transfer matters more than a $5 candy purchase. The fraud tutorial builds a tiered gating system (BLOCK / REVIEW / ALLOW) that captures 10x the fraud value in the BLOCK tier compared to the base model.

Fairness (COMPAS)

The COMPAS recidivism dataset is the canonical example of algorithmic bias. The fairness tutorial steers the risk ranking toward demographic parity, improving the adverse impact ratio from ~0.77 to ~0.92 — passing the 4/5ths rule — while preserving ranking quality.

RAG Safety

RAG pipelines retrieve documents by similarity, but adversarial prompt injections score high on similarity too. The RAG safety tutorial uses governed-rank to block all injected documents from the top-10 while retaining 65% of retrieval quality.

Objective Discovery

Before deploying any policy, you need to know which objectives actually help. The objective discovery tutorial evaluates 7 candidate policies via preference lift analysis, finding that quality_depth is the only policy with both high preference lift and diversity gain.

Key Insight

Across all tutorials, governed-rank maintains base ranker accuracy while steering toward the policy objective. The budget knob provides a single, interpretable control for trading off accuracy vs. policy compliance.

05 Architecture: The govern() Pipeline

The govern() Entry Point

For any domain where you have base scores and a policy signal:

from mosaic import govern

result = govern(
    base_scores=your_base_scores,
    steering_scores=your_policy_signal,
    budget=0.3,
)

Three arguments. Returns a reranked list with per-item receipts. No configuration objects, no calibration step, no training.

Core Modules

ModulePurpose
mosaic.governEntry point — orthogonalize, protect, project
mosaic.orthogonalizationScore-space interference removal
mosaic.gap_calibrationGap to confidence mapping, edge protection
mosaic.isotonic_projectionConstrained isotonic regression (PAV)

Why O(N log N)

The entire pipeline runs in O(N log N) time:

  • Sorting: O(N log N)
  • Orthogonalization: O(N) — single dot product and vector subtraction
  • Edge protection: O(N) — one pass over sorted gaps
  • Isotonic projection: O(N) — PAV algorithm is linear
  • Total: O(N log N), dominated by the initial sort

For a typical reranking of 100–1000 items, this runs in sub-millisecond time.

06 Getting Started

Install

pip install governed-rank

99 KB. Minimal dependencies — NumPy core, scikit-learn optional. Python 3.9+.

Quick Start

from mosaic import govern

result = govern(
    base_scores={"doc1": 0.9, "doc2": 0.8, "doc3": 0.7, "doc4": 0.6, "doc5": 0.5},
    steering_scores={"doc1": -0.5, "doc2": 0.3, "doc3": 0.8, "doc4": 0.1, "doc5": 0.6},
    budget=0.3,
)

print(result.ranked_items)   # reranked order
print(result.receipts)       # per-item audit trail

Tutorials

Walk through governed-rank solving real problems with real data:

Resources

  • GitHub: github.com/rdoku/governed-rank
  • PyPI: pypi.org/project/governed-rank/
  • License: Apache 2.0
  • Contact: ronald@haskelabs.com

07 Conclusion

Every ranked list in production faces the same unsolved tension: the base ranker optimizes for one thing, but the business needs to steer toward multiple objectives — fairness, safety, fraud triage, content moderation, RAG safety.

governed-rank provides the missing primitive. Three steps — orthogonalize, protect, project — that turn any base ranker into a governed ranker. The result is Pareto-optimal: maximum policy effect for any given accuracy budget.

This is demonstrated across 5 domain tutorials:

  • Fairness: AIR improves from ~0.77 to ~0.92 on COMPAS, passing the 4/5ths rule
  • Fraud: 10x fraud value captured in BLOCK tier vs base model
  • RAG Safety: All injected docs removed from top-10 with 65% quality retained
  • Content Moderation: Toxicity drops in top-10 while ranking quality preserved
  • Objective Discovery: Identifies the only policy with both high lift and diversity gain

99 KB. Minimal dependencies. Apache 2.0. Every decision auditable with per-item receipts.

If you serve ranked lists to users and have policy objectives beyond relevance, governed-rank is the governance layer your pipeline is missing.

The missing governance layer for ranked lists

governed-rank steers any ranked list — search results, recommendations, content feeds — toward policy objectives without breaking the base ranker's accuracy. Three steps: orthogonalize, protect, project. 99 KB, minimal dependencies, Apache 2.0.

Projects & Research — Haske Labs