When Do You Need to Build Your Own RAG System
As context windows grow from a few thousand tokens to hundreds of thousands or even millions, a natural question arises: if a model can "read" an entire knowledge base in a single pass, do we still need to build RAG ourselves? In most production environments the answer is still yes, but the reason has shifted from "the model cannot fit everything" to "cost, latency, controllability, and operability cannot fit everything." This article breaks down how long context and RAG solve different problems, and explains the cost, latency, controllability, and engineering factors that determine whether a self-built retrieval pipeline is worth it.
When context windows expand from a few thousand tokens to hundreds of thousands or even millions, a natural question arises: if a model can already “read” an entire knowledge base in one pass, do we still need to build RAG ourselves? The answer is that most production environments still need it, but the reason has changed from “the model cannot hold everything” to “cost, latency, controllability, and operability cannot hold everything.”
1. Separate the Two Problems: Long Context Solves Capacity, RAG Solves Hit Rate
Progress in long-context capability is real, but it optimizes how much input a single request can hold. RAG optimizes delivering the right fragment to the model at the right moment. The two have different objective functions: the former reduces the probability of “not fitting,” while the latter reduces the probability of “fitting the wrong thing, fitting too much, or paying too much.” Treating them as substitutes is where many teams start to stumble during load testing.
2. Cost: Input Length Scales Linearly or in Steps
Pricing for mainstream commercial models generally correlates with input token count, and many models use tiered pricing: the unit price holds within a certain context threshold, then jumps to a higher tier once that threshold is exceeded, with output-side pricing typically much higher than input-side pricing. This means that stuffing an entire document collection into the context does not raise cost gradually; cost climbs in steps as you cross tier boundaries.
Consider an illustrative comparison of magnitudes: one class of models charges roughly a bit over one dollar per million input tokens, with the unit price doubling beyond a tier of around two hundred thousand tokens, while the output side may reach more than ten times the input side; another tier positioned for higher quality has input and output unit prices in the “single-digit dollars” and “tens of dollars” ranges respectively. Injecting a corpus of twenty thousand documents and millions of vectors in full, compared with retrieving first and then injecting, can make the input cost of a single request differ by more than two orders of magnitude. When daily call volume exceeds ten thousand, that gap directly determines whether the business is viable.
Illustrative cost estimation logic (this only expresses the calculation method and does not represent any specific vendor’s pricing):
def estimate_cost(input_tokens, output_tokens, tier_threshold, in_price, out_price, over_price):# Above the tier threshold, the input portion is billed at a higher unit priceif input_tokens <= tier_threshold:input_cost = input_tokens / 1_000_000 * in_priceelse:input_cost = (tier_threshold / 1_000_000 * in_price+ (input_tokens - tier_threshold) / 1_000_000 * over_price)return input_cost + output_tokens / 1_000_000 * out_price
3. Latency: Prefill Cost Grows With Input, Retrieval Is Nearly Constant
In large-model inference latency, the input-side prefill stage is strongly correlated with input length. Publicly available industry measurements generally show that inputs on the order of hundreds of thousands of tokens often take tens of seconds to complete the first round of inference, and the time rises further as input approaches a million tokens. A well-engineered retrieval pipeline, by contrast, commonly compresses candidate recall and reranking to sub-second levels at a scale of tens of millions of vectors. In other words, for the same corpus size, the overall response of the RAG path can be kept around one second, while the full-injection path is often on the order of tens of seconds.
For interactive products this gap is critical: when time to first token exceeds a few seconds, user retention drops noticeably. For batch jobs, amplified latency translates directly into lower throughput and higher resource costs.
4. Controllability: Retrieval Is an Observable, Replayable, Optimizable Middle Layer
The biggest risk of full injection is not cost but the “black box.” When an answer is wrong, you cannot tell whether it is a model capability problem, a conflicting-materials problem, or a ranking problem. Adding a retrieval layer gives the system a set of observable intermediate artifacts: the recall set, ranking scores, fragment sources, coverage, and conflicts. These artifacts turn badcase diagnosis from “guessing” into “checking,” and give iteration a clear handle.
A practical layered structure usually contains six layers:
- Data ingestion layer: multi-source document parsing, layout restoration, incremental sync, and version management;
- Chunking and indexing layer: chunking by semantics and structure while preserving metadata such as heading hierarchy and page numbers;
- Recall layer: vector retrieval and keyword retrieval running in parallel, with fused and deduplicated results;
- Rerank layer: cross-encoders or rule-based policies for fine ranking, controlling how many fragments enter the context;
- Generation layer: assembling prompts, constraining citations, and producing structured output;
- Evaluation and operations layer: offline evaluation sets, online monitoring, logging, and alerting.
Illustrative retrieval main flow:
def rag_answer(query, top_k=50, rerank_n=6):dense = vector_index.search(query, top_k) # semantic recallsparse = keyword_index.search(query, top_k) # keyword recallmerged = fuse(dense, sparse) # fusion and deduplicationkept = reranker.rerank(query, merged)[:rerank_n]context = build_context(kept) # includes source metadatareturn llm.generate(query, context, require_citation=True)
5. Four More Engineering Constraints to Consider
- Permissions and isolation: different roles can see different document scopes, so retrieval must support filtering by identity; full injection makes fine-grained isolation difficult.
- Freshness: when knowledge updates daily, full injection means re-shipping the entire collection on every request, while retrieval only needs incremental index updates.
- Auditability and compliance: when you need to provide citation sources, retain the call chain, and support traceback, the retrieval layer’s metadata is a natural carrier.
- Multi-turn and scenario switching: corpora differ widely across business lines, and the retrieval layer can maintain separate indexes per scenario to avoid cross-contamination of context.
6. When You Can Skip Building Your Own
If the corpus is on the order of a few thousand tokens, updates are very infrequent, latency is not sensitive, and citation traceability is not required, using long context directly is simpler. In addition, if a team lacks evaluation and operations capabilities, forcing a retrieval pipeline is often worse than first using platform-based general capabilities. On cloud platforms such as Baidu AI Cloud, ready-to-use general retrieval-augmented capabilities are typically available, and combined with infrastructure such as object storage, message queues, container platforms, logging services, and monitoring and alerting, a usable version can be assembled quickly, then gradually made self-built as data scale and compliance requirements rise.
7. Evaluation Metrics: Let Data Decide Whether to Build Your Own
It is advisable to track at least five metrics: recall hit rate (whether the correct fragment enters the candidate set), context effectiveness (the proportion of fragments that enter the context and are actually cited), end-to-end accuracy, time to first token and overall latency, and the combined cost per thousand question-answer sessions. When the full-injection approach hits a business red line on cost or latency, and the retrieval approach can keep the hit rate stable at a high level, the return on investment of building your own becomes justified.
Conclusion
Long context and RAG are complementary: the former expands capacity, while the latter improves hit rate and reduces cost and latency. Whether you need to build your own does not depend on how many tokens the model can swallow, but on your corpus size, call volume, latency budget, and permission and audit requirements. When any one of these reaches its limit, building your own retrieval pipeline turns from an “option” into a “must.”
