Building a Private RAG System: A Five-Layer Deployment Guide
This article explains how to build a private, on-premises Retrieval-Augmented Generation (RAG) system using a five-layer architecture: model inference, embedding and reranking, document parsing, orchestration and APIs, and operations. It covers containerized deployment, GPU resource planning, common pitfalls, chunking and metadata practices, acceptance criteria, and a recommended deployment order for teams that need data to stay within their own network.
1. Why Private RAG Has Become a Must-Have
After the rapid improvement of large language models, the most urgent need on the enterprise side is not “training another model,” but “letting the model answer questions from our own business data.” Retrieval-Augmented Generation (RAG) injects external knowledge into the inference context through a “retrieve first, then generate” approach. This avoids the high cost of frequent retraining and significantly reduces the probability of hallucination.
The drivers for private deployment are mainly three: compliance requirements that keep data inside the internal network, control over inference latency and throughput, and avoiding the unpredictable costs of per-call billing.
A complete, production-ready RAG environment can usually be abstracted into five layers: the model inference layer, the vector and index layer, the document understanding layer, the orchestration and interface layer, and the operations and observability layer. The following sections go through each layer.
2. Layer 1: Model Inference Service Layer
The inference layer turns open-source weights into callable service endpoints. There are two common engineering routes:
- A specialized inference engine built for high throughput. It offers high GPU memory utilization and strong concurrency, but tuning parameters and parallelism strategies has a higher barrier to entry.
- A general-purpose inference platform. It manages multiple model types (LLMs, embedding models, reranking models, multimodal models) through a unified interface, supports downloading weights on demand, starting multiple replicas, and dynamic scaling. It is easier to use and more flexible, at the cost of lower peak performance than the specialized option.
A typical containerized startup looks like this (illustrative; use the images and ports from your own environment):
docker run -d --name inference-platform \--restart unless-stopped \-p 9997:9997 \-e PLATFORM_HOME=/data \-v /srv/models:/data \--gpus all \your-private-registry/inference-platform:latest \platform-local -H 0.0.0.0
What the key parameters mean: -d runs in the background; --restart unless-stopped automatically restarts the container after an abnormal exit; -p exposes the service port; -v mounts a host directory into the container to persist weights and configuration; --gpus all passes all GPUs through to the container; and -H 0.0.0.0 in the trailing command listens on all network interfaces, otherwise the service is only reachable inside the container.
Resource planning guidance: a 7B-class model needs about 14GB of GPU memory under FP16. Adding KV cache and concurrency overhead, reserve 20GB or more. For a 14B-class model, start with a single 24GB card or use multi-card tensor parallelism. Embedding and reranking models use little GPU memory and can share a card with the main model, but watch for memory fragmentation.
Common pitfalls: a CUDA version inside the container that does not match the host driver, causing initialization failures; insufficient permissions on the weights directory; a port already in use; and timeouts on the first weight download (consider offline import or specifying an internal mirror source instead).
3. Layer 2: Embedding and Reranking Models
The ceiling on retrieval quality is determined by the vector representation. For the embedding model, choose a general-purpose option that supports Chinese, has a moderate dimension (768–1024), and covers long documents with its context length. Place the reranking model after recall to do fine-grained ordering over the candidate set; this typically moves Top-5 hit rate up by a clear notch.
The engineering principle is “recall wide, rerank narrow”: retrieve 50–100 candidates with vector search, then keep 5–10 after reranking to enter the context, balancing quality against token cost.
4. Layer 3: Document Understanding and Parsing Layer
When RAG results are poor, most problems come from parsing rather than the model. This layer must handle multiple formats: PDF, Word, Excel, scanned documents, and HTML. Core capabilities include layout analysis, table structure reconstruction, image and formula extraction, and semantic chunking.
Practical advice: chunk by document structure rather than by a fixed word count, with a chunk size of 300–800 tokens and 10%–20% overlap. Keep metadata such as the heading path and page number for each chunk to support citation traceability and permission filtering.
5. Layer 4: Orchestration and Application Interface Layer
The orchestration layer provides knowledge base management, retrieval testing, prompt templates, workflows, and an external API. Recommended capabilities: multi-knowledge-base isolation, hybrid retrieval (vector + keyword), citation display, conversation memory, sensitive-word and access control, and a visual debugging panel. For the interface layer, standardize on an OpenAI-compatible style so the business side can integrate without changes.
6. Layer 5: Operations and Observability
Production environments must add the following: a logging service to collect call chains, monitoring and alerting that covers GPU memory and queueing latency, object storage to keep original documents and index snapshots, and a container platform to handle elastic scaling. Rebuild indexes incrementally every day and fully once a week, and keep rollback versions.
7. Deployment Order and Acceptance Checklist
Recommended order: inference platform → embedding and reranking models → document parsing and vector store → orchestration layer → gateway and observability.
Acceptance looks at four things: first-token latency, recall hit rate, citation accuracy, and error rate under concurrency. Once all pass, roll out to business traffic gradually.
8. Conclusion
The value of the five-layer architecture is decoupling: any layer can be replaced or upgraded independently without affecting the whole. Implemented with containers and paired with clear resource planning and an observability system, a team can get a stable, controllable, and auditable private retrieval-augmented environment within days. If you want to reduce the operational burden of self-hosting, you can also evaluate general-purpose capabilities from cloud vendors such as Baidu AI Cloud, including container platforms, object storage, and logging and monitoring, as the foundation.
