Coordinate independent search sources, preserve each source's access checks, and merge evidence without pretending their scores share a scale.
Federated retrieval: search multiple stores without losing policy or time budgets
Keep source ownership explicit
Federated retrieval sends a query to more than one store: perhaps a policy index, a ticket database and a table catalog. Each adapter must enforce the caller's authorization under that store's rules, and the coordinator must not infer that permission in one store grants access in another. Return source ID, passage ID, revision, eligibility and match route with every hit. Corpus access belongs at the source boundary as well as the final response boundary.
Budget each leg
Give the whole request a deadline and each source a smaller timeout. A slow table catalog should not stall a simple policy answer until the client disconnects. Cancel or ignore work after the deadline, and mark the result as partial. Partial results can support an answer only if all required evidence slots are covered; a missing source may require a clear abstention. The timeout policy should be visible in retrieval traces so a missing document is not mistaken for a ranking failure.
Merge identities, not raw scores
A cosine score of 0.79 and a lexical score of 11.4 are not comparable magnitudes. Deduplicate by stable source-and-passage identity, then use per-source rank, calibrated relevance or a judged fusion rule. Record which source returned each duplicate and why a candidate survived. Rank fusion offers a baseline when adapters expose rankings but not aligned probabilities. Keep source diversity when the answer needs both a ticket and a policy.
Handle source-specific freshness
One source may have a fresh transaction row while another holds yesterday's indexed document. Store source revision and observed-at time on every hit; do not present their join as a single current snapshot unless the application defines consistency semantics. For a question about historical eligibility, apply the requested as-of time to each adapter. If one store cannot answer as-of queries, say which part is unavailable rather than silently reading its current state.
Test partial and contradictory outcomes
Run evaluations where every source succeeds, one times out, a source returns forbidden hits, two stores disagree on a revision, and one store returns an exact ID absent elsewhere. Measure required-evidence coverage, p95 latency and per-source failure rates. A high overall recall score does not excuse a coordinator that leaks a restricted hit or hides a missing source behind a confident answer.
Worked contract
from dataclasses import dataclass
@dataclass(frozen=True)
class SearchHit:
source: str
passage_id: str
tenant: str
rank: int
text: str
def merge_hits(source_hits: dict[str, list[SearchHit]], tenant: str,
per_source_cap: int = 3) -> list[SearchHit]:
eligible = []
for source, hits in source_hits.items():
ranked = sorted((hit for hit in hits if hit.source == source
and hit.tenant == tenant), key=lambda hit: hit.rank)
eligible.extend(ranked[:per_source_cap])
seen: set[tuple[str, str]] = set()
merged = []
for hit in sorted(eligible, key=lambda item: (item.rank, item.source)):
identity = (hit.source, hit.passage_id)
if identity not in seen:
seen.add(identity)
merged.append(hit)
return merged
results = {"policy": [SearchHit("policy", "refund-r4", "north", 1, "47 days"),
SearchHit("policy", "refund-r4", "north", 2, "duplicate")],
"tickets": [SearchHit("tickets", "case-83", "south", 1, "private"),
SearchHit("tickets", "case-47", "north", 2, "eligible")]}
assert [(hit.source, hit.passage_id) for hit in merge_hits(results, "north")] == [
("policy", "refund-r4"), ("tickets", "case-47")]
assert all(hit.tenant == "north" for hit in merge_hits(results, "north"))Performance and operating cost
For N returned hits, filtering and sorting costs O(N log N) time and O(N) space. Concurrent source calls can lower wall time toward the slowest successful leg, but only with explicit deadlines and a shared request budget. This example does not execute network calls or enforce source authorization; production adapters must perform their own checks before returning candidates.
Common Mistakes
- Sorting raw scores from unrelated retrieval engines as if they were calibrated.
- Letting a single slow adapter consume the entire request deadline.
- Assuming an aggregator-side filter replaces authorization in each source.
- Answering as though all stores were current when their revisions differ.
Validation drill
Federate three mocked stores over 38 judged questions. Inject timeouts, duplicate hits, stale revisions and cross-tenant decoys; count partial results and unsupported final answers independently.
Read next
- Hybrid retrieval: fuse exact terms and semantic candidates by rank
- Retrieval caches and conversation turns: recheck access every time
- Retrieval traces: locate the stage that lost the answer
- Retrieval evaluation labels: build a trustworthy judged set
