Short answer: cap retrieval in stages, then spend a fixed evidence budget on source-diverse chunks that the answer can cite. For a healthtech news monitoring service, a large top-k is a weak safety net: it can crowd the context with repeated coverage of one announcement while the original advisory never reaches the model. The useful limit is therefore not one number. It is a small contract covering input size, candidate recall, document diversity, final evidence size, and concurrent work.
This experiment note uses grounding as the constraint. A run succeeds only when an alert's claims can point back to the exact indexed chunks that support them; fluent text without that link is a failed run. The first version can still ship quickly, but its limits need to be visible and testable from day one.
How should a news monitoring service enforce retrieval query limits?
Put limits at each place where work or evidence can expand. Reject an oversized request before embedding it, bound the vector search candidate pool, collapse duplicate chunks by document, restrict how much one publisher can occupy, and stop adding evidence when the context budget is full. Those controls answer different failure modes, so a single topK = 50 knob can't replace them.
A practical starting policy might allow a 512-character search query, recall 40 chunks, retain at most 12 documents, keep no more than 3 documents from one publisher, and admit 12,000 characters of evidence. These are starting values for an experiment, not universal thresholds. Change them from evaluation results and the target model's tokenizer, not from intuition. The uncertain variable is almost always corpus shape: a wire-service story copied across 30 outlets behaves differently from 30 independently reported clinical trial updates.
| Boundary | What it prevents | What to record |
|---|---|---|
| Query length | Unbounded embedding and parsing work | Rejected length and tenant |
| Candidate count | Wide vector scans and reranker growth | Requested and returned candidates |
| Documents per publisher | One syndicated narrative filling the evidence | Publisher distribution |
| Evidence budget | Context growth after chunk assembly | Admitted and dropped characters |
| In-flight searches | Bursts multiplying every earlier cost | Queue time and active count |
Return a clear client error for an invalid query and a retryable response for a concurrency limit. Don't silently truncate the user's query. Silent truncation changes meaning, which is especially risky when a drug name, trial identifier, or negation sits at the end.
Meaning comes first.
Small limits compound.
The simple top-k approach fails at the document boundary
Vector indexes rank chunks, but citations usually name documents. That mismatch matters when a 2,400-word regulatory notice produces many neighboring chunks with nearly identical embeddings. A plain nearest-neighbor request can return eight passages from that notice, three rewrites of the same press release, and no independent source. Increasing top-k may find the missing source, but it also enlarges reranking work and the prompt. The result looks rich while its evidence is narrow.
The correction is to treat retrieval as a funnel. First retrieve a bounded candidate set. Then deduplicate on a stable document key, apply source and time constraints, and assemble evidence under a separate budget. Keep chunk identifiers through every step. The generator should receive only text that has a citation handle; generated claims that cannot resolve to one of those handles should not be published as grounded alert copy. This follows the core RAG separation between generated output and retrieved non-parametric evidence, while adding application-level rules for a noisy news corpus.
Chunking belongs in the same contract. Store the canonical article ID, publisher, publication timestamp, normalized URL, chunk ordinal, and text span with every vector. Overlap may help preserve a sentence crossing a boundary, but overlap also creates near-duplicates. Deduplicate at the document level before choosing the final spans, then prefer the smallest set that covers the alert topic. More chunks aren't automatically more grounding.
There is a catch: aggressive publisher diversity is not suitable when one primary authority is the only valid source, such as a newly posted safety notice. In that case, allow several chunks from the primary document and label the alert as single-source. Keep a stricter diversity rule for broad trend summaries. One global policy would hide this distinction.
A focused TypeScript evidence-budget example
The following selector assumes the vector index has already returned candidates in score order. It does no network work and makes no vendor assumptions. Its job is deliberately narrow: choose citeable chunks without exceeding document, publisher, or evidence limits.
type Candidate = {
chunkId: string;
documentId: string;
publisher: string;
publishedAt: string;
text: string;
score: number;
};
type RetrievalLimits = {
maxDocuments: number;
maxDocumentsPerPublisher: number;
maxEvidenceChars: number;
};
type Evidence = Candidate & { citation: string };
function selectEvidence(
candidates: Candidate[],
limits: RetrievalLimits,
): Evidence[] {
const selected: Evidence[] = [];
const seenDocuments = new Set<string>();
const publisherCounts = new Map<string, number>();
let evidenceChars = 0;
for (const candidate of candidates) {
if (seenDocuments.has(candidate.documentId)) continue;
const publisherCount = publisherCounts.get(candidate.publisher) ?? 0;
if (publisherCount >= limits.maxDocumentsPerPublisher) continue;
if (evidenceChars + candidate.text.length > limits.maxEvidenceChars) continue;
selected.push({
...candidate,
citation: `doc:${candidate.documentId}#chunk:${candidate.chunkId}`,
});
seenDocuments.add(candidate.documentId);
publisherCounts.set(candidate.publisher, publisherCount + 1);
evidenceChars += candidate.text.length;
if (seenDocuments.size >= limits.maxDocuments) break;
}
return selected;
}
const evidence = selectEvidence(vectorCandidates.slice(0, 40), {
maxDocuments: 12,
maxDocumentsPerPublisher: 3,
maxEvidenceChars: 12_000,
});
This is intentionally greedy. It is easy to inspect and cheap to run, which is useful for a solo team shipping the first evaluation loop. It does not guarantee the globally best mix of passages, and it can underfill the budget when an early high-scoring chunk is long. Stick with a more expensive reranker or an optimization step when cross-source coverage is a hard requirement and the evaluation set shows the greedy choice missing essential evidence.
Also, character count is only an admission proxy. The model consumes tokens, and tokenization varies with content and model. Measure the final serialized prompt with the actual tokenizer before the generation call. The character ceiling remains useful earlier in the pipeline because it prevents obviously large evidence sets from flowing through every later stage.
Keep it boring.
Measure citation quality before raising any cap
Build the evaluation set from the alerts the service must handle: a primary safety notice, syndicated copies, an ambiguous product name, a correction published after the original story, and a topic with no relevant result. For each case, record the expected source documents and the exact claims they support. Then replay the set whenever chunk size, embedding model, filter logic, or a limit changes.
The main retrieval measures should separate discovery from grounding. Candidate recall asks whether an expected document appeared before selection. Evidence recall asks whether it survived deduplication and budgeting. Citation precision asks whether each attached chunk actually supports the claim beside it. Also track the share of evidence from the largest publisher, empty-result rate, evidence characters, end-to-end latency, and work rejected by the concurrency guard. A high candidate recall with weak citation precision is not a win; it means the funnel found relevant material but assembled it badly.
Use a sweep rather than one benchmark. Run candidate caps such as 10, 20, 40, and 80 against the same frozen cases, then plot citation quality against latency and evidence size. Stop increasing the cap when the quality curve flattens or the extra candidates are mostly duplicates. No percentage or threshold transfers cleanly between corpora, so I'm not sure any published default should be copied without this sweep. The corpus, update cadence, and definition of a supportable claim would resolve that uncertainty.
Deployment needs two separate controls. A per-request limit bounds one search; a tenant-aware concurrency gate prevents a burst of saved-topic alerts from multiplying that work. Queue scheduled searches, attach the policy version to every trace, and log why each candidate was dropped. That last field turns a vague missing-citation report into something actionable: excluded as duplicate, publisher cap reached, outside the time window, or evidence budget exhausted.
Do not raise limits to cover stale ingestion. If the primary notice never reached the vector index, a wider query only spends more work searching incomplete data. Monitor ingestion lag, chunk counts per document, and index-write failures independently from retrieval. The decision rule is blunt: raise a query limit only when the expected document exists in the index, appears just beyond the current boundary, and improves citation evaluation after admission. Otherwise fix ranking, metadata, chunking, or ingestion instead.
No cap repairs missing data.
Before copying this design, measure three things in your own service: how often the expected primary document enters the initial candidate pool, how often source caps remove useful evidence, and how much the final citation pack contributes to latency. Those observations tell you which boundary is protecting the system and which one is merely cutting recall.
Top comments (0)