跪拜 Guibai
← All articles
Artificial Intelligence

Aligning the RAG Boundary: What Stays in the Retrieval Service and What Moves to the Agent

By 满眼星河 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

RAG systems fail in production when retrieval services quietly absorb agent responsibilities such as query rewriting and answer generation; this scope definition gives teams a concrete checklist for where to put each function. That separation keeps retrieval fast, auditable, and permission-safe while the agent handles the reasoning loop.

Summary

A RAG application works cleanly only when the retrieval service and the agent have hard boundaries. A standalone retrieval service handles the offline document pipeline, chunking and embedding, hybrid retrieval, reranking, permissions, and evaluation. It returns raw chunks with metadata, never generated answers. The agent above it owns query rewriting, sub-question decomposition, deciding whether to search, multi-turn retrieval, and hallucination checks.

The service separates into five required blocks: ingestion connectors and parsing, index management, online retrieval APIs, enterprise governance, and observability. Each has specific production defaults: dual vector and full-text indexes, hybrid BM25 plus dense retrieval with RRF fusion, ACL filtering at the document level, Redis query caching, and reranking with timeout degradation. The enterprise layer adds content moderation, desensitization, and a web console for manual debugging.

Advanced capabilities such as GraphRAG and multimodal retrieval are optional, not baseline. The operational rule is to avoid coupling: keep parsing, chunking, retrieval, and permission filtering inside the retrieval service, and push query rewriting, answer generation, and loop decisions into the main agent.

Takeaways
— The retrieval service covers only ingestion, indexing, retrieval API, governance, and observability; query rewriting, sub-question decomposition, multi-turn retrieval decisions, answer generation, and hallucination checking live in the main agent.
— Ingestion supports PDF, Word, Excel, PPT, Markdown, txt, epub, and scanned files from object storage, crawlers, APIs, databases, Git, OA/SharePoint/Jira, with incremental sync via polling, webhooks, or message queues.
— Chunking strategies include fixed-length, recursive, heading-aware, semantic, table-independent, and section-boundary splitting with overlapping windows.
— Indexing uses a vector database (Milvus/Qdrant/pgvector) plus full-text search (ES/Elasticsearch) in a dual-index setup with hot/cold lifecycle and TTL cleanup.
— Online retrieval combines dense vectors and BM25 with RRF fusion, supports metadata and document-level ACL filtering, and returns unified chunk metadata.
— Reranking first recalls topN (20-50), reranks, and returns topK, with timeout degradation to the coarse recall results.
— Production safeguards include Redis query caching, rate limiting, concurrency control, circuit breaking, and automatic degradation when the vector DB or ES fails.
— Enterprise features cover knowledge-base and document-level ACLs, API Key/JWT/SSO auth, content moderation, sensitive-word filtering, and data desensitization.
— Observability includes per-request tracing with LangFuse/LangSmith, Prometheus/Grafana metrics, and offline evaluation with Ragas/DeepEval for context recall, precision, and faithfulness.
— Advanced optional extensions are multimodal retrieval, GraphRAG knowledge-graph search, summary-index assisted retrieval with original chunks still returned, and PDF citation positioning with coordinates.
Conclusions

Separating retrieval from agent logic changes the failure model: the retrieval service stays deterministic and cheap, while every query rewrite or extra loop costs an LLM call inside the agent.

Calling hybrid search with RRF, document-level ACL filtering, and rerank degradation "industry standard" or "must add in production" makes this a baseline for enterprise deployment, not an experimental design.

Putting GraphRAG and multimodal retrieval in an optional extensions section suggests teams should first stabilize ingestion, search, permissions, and evaluation before adding graph or vision complexity.

Concepts & terms
RAG
Retrieval-Augmented Generation, a pattern where a model generates answers using retrieved document chunks; in this design, retrieval and generation are split into separate services.
RRF
Reciprocal Rank Fusion, a method for combining ranked lists from different retrieval systems by summing reciprocal ranks, used here to merge dense vector and BM25 results without tuning scores.
ACL
Access Control List, a permission rule set attached to documents or knowledge bases; retrieval APIs filter chunks based on user identity before returning results.
Hybrid search
Combining dense semantic vector retrieval with sparse keyword retrieval (BM25) to cover both meaning and exact terms.
GraphRAG
A retrieval approach that uses an entity-relation knowledge graph to retrieve subgraphs alongside vector search, useful for queries connecting equipment, procedures, and defects.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗