r/Rag • u/Kendall-Kaiser95 • 10d ago
Discussion do you cap how many chunks a rag system pulls from one doc?
say you retrieve 5 chunks and 4 come from the same guide. two of them basically say the same thing and the question still needs one detail from a different doc
would you cap it at 2 chunks per doc or pull more candidates and rerank them? curious if anyone tried a cap and found it dropped useful context on questions where most of the answer really was in one doc
3
Upvotes
2
u/Alternative_Pin9598 10d ago
Pull more and rerank, but I wouldn't hard-cap. Your example mixes two problems: redundancy (two chunks saying the same thing) and coverage (the one detail from another doc never makes the cut). A per-doc cap treats both as "too many chunks from one doc", and yes, it drops useful context when the answer really is spread across one long guide. Handle them separately:
1. Over-retrieve, then rerank. Pull 30–50 candidates (hybrid if you have it), rerank all of them, and only then choose what goes into the prompt.
2. Drop near-duplicates. Skip a chunk that's very similar to one you've already kept. Embedding cosine above ~0.95 is a reasonable starting threshold (check a few pairs by hand), and with sliding-window chunking, overlapping spans count as duplicates. That alone fixes "two say the same thing" without touching doc counts.
3. Select with MMR instead of a cap. Maximal marginal relevance picks each next chunk by
score = λ * relevance - (1 - λ) * max_similarity_to_selected. Normalize the reranker scores to 0–1 first and start around λ = 0.7. A dominant doc still gets several chunks if each adds something new, while a repeat gets pushed down, which frees a slot for the other doc.4. If you want a doc limit, make it soft. A doc's third chunk only gets in if its reranker score beats the best remaining chunk from any other doc by some margin. Single-doc questions keep their context, and the outside detail gets in when it's competitive.
5. Merge neighbours. Adjacent chunks from the same doc become one span (or expand to the parent section), so "four chunks from one guide" turns into one coherent passage. Budget by tokens rather than chunk count.
If the missing detail answers a different part of the question, no selection rule will reliably rescue it. Split the question into sub-queries, retrieve for each, then merge.
To answer your cap question with data: tag your eval questions as single-doc or multi-doc by where the gold evidence lives. Then measure evidence recall (did every gold chunk make it into the final context?) for no cap, cap = 2, dedupe + MMR, and the soft quota. The usual pattern is that a hard cap helps multi-doc questions and hurts single-doc ones, and dedupe + MMR gets most of both. Compare the two groups separately, because the average hides exactly that trade-off.
1
u/SystemicGrowth 10d ago
J'ai essayé, ça ne me convient pas.
Ma bibliothèque contient principalement des livres de psychologie et philosophie. Selon les questions, le nombre de reponses par livre est trés différent. J'ai une première couche qui renvoie beaucoup de données, avec souvent les paragraphes adjacents pour plus de contexte, la selection se fait plus finement au reranking.
La limite réelle porte sur la taille des données transmises au llm. Je prefère des reponses tres construites, avec un maximum d'élements, et pas de contrainte de temps de réponse, donc cette limite est surtout fonction de la taille de contexte.
Il est très facile pour mon rag de distinguer les livres pertinents des livres impertinents, et mes livres sont assez spécialisés, par conséquent il y a assez peu de bruit.
1
u/Senior-Assumption864 10d ago
i would pull more candidates and rerank, a hard cap feels risky when most of the answer really lives in one doc
1
u/Vegetable_Anxiety650 10d ago
A hard 2-chunk cap could easily cut off useful context. Better to rerank a larger set and remove overlapping chunks before deciding what to keep.
1
u/the-solo-dev-il 9d ago
agree with the rerank answers, but two things you can do that sit between "no cap" and a hard cap:
diversity-aware selection instead of a cap. mmr (maximal marginal relevance) picks each next chunk by relevance minus similarity to what's already picked. so the second near-duplicate from the same guide gets pushed down, but a third chunk from that guide that adds new info still makes it in. it handles your exact case (two chunks saying the same thing) without punishing docs that really do hold most of the answer. most vector dbs and frameworks have it built in.
merge before you count. if 3 of your 5 chunks are adjacent sections of one guide, stitch them into one passage. now it's 1 slot instead of 3, and you free up room for the detail from the other doc. it also reads better for the model than three fragments.
and if the missing detail keeps losing, that's usually a recall problem, not a selection problem. the other doc never scores high enough because the query is really two questions. splitting the query (or generating a couple of sub-queries) and retrieving for each fixes that better than any cap.
whatever you pick, test it on a small set of questions where you know which docs the answer needs. check how often every required doc makes the final context. that number tells you right away if a cap is dropping useful stuff.
1
u/white-9igga 6d ago
the ordering matters more than the cap. retrieve wide, like 40-50 candidates, rerank, and only then apply any per-doc limit or dedupe. capping at retrieval cuts candidates before the reranker sees them, so you lose diversity and relevance at once.
for the two-chunks-say-the-same-thing case, dedupe on content overlap instead of doc id: if two chunks share most of their text, drop the weaker one wherever it came from. that fixes redundancy without hurting coverage, and it also catches the same paragraph copy-pasted across docs. the one-detail-in-another-doc problem is fixed by the wide pool plus rerank, a hard 2-per-doc cap just hurts the questions where the answer really is in one doc.
1
u/AlexAtOracleAIDB 3d ago
My pick would be pulling more candidates and reranking them rather than setting a hard two-per-doc cap. When two chunks from the same guide say the same thing, dropping near-duplicates, even if they score well, frees a slot for a detail from another doc.
Chunks from different docs tend to matter most when the question compares two sources, and a hard cap can cut chunks you need when most of the answer is in one guide.