Back to blog
    RAG as a Modular Service: Why Retrieval Should Be Infrastructure, Not Embedded Code
    rag-pipelinearchitectureinfrastructureenterprise-aiai-agentssegment:enterprise

    RAG as a Modular Service: Why Retrieval Should Be Infrastructure, Not Embedded Code

    Most teams embed retrieval logic directly into their application code. When the RAG pipeline needs updating, it means redeploying the entire application. Treating RAG as modular infrastructure solves this.

    EErtas Team·

    Nobody embeds their database driver logic into their HTTP handler and calls it architecture. Databases became infrastructure decades ago — abstracted behind connection strings, query interfaces, and managed services. But for some reason, most teams building with retrieval-augmented generation are doing the equivalent of hardcoding SQL directly into their route handlers, except the "SQL" is chunking logic, embedding calls, vector search configuration, and reranking heuristics, all tangled into application code that has no business knowing about any of it.

    This is the coupling problem at the heart of most RAG implementations today, and it is quietly creating the same kind of technical debt that the industry spent years learning to avoid with databases, caches, and message queues.

    The Coupling Problem

    A typical RAG implementation looks something like this: the application receives a user query, the application code calls an embedding model to vectorize the query, the application code queries a vector database with specific search parameters, the application code applies reranking or filtering logic, the application code constructs a prompt with the retrieved context, and then the application sends that prompt to an LLM.

    Every one of those steps lives inside the application. The chunking strategy, the embedding model choice, the similarity threshold, the number of retrieved documents, the reranking algorithm — all of it is embedded in application code, often scattered across multiple files and functions.

    Now consider what happens when you need to change any of these decisions.

    You switch from one embedding model to a newer one with better performance. That is an application deployment. You adjust your chunking strategy because documents with tables were being split incorrectly. Application deployment. You add a metadata filter to restrict retrieval to documents from the last 90 days. Application deployment. You add a reranking step to improve precision. Application deployment.

    Every retrieval improvement requires a full application release cycle. The retrieval pipeline and the application share the same deployment boundary, the same CI/CD pipeline, the same rollback procedure. A bug in your reranking logic can take down your entire application. A regression in your chunking strategy requires rolling back application features that were shipped in the same release.

    This is not a theoretical concern. Teams building production RAG systems report that retrieval tuning — adjusting chunk sizes, experimenting with embedding models, tweaking search parameters — accounts for a significant portion of ongoing maintenance work. When that work is coupled to application deployments, it slows down both the retrieval team and the application team.

    The Database Analogy

    Consider how your application interacts with a PostgreSQL database. Your application does not contain the query planner. It does not manage index creation. It does not handle storage engine decisions. It connects to an endpoint, sends a query through a well-defined interface, and receives results. The database team can rebuild indexes, upgrade the engine, change the replication topology, and optimize query plans — all without the application team deploying anything.

    This separation exists because the industry learned, through painful experience, that coupling storage infrastructure to application logic creates systems that are fragile, slow to iterate on, and difficult to reason about.

    Retrieval is the same category of concern. It is infrastructure. It has its own performance characteristics, its own tuning parameters, its own failure modes, its own versioning requirements. Treating it as application code is an architectural category error.

    What RAG as a Service Looks Like

    A RAG retrieval API endpoint separates the retrieval pipeline from the application cleanly. The application sends a query. It receives ranked, relevant context. It does not know or care how that context was retrieved.

    Behind the endpoint, the retrieval service owns its own deployment lifecycle. The retrieval team can:

    • Swap embedding models without touching the application. Move from a general-purpose model to a domain-specific one, or upgrade to a newer architecture entirely. The API contract stays the same.
    • Change chunking strategies per document type. Legal contracts get one chunking approach, technical documentation gets another, customer support transcripts get a third. The application never knows.
    • Add or remove reranking stages. Start with vector similarity only, then layer in cross-encoder reranking, then add metadata boosting. Each change is an independent deployment.
    • Version retrieval pipelines. Run v1 and v2 side by side. Route 10% of traffic to the new pipeline. Compare retrieval quality metrics. Promote or roll back without any application changes.
    • Instrument independently. Track retrieval latency, relevance scores, cache hit rates, and embedding throughput as first-class operational metrics, separate from application-level observability.

    This is what a RAG pipeline with tool-calling spec integration enables for AI agents. The agent does not contain retrieval logic. It calls a retrieval tool through a standardized interface. The retrieval service behind that tool can evolve independently.

    Why Enterprises Need This Separation

    For enterprise teams evaluating RAG as a service on-premise, the separation between retrieval infrastructure and application code is not optional — it is a governance requirement.

    Auditability. When retrieval is a separate service, you can audit exactly what was retrieved for any given query. You can log the retrieval pipeline version, the documents considered, the ranking scores, and the final context passed to the model. This audit trail lives in the retrieval service, not scattered across application logs.

    Access control. Different document collections may have different access policies. The retrieval service can enforce document-level permissions centrally, rather than requiring every application to implement its own access control logic around retrieved content.

    Data residency. When the retrieval pipeline is a deployable service, you control exactly where it runs. On-premise deployment of the retrieval layer means embeddings, vectors, and document content never leave your infrastructure, even if the application layer uses a cloud-hosted LLM for generation.

    Independent scaling. Retrieval workloads and generation workloads have different resource profiles. Embedding and vector search are compute-intensive but fast. LLM generation is slower and memory-intensive. When these are separate services, you scale each independently based on its actual resource demands.

    How Ertas Treats Retrieval as Infrastructure

    Ertas approaches retrieval as a deployable pipeline that is architecturally separate from the applications that consume it. The retrieval pipeline — document ingestion, chunking, embedding, indexing, and search — is a managed service with its own configuration, versioning, and deployment lifecycle.

    When an Ertas-powered application or agent needs context, it calls the retrieval pipeline through a defined interface. The application specifies what it needs: a query, optional filters, a desired number of results. The pipeline handles how to fulfill that request, including which embedding model to use, how to search, whether to rerank, and which document collections to query.

    This means the team managing document ingestion and retrieval quality can iterate independently of the team building the user-facing application. Chunking strategies can be refined. Embedding models can be upgraded. New document collections can be indexed. None of these changes require application redeployment.

    For teams deploying on-premise, the retrieval pipeline runs entirely within their infrastructure. Document content, embeddings, and vector indexes stay on-site. The pipeline can be configured to work with the organization's existing document stores, pulling from file shares, content management systems, or internal databases without requiring data migration to external services.

    The Architectural Principle

    The pattern here is not novel. It is the same principle that drove the separation of databases, caches, message queues, and authentication services from application code. Infrastructure concerns deserve infrastructure treatment: dedicated services with defined interfaces, independent deployment lifecycles, and specialized operational tooling.

    Retrieval is infrastructure. It has been masquerading as application code because the RAG pattern is relatively new and teams defaulted to the fastest path to a working prototype. But prototypes become production systems, and production systems need architectural boundaries.

    The teams that draw this boundary early — treating their RAG pipeline as a modular, independently deployable service rather than code embedded in their application — will iterate faster on retrieval quality, deploy application changes with less risk, and maintain cleaner operational visibility into both systems.

    The teams that do not draw this boundary will eventually reach the same conclusion the industry reached about databases thirty years ago: infrastructure belongs in infrastructure, not in application code. The only question is how much coupling they accumulate before making the change.

    Turn unstructured data into AI-ready datasets — without it leaving the building.

    On-premise data preparation with full audit trail. No data egress. No fragmented toolchains. EU AI Act Article 30 compliance built in.

    Keep reading