Guide
Production RAG Cost Traps: Chunking, Reranking, and Vector DB Trade-Offs for Small Teams
Innocent Ncube, based in Poland ·
A support assistant answers the right question in staging. In production, the same page shows up in six near-identical passages, the reranker runs on every search, and the next documentation import forces a database upgrade. Each stage looked cheap on its own. The request taken end to end is where the bill appears.
Pick one route and measure it from document import to final answer. Separate ingestion and re-embedding from recurring storage, query embedding, retrieval, reranking, and generation. Divide recurring spend by the number of answers that pass your quality and latency checks. A low cost per request can hide retries and answers the support team has to correct.
1. Count what chunk overlap creates
With 500-token windows and 100 tokens of overlap, the next window starts 400 tokens later. Over a long corpus, that produces about 25% more chunks than a 500-token stride. A library setting expressed in tokens becomes a line item in the embedding, storage, and index budgets. Managed retrieval services can expose both window size and overlap as ingestion settings. OpenAI retrieval documentation
Say you have 40 million source tokens across long documents. Ignore document ends and metadata for this estimate.
| Chunk setting | Vectors to index | Tokens to embed | Raw 1,536-dimension float32 vectors |
|---|---|---|---|
| 500 tokens, no overlap | 80,000 | 40 million | 492 MB |
| 500 tokens, 100 overlap | 100,000 | 50 million | 614 MB |
Storage here is vector count × 1,536 × 4 bytes, rounded to decimal MB. Add stored text, metadata, indexes, replicas and backups when you size the database. Use the actual provider's tokenizer and a representative import to count chunk ends, heading text and repeated boilerplate.
For manuals and runbooks, split on headings first and keep the path to the heading on each chunk. Test cases where a prerequisite and its procedure fall on opposite sides of a boundary. Add overlap or fetch a neighbouring passage where it rescues those cases. Keep a document content hash plus the chunker and embedding-model versions so a routine import can update changed chunks and remove stale ones. Budget for both indexes during a full re-embed if you need to keep serving and retain a rollback path.
2. Give the reranker a job and a budget
A reranker orders an existing candidate set. Log whether the right passage reached that set before you tune the ranking stage. If retrieval missed it, try a better chunk boundary, lexical matching for exact terms, or a wider authorised candidate set. Apply tenant and document permissions before passing text to the reranker. For requests that reach it, record candidates sent, rerank latency, and passages retained. Cohere rerank documentation
Start the replay with up to 20 unique candidates and four passages in the final prompt. Compare it with the same four-passage budget without reranking. Include codes and product names that need exact matches, questions that need two sections, and questions with no authorised answer. Count evidence found in the candidate set, evidence retained in the prompt, correct citations, correct refusals, and p95 end-to-end latency. Evaluate long prompts on your own model because evidence position changed answer accuracy in published long-context experiments. Lost in the Middle
Here is how the price test could look at 4,000 answer requests per day. Assume 30 days, 600 input tokens for the question and instructions, 400 tokens per passage and 300 output tokens per answer. Use illustrative rates of $1 per million input tokens, $4 per million output tokens and $1 per 1,000 reranker calls.
| Scenario | Input tokens per answer | Monthly generation | Monthly reranking | Combined |
|---|---|---|---|---|
| Eight passages, no reranking | 3,800 | $600 | $0 | $600 |
| Four passages, no reranking | 2,200 | $408 | $0 | $408 |
| Four passages, rerank every request | 2,200 | $408 | $120 | $528 |
Dropping four passages saves 192 million input tokens, or $192 per month at the illustrative rate. Reranking every request leaves a $72 monthly saving compared with eight passages. Against four passages without reranking, it has to earn its $120 through better answers or fewer retries. If the gain is concentrated in hard queries, test a gate for those queries and decide whether a timeout should fall back to the original ranking or return search results. Check how your reranker counts billable work and add database and ingestion costs separately.
Use the RAG workload in Signal Engine to compare your generation spend at those traffic and token volumes. Add the separate stages from your own measurements.
3. Compare databases with real filters and writes
If the source documents and permissions already live in Postgres, start with a tenant-filtered exact vector search on a realistic slice. Keep PostgreSQL full-text search as another candidate source for keywords and names. Measure recall and query p95 under normal writes and a backfill. This can establish a useful baseline before you add a new index or another service. PostgreSQL full-text search · pgvector documentation
If exact search misses the latency target, test an approximate index against the exact results using the same tenant and metadata filters. HNSW generally buys a better speed–recall trade-off than IVFFlat in pgvector at the cost of more memory and slower builds. Selective filters can yield too few neighbours after an approximate index scan. Measure the effect of iterative scans or a different index layout on both recall and p95. pgvector index trade-offs and filtering
Compare a dedicated vector store when retrieval competes with application transactions, or when filtered search needs a different scaling plan. Give it the same access filters, ingest rate, delete requests and replay questions. A store such as Qdrant uses payload indexes for filtered search, and those indexes also take memory and disk. Put primary and replica resources, backups, network charges, index rebuild headroom, and time to restore in the same comparison. A second store also needs a way to replay missed updates and verify that deleted documents stop appearing. Qdrant indexing documentation
Production checklist
- Ingestion. Run a representative import with two chunk settings. Record chunk count, embedded tokens, index size, build time and the evidence recovered by overlap.
- Retrieval and ranking. Replay exact terms, multi-section questions and no-answer cases. Check permission filtering before reranking and record candidate recall and citation accuracy.
- Unit cost. Compare short prompts with and without reranking at the same answer-quality target. Include retries and reranker timeouts in the measurement.
- Database. Test the normal tenant filter mix during writes and backfills. Record peak memory, p95, restore time and the cost of serving a replica.
- Rollout. Set an answer-quality floor and a latency ceiling before changing traffic. Put the candidate limit, context budget and reranker switch in configuration so the on-call owner can roll back.
Take one support route this week and compare the two prompt budgets on the same questions. Save the input lengths, quality scores, spend and rollback trigger in a short decision record. The AI Engineering Toolkit has checklists and worksheets for the inference and rollout decisions that follow.