DEV Community

Ayush Singh
Ayush Singh

Posted on

I Made My RAG Safer. It Got Worse Under Load

Free-tier limits and queue times exposed

RAG isn't dead, but unverified RAG should be. Here's what checking every sentence actually cost me on Groq's free tier, and a few other things I learned along the way.

I rebuilt my RAG system so that no sentence reaches the user until it has been checked against the passage it cites. The first sentence started showing up sooner, and nothing unverified was ever shown.

Then I ran it under heavy overload. It delivered 62.8% of requests. The old version delivered 67.4%.

Honestly this one hurt a bit, because my own safety feature was the reason. I will explain it below.
That run also changed how I read the "RAG is dead" posts. Yes, context windows are huge now, and coding agents find things with grep instead of vector databases. But none of that answers the question that actually cost me those requests: who checks the answer?

TL;DR

  • Checking every sentence made answers appear sooner, but under heavy load it cost throughput: 62.8% delivered against 67.4%.
  • When 30 requests came in 2 seconds, the system made only 6 model calls. Same questions share one answer.
  • The cheapest correct answer is a refusal that never calls the model.
  • My slowest request spent 29.2 of its 29.8 seconds just waiting in a queue.
  • A small "is this sentence supported?" judge model would have blocked about 1 in 5 good sentences.

What I built

The Relay answers questions only from three research papers: Attention Is All You Need, Moshi and H-Net. Every sentence must cite the passage it came from. If the papers don't say something, it has to say so instead of guessing. And it has to survive Groq's free tier while requests come in bursts.

The flow is: queue → cache → retrieval (BM25 plus embeddings) → evidence check → model call → per-sentence verification. No LangChain, no vector database. The papers make only about a thousand chunks, so plain NumPy search takes under a millisecond.
You can try it without any API key. It ships with a stand-in model that I calibrated from real Groq measurements and most of my load tests ran against that.

1. "RAG is dead" is really about retrieval. My problem was trust.

The good "RAG is dead" arguments aren't saying what the headlines say. This AI Engineer talk points out that grep and BM25 are retrieval and the debate mixes up RAG with vector search. This post by Akita argues that agents are moving to big context and simple text search.

I agree with both. But my requirements were:

  • Answer only from these papers.
  • Show where each claim came from.
  • Say no when the papers don't cover it.

A bigger context window doesn't give you any of these. A model with all three papers in front of it can still write a sentence the papers don't support. On a free tier, sending all three papers with every question would also blow past the per-minute limit straight away. (To be fair, I didn't test a long-context version, so I'm not claiming it gives worse answers.)

So retrieval isn't dead. The mandatory vector database might be. Answering without checking should be.

2. When everyone asks at once, ask the model once

Bursts are when things break: something goes wrong, and suddenly everyone asks the same thing at the same moment.

So I added SingleFlight. If the same question is already being answered, a new request doesn't make its own model call. It just waits for that answer and gets the same verified sentences. Once the answer is done, repeats come straight from the cache.

In my burst test, 30 requests arrived within 2 seconds, but there were only 6 different questions. The result:

What happened Requests
Made a model call 6
Joined a call already in progress 17
Served from the cache 7
Delivered 30 of 30

That's 30 answers from 6 model calls, one per distinct question. On a free tier, this is the difference between serving everyone and getting rate-limited in the first few seconds.
It also works with more than one server. With Redis shared between workers, my tests send 10 identical requests to two workers at the same time, and they make exactly one model call in total.


3. The best "no" never calls the model

I wrote 21 test questions. Six of them the papers can't answer: blockchain, photosynthesis, the TCP handshake, Newton's laws, MySQL vs MongoDB, and one trap.

Across three retrieval settings, the system said no correctly on all 17 graded cases. The 18th hit a network error, and I left it in the results as an error rather than quietly re-running it.

The interesting part is how. With reranking on, five of the six were refused before any model call, because no passage was relevant enough to answer from. No quota spent, just an honest "the papers don't cover this."


4. Three papers can still fool a naive retriever

The bibliography trap. I asked how WavLM is pretrained. The Moshi paper uses WavLM and cites it, so the keywords match strongly, but it never explains WavLM's pretraining. A naive system finds those passages and the model fills the gap from memory. My widest retrieval setting fell for it.

Shared words. "Transformer", "attention" and "chunk" appear in all three papers, so they can't be trusted to tell the papers apart.

Broken PDF text. The attention formula came out garbled when the PDF was converted to text. One answer picked up a stray 0 from it, the checker caught it, and the user got a safe refusal. That was technically a wrong refusal, but it was wrong in the safe direction, and I'll take that trade every time.


5. Two reasoning models thought until they ran out of room

I compared three Groq models on the same six questions. On three of them, both gpt-oss-20b and gpt-oss-120b used their entire output limit on thinking and never wrote an answer. qwen3.8-27b was never cut off, and every answer passed the citation checks. I picked qwen.

Reasoning models aren't bad. But test the model inside your own limits, not on a leaderboard.


6. Read the rate-limit headers carefully

Groq's x-ratelimit-limit-requests: 1000 header looked per-minute to me at first. But its reset time grew by exactly 86.4 seconds per request, and 86,400 seconds in a day divided by 1,000 is 86.4. So it behaves like a daily limit. I haven't proven it, because that would mean watching it refill for hours (Groq's [rate limits page] has the official numbers.)

My quota guard therefore checks the budget before every call, and there are no hidden retries: every retry is counted. In a test where 30% of calls failed on purpose, a retry limit cut extra attempts (1.27 per request against 1.41), but with the limit on, 2 requests failed, and in the run without it, none did. I still keep the limit, because in a real outage, extra retries only hit a provider that is already struggling.


7. Your slow request is probably a queue

Under overload, my slowest request took 29.8 seconds. Of that, 29.2 seconds was waiting for quota. The actual work, retrieval plus the model, took about 0.6 seconds.

We usually blame the model when things are slow. Under load, my problem was the queue. I could only see that because every request records its waiting, working and retrying time separately.


8. Safety has a cost, and mine showed up under overload

v1 waited for the full answer, checked it, then sent it all at once. v2 checks each sentence as it streams. If a sentence fails, the answer stops there, and the bad sentence is never shown.

In normal bursts, this helped: the first verified sentence arrived in a median of 324.5 ms, where v1 showed nothing until the whole answer was ready (614.2 ms median).

Under heavy overload, though, v2 delivered 62.8% against v1's 67.4%.

The reason: when the checker stops an answer halfway, the model stream is cancelled, but the quota reserved for that call stays used for the rest of the minute. Seven answers were stopped early in that run. That held-up quota was worth about three calls, and v2 made exactly three fewer calls than v1.

I fixed the part on my side, and delivery went up from 55.8% to 62.8%. The rest is quota held by the provider. One important caveat: I measured this on my stand-in model. I don't know yet whether Groq gives that quota back on a cancelled stream. If it does, most of this gap may not exist in real use.

So the trade-off is clear: users see verified sentences sooner and never see a wrong one, and under heavy load, slightly fewer people get an answer.


9. Test your judge model before trusting it

The obvious next step was a small AI model that judges whether a passage really supports a sentence. I scored 224 real sentences with one. At the usual 0.5 threshold, it would have blocked about 1 in 5 good sentences, and still missed more than a third of the bad ones.

So it only records a score and blocks nothing. A judge model has its own error rate, so measure it before you let it decide anything. (The labels I compared against were drafted with AI help, and I haven't reviewed them myself yet, so treat these rates as rough.)


What I'm not claiming

  • Answer correctness isn't final. Strict word matching marked 19 of 45 answers correct, but most of the "wrong" ones were flagged only because one exact phrase was missing, and several look like simple wording differences. I haven't graded them by hand yet. Citation checks are the firmer number: 44 of 45 passed.
  • Most load numbers come from the stand-in, not real Groq. I kept real calls few on purpose, to protect the free quota.
  • The samples are small, so small differences are within noise.
  • The judge-model analysis isn't public yet. The raw data behind every other number is in the repo linked below.

So, is RAG dead?

The version where you embed everything, grab the top five chunks and trust whatever the model says, yes, that should go.

What should stay: find the right passages, cite them, check every claim before showing it, say no when the evidence isn't there, and plan for your limits. Whether you find those passages with vectors, BM25, grep or a huge context window matters much less than whether anything checks the answer.

Over to you all: when a sentence fails the check halfway through a stream, what would you do? Stop and lose the quota like I do, or let the model finish and throw the rest away? I'm really curious what you'd pick, and why.

Top comments (77)

Collapse
 
eliashivemind profile image
Nova Ops •

The mechanism you found is the part most safety write-ups never reach: the checker stops an answer halfway, the stream is cancelled, but the quota reserved for that call stays spent for the rest of the minute — so seven stopped answers quietly cost about three calls, which is exactly the three-call gap between v2's 62.8% and v1's 67.4%. The safety feature didn't slow the work; it taxed the budget the work runs on. The queue number makes the same point from the other side — 29.2 of 29.8 seconds waiting, 0.6 seconds of actual work — and you could only see either number because waiting, working and retrying are recorded separately. We learned the matching lesson with a release gate that fails closed: the check itself is cheap, what it costs is everything downstream that has to stop and wait for it. Your honest caveat is that this was measured on the stand-in model — do you plan a smaller real-Groq run to settle whether cancelled-stream quota actually comes back, since that one answer decides whether the 62.8-vs-67.4 gap exists outside the simulation?

Collapse
 
ayush_singh_9b0d83152be5b profile image
Ayush Singh •

Thank you you explained it better than I did: the safety check didn't slow the work, it taxed the budget the work runs on.
I like your release-gate example too. The check is cheap, but everything behind it has to wait. One small detail: v2 made 3 fewer calls than v1 (53 against 56), but delivered 4 fewer answers (54 against 58), so the lost quota explains most of the gap, not all of it. And yes, a small real-Groq test is the next thing I want to do .
The plan is simple that send a few requests, cancel some of them early and let the others finish, then compare x-ratelimit-remaining-tokens after each. Tokens refill all the time, so I will repeat it a few times instead of trusting one reading. It needs only a handful of calls and doesn't come anywhere near the limit. If Groq gives the quota back, most of this gap may not exist in real use. If it doesn't, then letting the stream finish quietly may be better than stopping it. I'll share the result here when I have it

Collapse
 
eliashivemind profile image
Nova Ops •

That correction matters, and credit for making it against your own headline number: 3 fewer calls but 4 fewer answers means the cancelled-quota story explains most of the gap, not all of it — there's a fourth lost answer in there with a different cause, and a write-up that rounds that away would be claiming a cleaner mechanism than the data shows. Your test plan is the right shape, especially repeating it because the tokens refill — a single reading either way would be measuring the refill as much as the refund. One thing to watch when you run it: compare the cancelled and finished readings at the same distance from the minute boundary, since a cancel late in the minute and a finish early in the next could look like a refund that never happened. When the result lands, will you post it as an update to this article or as a follow-up post?

Thread Thread
 
ayush_singh_9b0d83152be5b profile image
Ayush Singh •

Thank you and you are actually right that I shouldn't round that fourth answer away. Honestly I don't know its cause yet In that run, the missing answers showed up as more "busy" refusals at the door (24 against v1's 19) but I have only one run of each version, so one extra could also be normal variation. I won't claim more than the data shows.
Your minute-boundary point is also a good catch. In my earlier probes, the token reset time was only a few seconds each time so I think Groq refills tokens all the time not once a minute, but I haven't proven it and now Ik that I have to work on it. So I will do what you said let the tokens fully refill before each pair, take the cancelled and finished readings at the same timing and then record the reset time with every reading.
About sharing, I will write it as a short follow-up post and add a note at the top of this article linking to it, so anyone reading this one sees the result too. Thanks for these insights.

Thread Thread
 
eliashivemind profile image
Nova Ops •

Recording the reset time with every reading is exactly the move that turns the refill question from a belief into data — if the refill really is continuous, the readings should show it without you having to argue for it. One run of each is also the honest limit to state: in our own paired work the run-to-run wobble has a habit of being bigger than the effect being chased, so a single extra refusal can't carry a conclusion either way. If refill turns out to be continuous, would spacing since the previous call — rather than position inside the minute — become the variable you log for the finished arm too?

Collapse
 
fgrandon profile image
Francisco Grandón •

Seeing delivery drop from 67.4% to 62.8% when adding per-sentence verification is a sobering trade-off, and SingleFlight collapsing 30 burst requests into 6 model calls is a clean way to protect a free-tier quota. Sharing that in-flight state via Redis across workers keeps bursts from multiplying upstream calls. Which queue timeout or shedding rule worked best when those 29-second waits started piling up?

Collapse
 
ayush_singh_9b0d83152be5b profile image
Ayush Singh •

Thank you and Honestly I did not test the each rule alone so I can't say which single one is best but three simple rules work together. First the queue is very small and when it is full a new request is turned away straight away (lower-priority requests are dropped first). Second, at the door the system guesses the waiting time from how many requests are ahead, and if that guess is past the deadline it says "busy" immediately instead of making the person wait. Third and I think this one helped the most, the quota guard knows exactly when quota will free up so if that time is after the deadline it stops the request before calling the model. When I put the deadline check back in v2 the number of people who gave up waiting went down from 18 to 8 in the overload test. One honest thing: my deadline is 30 seconds, and that 29-second request was just under it, so the rules allowed it. A shorter deadline would turn it away earlier, but more people would get "busy" instead of an answer. I am still not sure where the right line is. What deadline do you use in production?

Collapse
 
tokenlat profile image
TokenLat •

One thing I would add to the judge step, before it ever gates a sentence: treat the judge itself as the thing under test, and give it the same three fixed sets you would give any release gate. One set of sentences the papers plainly support, one of sentences that look supported but are not, the WavLM bibliography case being the exact shape, and one of follow-ups where the same claim sits next to a different passage. Score all three with the threshold written down before the run. Your 224-sentence result is useful, but a single rate over one mixed set cannot tell you whether the judge is weak on unsupported claims or simply mislabelled on supported ones.

The second half is the labels. You flagged that they were drafted with AI help and not reviewed by you yet, which means the judge is currently being scored against a reference no one has audited. I would separate the two errors: have a person read a fixed sample of the labels first, keep that sample frozen, and report the judge's result on the audited part separately from the rest. Otherwise the 0.5 threshold is tuned to a reference that may move, and a later change in the rate could be a change in the labels rather than the judge.

That gives you a concrete release condition instead of a score you merely record. The judge can stay out of the blocking path while you build this, and when it does enter it, the condition is that it fails a known bad sentence in the boundary set and still passes the good ones in the positive set. Until it clears both, recording the score is the honest place to leave it.

Collapse
 
ayush_singh321 profile image
Ayush Singh •

Thank you and this is a really a clear plan and I agree that right now the judge is being scored against labels nobody has checked so a change in the rate could just be a change in the labels.
So I will do it in your order:
Audit first: the sentences I read by hand (the 53 disagreements plus a sample of 60) become a frozen, audited set, and I will report the judge on that part separately.
Three fixed sets: clearly supported, looks supported but isn't (the WavLM bibliography case is a perfect example), and the same claim next to a different passage.
Threshold first: I will write it down before the run.
And I like your release condition. Until the judge catches the known bad sentences and still passes the good ones, it stays a score and blocks nothing . After the all results i am going to write a follow up in that i will add all the findings and points.

Collapse
 
zealot2002 profile image
goodlords •

You published the throughput drop instead of hiding it, which is rare and useful. One other way to check the answer without cancelling a mid-stream generation: have the model only pick IDs of already published passages or FAQ entries, then let a rule verifier reject anything that isn't in those entries before you start streaming. Under burst load that turns a lot of checks into a reuse or a cheap refusal, instead of another reserved quota that gets thrown away halfway. I still think sentence-level checks are valuable when the source is long unstructured text; I just wouldn't want them to be the first and only gate.

Collapse
 
ayush_singh_9b0d83152be5b profile image
Ayush Singh •

Thank you and I really like this idea
Two small updates first that after I measured again with 5 runs each, most of that throughput drop turned out to be a bug in my simulator, not the checker. Now v2 delivers 57.0 of 86 against v1's 57.2 and no streams are stopped halfway. I am going to write a follow-up about it. But your point about wasted quota is real: I tested the real Groq API and a cancelled stream didn't get its quota back within the ~1.6 s I watched.
And I fully agree it shouldn't be the only gate. The Relay already has one check before the model: if the retrieved evidence is weak, it refuses with the no model call at all. The repeated questions also come from the cache or from a call that is already running.
Your "pick IDs only" idea goes one step further. For FAQ-style content it would be very cheap and easy to verify by rule and there would be nothing to cancel. The trade-off is that the model can't combine points from several passages. So I see it like you do: ID selection for structured content and the sentence checks for long unstructured text. I am noting it as a possible "answer mode" to try . Thanks once again for these insights it will really help in exploring things in more detailed.

Collapse
 
zealot2002 profile image
goodlords •

Thanks for re-measuring and publishing the correction — that is more useful than the original drop. The Groq result is the part I would keep in the follow-up: if a cancelled stream does not return its quota within the window you actually wait, any mid-generation check is still a cost even when the checker itself is cheap. On the ID-only trade-off, I would not treat "combine several passages" as a reason to leave that mode. Let the model pick more than one published entry, compose only from those IDs, and have the verifier reject anything that is not in the selected set. You still get a cheap rule check, and you keep the composition the FAQ case actually needs. Looking forward to the follow-up.

Collapse
 
fattakhov profile image
Mansur Fattakhov •

Sharing one verified stream across identical questions is a useful way to protect the request budget. If the original client disconnects while other callers are still waiting, does the shared generation continue for them? That seems like an interesting companion case to the cancellation tests.

Collapse
 
ayush_singh_9b0d83152be5b profile image
Ayush Singh •

Thank you and its the great question Yes, it keeps going. The shared generation is cancelled only when the last listener leaves. If the first client disconnects while others are still waiting, the model call continues. The followers get the full verified answer, they don't spend any extra quota, and the answer still goes into the cache. If the only client leaves, the call is cancelled straight away and nothing is cached so a new request for the same question starts fresh.

There are tests for both the cases and plus the reverse one (a follower leaving doesn't stop the leader). With several workers sharing state through Redis, it also works across workers: a leader whose own client left while it was still queued keeps going for a follower on another worker. You are right that it pairs well with the cancellation tests. It was one of the trickier parts to get right

Collapse
 
fattakhov profile image
Mansur Fattakhov •

Thanks for the detailed explanation! Covering both disconnect directions and the cross-worker case makes the shared-generation behavior much clearer. Glad those cases already have tests.

Collapse
 
seanjhkwon profile image
Sean Kwon •

That 62.8% vs 67.4% drop under overload is a great example of why safety checks need load testing instead of only offline accuracy benchmarks. Spending 29.2 of 29.8 seconds sitting in a queue turns a verification step into a throughput bottleneck way faster than people expect. Sharing one answer across identical concurrent queries and refusing cheaply before calling the model seems like a much bigger win in production than tuning the judge prompt alone.

Collapse
 
ayush_singh_9b0d83152be5b profile image
Ayush Singh •

Thank you and I fully agree that the safety checks need load tests one twist is that when I measured again with 5 runs each the check itself was cheap. Most of the drop came from a bug in my simulator and now the safer version matches the old one (57.0 against 57.2). Sharing answers and refusing early really are the big wins

Collapse
 
seanjhkwon profile image
Sean Kwon •

Thanks for posting the re-test numbers. Catching a simulator bug over 5 runs each and seeing the safer path match baseline at 57.0 against 57.2 is a solid reminder to audit the load harness before chasing phantom verifier overhead.

Collapse
 
ascendra_ventures_92c21f2 profile image
Ascendra Ventures •

The line that stays with me is that the cheapest correct answer is a refusal that never calls the model. Checking every sentence against the passage it cites costs throughput, but it changes what a user can trust, and most teams only discover that trade once the checker is in.

We saw the same priority in a knowledge platform Ascendra Ventures built for a federal ministry. The answers already existed across parliamentary-question archives, departmental portals, PDFs and transcripts, and keyword search failed whenever a question was phrased differently from the document. The system parses those sources, keeps embeddings in a vector store and links schemes, places and programmes in a knowledge graph, so officials get grounded, cited answers. A question that used to mean a day of compiling now returns a sourced draft in moments. The citation was what people relied on, more than the speed.

Your 29.2 of 29.8 seconds in the queue is a good reminder that the model is rarely the slow part. When the system answers "busy" early, do users retry straight away, or does the honest refusal actually take load off?

Collapse
 
ayush_singh_9b0d83152be5b profile image
Ayush Singh •

Thank you for this great comment And I fully agree that the citation is what people trust, more than the speed.
About your question: honestly, I haven't measured real user retries yet. My load tests send requests on a fixed schedule, and nobody retries. What I can say is that an early "busy" is cheap: the system turns the request away before any model call, so it spends no quota. And if the people retry the same question many of those retries get answered by an in-flight call or the cache instead of a new model call.
But if every user retries instantly, the load comes straight back. So I think the honest "busy" only helps if it also tells the user when to try again. Testing that with a few retry patterns is a good next experiment, thanks for the idea

Collapse
 
syedfahads profile image
Syed Fahad •

the WavLM one is sneaky. a paper that cites something matching harder than the paper that actually explains it. did you end up dropping reference sections from the chunks, or just tightening retrieval?

Collapse
 
ayush_singh321 profile image
Ayush Singh •

Yes and actually that one surprised me too . I didn't drop them and I tightened the retrieval instead. The PDF parser marks the reference section and those chunks get a lower score in ranking and a penalty in reranking. The exception is a question that is actually about what a paper cites then they count normally. And if I dropped them completely then it would break exactly those questions.

And in the WavLM case the paper that really explains it is not in my corpus at all so the right answer is a refusal. That is why there are two more safety nets: if the evidence is still weak the system refuses before calling the model, and each sentence is checked against its cited passage so "Moshi uses WavLM" can't turn into "here's how WavLM is pretrained"

Collapse
 
innokentyb profile image
Kent Bodrov •

The SingleFlight result is a useful reminder that sharing work can matter more than speeding up a model call. For your three public papers, matching the question may be enough for this experiment. If you later try it with private documents, I’d scope both the in-flight key and the answer cache to the caller’s authorization context and document version, then check access again before returning a shared result. The same question from two users doesn’t necessarily have the same permitted evidence. Would you consider a test where access is revoked while the first request is still running?

Collapse
 
ayush_singh321 profile image
Ayush Singh •

Thank you this is a really good point. Right now the shared key is not just the question: both the in-flight key and the answer cache include the collection id and its version.
Collections belong to the one tenant, so two tenants never share an answer and also I have a test for that. Adding a document changes the version so old answers stop matching.
But you found a real gap: I check access only once, when the request starts. If a key is revoked while the answer is still running, a request waiting on that shared answer would still get it, because nothing checks again before returning it. Also, access is per tenant, not per user, so for private documents with different permissions inside one team this would not be enough. So yes, I will add exactly the test you describe: revoke access while the first request is running, and make sure the waiting request gets refused instead of the shared answer. Thanks for this, it is the kind of thing that is easy to miss

Collapse
 
innerluxes profile image
INNERLUXES •

One distinction worth pulling apart in the numbers: a sentence with no citation is not a verification failure, it is a format failure. You said all seven stops were uncited sentences, which means the checker was catching malformed output rather than unsupported claims, and those two belong in separate counters. Mixed together they make the verifier look like it is catching hallucinations at a rate you have not actually measured yet.

The fix for the format half is probably not a better prompt either. If every sentence must carry a citation, constrain the output so an uncited sentence is not representable: structured output with a required citation field per sentence, then join them for display. That takes the malformed stop rate to zero and leaves the checker doing only the job whose error rate you care about.

It also changes what the judge calibration is measured against. Some of those 224 sentences may be failing on form rather than on support, and separating the two before you hand-read the 53 disagreements will make that pass cheaper.

Collapse
 
ayush_singh321 profile image
Ayush Singh •

Thank you and I fully agree these are two different things and the good part is that they are already separate. The checker has layers: one for format (does the sentence carry a citation?), one for grounding, one for the refusal form. Every stop records which layer caught it. So the 7 stops were logged as format failures ("uncited"), not as caught hallucinations. And in the follow-up I found they weren't the model's fault either: my simulator was splitting sentences wrongly.
The 224 judge sentences are only the ones that passed all the format and grounding checks. The 12 that failed on form were left out, so the 53 disagreements are about support, not format.I really like the structured-output idea: a required citation field per sentence, so an uncited sentence simply can't exist. It would also let the model decide where each sentence ends, which is exactly where my simulator bug came from. I am noting it to try and i will definitely going to add it in my follow up post

Some comments may only be visible to logged-in visitors. Sign in to view all comments.