RAG Application Deployment: A Five-Layer Architecture in Practice
This article breaks down a typical private RAG platform into five layers: model inference, vector and reranking, knowledge processing, orchestration and APIs, and operations and observability. It explains why getting a service running is not the same as making it usable, and covers common deployment pitfalls, GPU memory and concurrency planning, chunking and metadata design, permission-aware retrieval, cost control, and canary rollout with rollback. The goal is to help teams turn retrieval-augmented generation from a demo into stable production output.
1. Why “It Runs” Does Not Mean “It Works”
Over the past year, the capability boundaries of open-source large models have been pushed steadily higher, and enterprise deployment demand has surged along with them. Many teams start by standing up an inference service, connecting a knowledge base, and adding a chat interface, then call the project done. In real projects, however, the gap between a demo and production tends to show up in the unglamorous places: retrieval quality, context length management, concurrent request queuing, and failure recovery.
The core value of Retrieval-Augmented Generation (RAG) is that it lets a model consume private knowledge without retraining. By retrieving first, assembling the prompt next, and generating last, it mitigates hallucination and stale knowledge. The engineering complexity lies not in the model itself, but in chaining several independent capabilities into a pipeline that is stable, observable, and rollback-capable.
This article therefore breaks a typical private RAG platform into five layers: the model inference layer, the vector and reranking layer, the knowledge processing layer, the orchestration and API layer, and the operations and observability layer. The “five-piece set” experience mentioned in the source material is essentially a combination of these five capabilities. Below, product-specific attributes are stripped away, and only general technical problems and engineering practices are discussed.
2. Layer One: Model Inference Service
The inference layer turns model weights into callable endpoints. Two approaches are common in the industry. One is a general-purpose high-performance inference framework, which offers better throughput but comes with a large number of configuration options. The other is a unified model management platform, which loads models visually, is easy to pick up, and supports a wide range of model types, at the cost of some peak performance and flexibility. There is no need to choose only one: a unified platform can host smaller models such as multimodal, embedding, and reranking models, while a high-performance framework can host the main conversational model.
Containerization is the least troublesome delivery method. The idea of bringing a service up with a single command looks like this (illustrative; adjust the parameters to your own environment):
docker run -d --name inference-gateway \--gpus all \-p 9997:9997 \-e RUNTIME_HOME=/data \-v $(pwd):/data \your-registry/inference-runtime:latest \runtime-server -H 0.0.0.0
A few frequent pitfalls are worth avoiding in advance:
- Port and host address: if the service inside the container listens only on the loopback address, neither the host nor an external gateway can reach it. A parameter such as
-H 0.0.0.0must be set explicitly. - Data persistence: model caches can easily reach tens of GB, so always mount a dedicated volume or host directory. Otherwise the model has to be downloaded again after the container is recreated.
- GPU memory and concurrency: GPU memory usage is roughly related to “parameter count × precision factor + KV cache.” Long contexts and high concurrency significantly amplify KV cache overhead, so cap the maximum context length and the concurrent batch size in exchange for stability.
- Model source: prefer a model repository mirror that supports fast pulls, which noticeably shortens cold start time.
Before going live, run a baseline load test and record time to first token, output tokens per second, and peak GPU memory under long context. These three numbers are the basis for all later capacity planning.
3. Layer Two: Embedding and Reranking
Retrieval quality sets the ceiling for RAG. This layer usually involves two roles: the embedding model maps text into vectors, and the reranking model performs fine-grained ordering on the initial recall results.
Key engineering points include:
- The embedding model and vector dimensions must strictly match the vector store index configuration. A dimension mismatch is the most common cause of startup failure.
- For Chinese-language scenarios, choose an embedding model that handles Chinese semantics well, and run a small-scale recall evaluation on your own business corpus rather than relying only on public leaderboards.
- Reranking is the most cost-effective optimization point. A typical pipeline is “vector recall Top 50 → rerank and keep Top 5,” which significantly improves answer relevance with almost no increase in generation cost.
- Batch inference and batch size settings affect throughput. Small models also need GPU memory, so plan GPU memory quotas together with the main model.
4. Layer Three: Knowledge Processing and Indexing
This layer is the most easily underestimated, yet it directly determines answer quality. It is best to fix the workflow as a repeatable offline pipeline:
- Parsing: choose parsing strategies separately for documents, tables, and scanned files; for content with complex layouts, prioritize preserving structure.
- Chunking: split along semantic boundaries and keep the heading hierarchy. Chunk length and overlap ratio must be determined experimentally: chunks that are too long dilute relevance, while chunks that are too short lose context.
- Metadata: attach fields such as source, permissions, and timestamp to every chunk, leaving room for later permission filtering and recency-based ranking.
- Indexing: when writing to the vector store, also build scalar filter indexes that support pre-retrieval filtering by department and classification level. This is a hard requirement in enterprise scenarios.
5. Layer Four: Orchestration and APIs
The orchestration layer turns the capabilities above into an application. Low-code visual orchestration suits quickly validating a business flow, while code-based orchestration suits scenarios that need fine-grained control. The two can coexist: build the main flow visually first, then replace key nodes with in-house implementations.
A minimal working retrieval-augmented call can be abstracted as:
def ask(query, top_k=5):hits = vector_store.search(embed(query), top_k=50)hits = reranker.rank(query, hits)[:top_k]context = "\n".join(f"[{h.meta['source']}] {h.text}" for h in hits)prompt = f"Answer only based on the following material; state clearly if you cannot answer.\nMaterial:\n{context}\nQuestion: {query}"return llm.chat(prompt)
When exposing this externally, be sure to add three capabilities: streaming output to improve perceived responsiveness, citation and provenance to build trust, and permission filtering based on scalar metadata to prevent unauthorized retrieval.
6. Layer Five: Operations, Observability, and Cost
The real cost of private deployment is operations. At a minimum, build four foundational capabilities: a logging service for tracing requests across the pipeline, monitoring and alerting for GPU memory and latency dashboards, object storage for archiving model and document assets, and a container platform for elastic scaling and canary releases.
For cost control, route high-frequency simple requests to a smaller model and reserve the large model for complex reasoning; introduce a semantic cache for repeated questions; and use offline batch processing for non-real-time tasks. For canary rollout, first validate the retrieval and generation quality of a new version with shadow traffic, then gradually increase the traffic share, and keep the ability to roll back to the previous index snapshot with a single action.
7. Conclusion
The hard part of productizing RAG has never been starting the services. It is turning the five layers into a system that is measurable, rollback-capable, and extensible. Using a general-purpose container platform as the foundation, and solidifying each layer in order — inference, vector and reranking, knowledge processing, orchestration, and operations — together with a clear evaluation set and baseline data, is what moves retrieval-augmented generation from a demo to stable production output. To further lower the barrier to self-hosting, you can also evaluate managed capabilities such as general-purpose container platforms, object storage, and monitoring and alerting in the cloud, and focus your effort on the two things that truly determine results: data and evaluation.
