Enterprise RAG Knowledge Base: A Hybrid Architecture with Two Engines

    This article explains why enterprise RAG deployments benefit from separating document parsing from application orchestration, and how to combine both through standard interfaces. It covers evaluation criteria for each layer, Docker port mapping and networking preparation, integration contracts and code examples, retrieval quality practices, common pitfalls, and the key conclusion that capability layering avoids vendor lock-in.

    1. The Real Problem: Not Either/Or, but Capability Layering

    When teams build a retrieval-augmented generation (RAG) knowledge base in an enterprise, the most common debate is “which framework should we pick?” Abstract the problem one level up, and the real decision is between two orthogonal capabilities:

    • Deep document parsing: turning PDFs, scanned files, complex tables, and mixed text-and-image layouts (“dirty data”) into structured, retrievable chunks.
    • Application orchestration: chaining retrieval, reranking, tool calls, multi-model collaboration, and human approval into a deliverable business workflow.

    The first capability optimizes for parsing accuracy and throughput; the second optimizes for usability, observability, and iteration speed. Because their optimization goals differ, a “single framework does everything” approach usually compromises on one side. The value of a hybrid architecture is that each layer runs on the implementation that does it best.

    1.1 How to Evaluate the Parsing Layer

    When assessing a document parsing engine, look at five things: layout reconstruction (multi-column pages, header and footer removal), table structuring, OCR quality, how configurable the chunking templates are, and latency under heavy load. In enterprises with a high share of complex documents (contracts, financial reports, drawings, medical records), parsing errors amplify along the chain and eventually surface as answers that miss the question.

    1.2 How to Evaluate the Orchestration Layer

    For the orchestration layer, evaluate: visual workflow building, the agent and tool ecosystem, cross-knowledge-base routing (automatically selecting retrieval targets based on the question), multi-model integration and switching, and how modular the layer is for secondary development. Cross-base routing is often underestimated—when an enterprise has dozens of business knowledge bases, the lack of routing directly causes recall noise.

    1.3 What Layering Buys You

    Once capabilities are separated: complex applications are carried by the orchestration layer; parsing quality is guaranteed by a specialized engine; the two sides are decoupled through standard interfaces, so either side can be upgraded or replaced independently, avoiding vendor-lock-in coupling.

    2. Network and Port Preparation Before Deployment

    Both types of components are usually deployed as containers, and the most common problem when they coexist on one host is a port conflict. A Docker Compose port mapping is written as A:B, where A is the host port and B is the container port; inside a container, 80 is typically used for HTTP and 443 for HTTPS. If both systems map 80/443, whichever starts first takes the port and the second one fails.

    The recommended approach: change only the host port and keep the container port unchanged, so you do not break the application’s built-in assumptions about its external address.

    1. # Example: remap ports on the parsing service side, container ports unchanged
    2. ports:
    3. - "8080:80" # host 8080 -> container 80 (HTTP)
    4. - "8443:443" # host 8443 -> container 443 (HTTPS)

    Also keep three points in mind. First, the reverse proxy needs to split traffic by different domains or path prefixes. Second, if the orchestration layer reaches the parsing layer over an API, use the service name inside the container network rather than the host port, which removes one NAT hop. Third, define health checks and timeout thresholds explicitly; parsing large files is a long-running task, so timeouts should be relaxed and paired with asynchronous task queries.

    3. Integration Design: Decoupling Through Standard Interfaces

    The key to a hybrid architecture is not “installing two systems side by side” but defining clear contracts.

    1. Knowledge base lifecycle: document upload, parsing status queries, and deletion go through the parsing-side interfaces.
    2. Retrieval interface: inputs are the query text, knowledge base identifier, Top-K, and similarity threshold; outputs are chunk text, source location, and score.
    3. Orchestration-side wrapper: wrap the calls above as a single “retrieval tool” that agents and workflow nodes can reuse.
    1. # Example: wrapper for calling the parsing side's retrieval capability from the orchestration layer
    2. def retrieve(query: str, kb_id: str, top_k: int = 6, threshold: float = 0.35):
    3. resp = requests.post(
    4. f"{PARSE_ENGINE_BASE}/api/retrieval",
    5. json={"question": query, "kb_ids": [kb_id],
    6. "top_k": top_k, "similarity_threshold": threshold},
    7. timeout=30,
    8. )
    9. resp.raise_for_status()
    10. chunks = resp.json().get("chunks", [])
    11. return [c for c in chunks if c.get("score", 0) >= threshold]

    Engineering details: run batch parsing as asynchronous tasks with callbacks or polling; normalize retrieval results into a “source + chunk + score” triple so upper layers can rerank and add citations; compress overly long context a second time to control token cost.

    4. Retrieval Quality and Engineering Practices

    • Layered chunking strategy: split well-structured documents by heading hierarchy, and keep tables as separate blocks with their headers preserved.
    • Hybrid retrieval: run keyword recall and vector recall in parallel, then fuse and rerank, which reduces missed recall for proper nouns and identifier-style queries.
    • Reranking and thresholds: introduce a reranking model; a threshold that is too low brings in noise while one that is too high produces empty answers, so calibrate it with a business Q&A set.
    • Cross-base routing: use a lightweight classifier to decide the target base first, then retrieve, avoiding a full scan across all bases.
    • Evaluation loop: build a regression set of 100–300 real question-answer pairs and track recall rate, citation accuracy, and empty-answer rate.
    • Observability: log and alert on parsing time, retrieval latency, failure rate, and token consumption; when capacity runs short, scale the stateless retrieval nodes on the parsing side horizontally first.

    5. Common Pitfalls

    One is mistaking a parsing quality problem for a model problem and repeatedly swapping the generation model. Another is waiting synchronously for large-file parsing, which causes requests to pile up. A third is missing citation traceability, so users cannot verify answers. A fourth is an absent permission model: if the retrieval layer does not filter by document-level permissions, there is a risk of unauthorized access. Permissions should be injected as a mandatory retrieval input, not patched after generation.

    6. Conclusion

    The robust path for enterprise RAG is capability layering: a specialized parsing engine handles “understanding the document,” and an orchestration engine handles “making the workflow run,” with the two decoupled through standard interfaces and the container network. If you need lighter-weight semantic indexing or graph-based augmentation, you can keep layering general-purpose options onto the retrieval layer instead of rebuilding the whole architecture.