RAG Productization: Five-Layer Architecture and Deployment Practices
This article presents a five-layer architecture for RAG productization, covering unified model inference, document understanding and chunking, hybrid retrieval and reranking, orchestration, container deployment pitfalls, and evaluation. It explains how to turn a working RAG pipeline into a stable, observable, and deliverable system.
1. “It Runs” Does Not Mean “It Ships”
Many teams can get a RAG pipeline running in a few days: start an inference service, load a batch of documents, and connect a Q&A interface. But once the project enters delivery, problems tend to surface all at once: broken document parsing, inaccurate retrieval, answers without citations, timeouts under concurrency, and total data loss after a restart. The root cause is often not that the model is insufficiently strong, but that the pipeline is treated as a one-off script rather than a layered system.
The core of RAG productization is encapsulating model capabilities as stable engineering capabilities. The following sections describe a five-layer structure.
2. Layer 1: Unified Model Inference Service
RAG requires three types of models to work together: generation models, embedding models, and reranking models. If each model type runs its own service with its own interface, the application layer falls into integration hell. A better approach is to introduce a unified inference gateway that registers different models as addressable service endpoints and exposes a consistent protocol upward.
# Layered deployment illustration (not tied to a specific product)services:inference-gateway: # Unified inference entry point for multiple model typesports: ["<inference-port>"]volumes: ["./models:/models"] # Persist model weightsresources: { gpus: all }doc-parser: # Document parsing and chunkingdepends_on: [inference-gateway]vector-store: # Vector and metadata storageorchestrator: # Orchestration and Q&A entry pointdepends_on: [doc-parser, vector-store, inference-gateway]
Practical considerations:
- VRAM is a hard constraint. Generation, embedding, and reranking models resident at the same time can easily exceed single-GPU capacity. Validate with a small batch first, then allocate resources so that the generation model has exclusive use of the primary GPU while embedding and reranking share a secondary GPU.
- Model sources must be selectable. Weight download sources vary widely in speed, so support loading from an internal mirror or local directory to avoid deployment being bottlenecked by external bandwidth.
- Define interface contracts first. Fix the request and response structures for generation, embedding, and reranking so that changing models later does not require application code changes.
3. Layer 2: Document Understanding and Chunking
The upper bound of RAG quality is determined by data quality, and data quality is already set during parsing. PDF tables spanning multiple pages, scanned documents without a text layer, and headers and footers mixed into body text can all cause downstream retrieval to lose focus entirely.
From an engineering perspective, you should:
- Route by format: Plain text, tables, and scanned documents should follow different parsing paths. Do not expect a single parser to handle everything.
- Preserve structure: Heading hierarchy, lists, and tables should be retained as structured metadata rather than flattened into a plain text paragraph.
- Make chunking configurable: Chunk size and overlap ratio need to be adjusted by document type. Technical manuals can use larger chunks, while Q&A-style documents should use smaller ones.
- Keep metadata attached: Source file, page number, section, and update time must be written into metadata. This is the only basis for grounded citations later.
4. Layers 3 and 4: Hybrid Retrieval and Reranking
Vector similarity alone performs poorly in scenarios dense with proper nouns, model numbers, and identifiers. A reliable approach is hybrid retrieval: keyword retrieval handles exact matches, vector retrieval handles semantic generalization, and the two result sets are fused and then passed to a reranking model for refined ordering.
candidates = fuse(keyword_topK, vector_topK)final_results = rerank(candidates)[:N]
The reranking model is one of the highest-return components: it does not require retraining and simply corrects the candidate set from coarse order to refined order, often significantly improving citation accuracy in answers. Note that reranking is compute-intensive, and an overly large candidate set directly increases latency. TopK should be selected after load testing.
5. Layer 5: Orchestration and Product Delivery
The orchestration layer connects the capabilities above into a product: knowledge base management, document upload and parsing status display, conversation context management, citation traceability, and permission isolation. This layer determines the user experience and is also the easiest to overlook during demos.
When deploying in containers, three pitfalls are almost guaranteed:
- Data is not persisted: Only the model directory is mounted, while the vector store and metadata directories are not. After the container is rebuilt, the knowledge base is wiped. All stateful directories must be explicitly mounted.
- Ports and health checks are missing: The service starts, but dependencies are not ready, so the orchestration layer fails at startup. Dependency order and readiness probes must be configured.
- Logs are unavailable: When problems occur in a multi-container pipeline, without unified logs and monitoring alerts, you can only guess. At a minimum, aggregate container logs into a unified logging service and set threshold alerts for VRAM usage, request latency, and failure rate.
6. Evaluation: Turning “Feels Good” into Metrics
Productization must be measurable. At minimum, track four categories of metrics: retrieval-layer recall and hit ranking, generation-layer answer faithfulness and relevance, system-layer time to first token and end-to-end latency, and cost-layer resource consumption per Q&A. Build an evaluation set with ground-truth answers, and run a regression whenever chunking parameters, TopK, or model versions change, so you avoid fixing one scenario while breaking three others.
7. Conclusion
The hard part of RAG productization is never model selection. It is layered decoupling, data governance, and operability. By making the five layers of inference, parsing, retrieval, reranking, and orchestration replaceable, observable, and persistent, and by combining them with quantitative evaluation and continuous regression, a one-off demo can become a sustainable product capability.
