# Anyone can build a RAG demo; what counts is getting it into production

Date: 2026-11-20
Category: Technology
Tags: RAG, Agent, Open Source, Private Deployment
Summary: A RAG demo for an enterprise knowledge base can be up and running in a few hours. The hard part is the work that only surfaces in production: authentication, quotas, auditing, data masking, model switching. This article uses an open-source reference implementation to break down this engineering checklist and explain which scenarios are worth following it for.

It's not hard to build a demo that answers questions in two weeks for an enterprise knowledge base project: upload a few PDFs, chunk them, vectorize them, hook up an LLM, and a single chat box can answer questions about company policies. What usually stalls the project is the next step. Security asks who can access which corpora, IT asks where the model keys are stored, compliance asks whether a wrong answer can be traced back to the source text, and ops asks how quotas and audit logs are viewed. None of this has anything to do with retrieval algorithms, but each one is enough to keep the project stuck in an intranet pilot.

I increasingly feel that the dividing line for private RAG isn't retrieval quality, but the string of engineering work after the demo that nobody wants to write. I recently came across an open-source project called AgentDesk that finishes this stretch of work, and it happens to work well as a checklist for explaining what separates "can answer" from "can be used."

## A demo that can answer and a production system that can be used are two different things

Laying out the gap between the two states makes it clearer where the money and time go.

| In the demo | At launch | The real blocker |
| --- | --- | --- |
| One chat box, anyone can ask | Restrict visible corpora by department and role | Enterprise identity system (OIDC/JWKS), role-based access control (RBAC) |
| Model keys written in environment variables | Key rotation without restart, backend never returns plaintext | Encrypted storage plus cache that takes effect live |
| Answers look right, that's enough | Every sentence traceable to its source | Citation tracing plus refusal when there's no basis |
| Logs printed to the terminal | Who asked what and when, replayable | Audit logs plus call quotas |
| Sensitive words constrained by prompts | Interception and masking on both input and output | Rules configured in the backend and effective immediately |

Every item in this table is not hard on its own; what's hard is that they must all hold at the same time, and be deliverable inside the customer's intranet. Most open-source RAG projects stop at the first column and leave the second for users to fill in themselves. The filling-in process brings no technical thrill, yet it determines whether the project passes acceptance.

AgentDesk belongs to the category that finishes the second column outright. It's a reference implementation of a privatizable RAG knowledge base plus Agent runtime, built on the Mastra Agent framework, with a full chain of document upload, chunking and vectorization, streaming Q&A, citation tracing, auditing, and quotas.

## It lays out the entire set of services

One easily misunderstood point needs to be made clear first: it's not a software development kit (SDK), but a complete set of services that can actually run. The business backend, chat frontend, admin console, Agent runtime, and deployment orchestration are all in the repository.

| Application | Responsibility | Tech |
| --- | --- | --- |
| agentdesk-api | The sole business backend: auth, sessions, quotas, orchestration, auditing | Go + Gin + GORM |
| agentdesk-chat | Chat frontend: streaming answers, citation display, mobile pages | React 19 + Vite |
| agentdesk-admin | Admin console: corpus upload, model config, quota auditing, security policies | React 19 + shadcn/ui |
| agentdesk-agent | RAG retrieval, vectorization, tool calls, intranet-only | Mastra + pgvector |
| deploy/ | Local and production deployment templates | Docker Compose + Traefik |

![AgentDesk admin console and mobile chat interface](/img/agentdesk/ad-ui-stack.png)

The two frontends share the same set of blue semantic color variables, so changing the theme touches only one cascading style sheet (CSS). The admin console uses Tailwind v4's oklch semantic colors with dark mode, and charts and metric cards follow the primary color through compatible variables; the chat frontend uses CSS custom properties, where the brand gradient, user bubbles, send button, and input focus border are all the same blue. The implementation details aren't complex, but for internal enterprise tools it's very practical: no need to redo a visual system for every project, and light and dark themes are both solved at the variable level.

## Where a single Q&A goes internally

The claim that data never leaves the intranet only counts once it lands on concrete call boundaries. AgentDesk's approach is that the Agent runtime is not exposed to the public internet and is called only by the Go backend via an intranet address; PostgreSQL and its vector extension pgvector, Redis, and object storage can all be deployed privately; the model address is configured by the user, and can be a cloud vendor or a self-hosted inference gateway.

![AgentDesk deployment architecture](/img/agentdesk/ad-pro-architecture.png)

The full chain of a single question is worth walking through.

![RAG Q&A request chain swimlane diagram](/img/agentdesk/ad-swimlane.png)

The question first passes input safety checks, then vector retrieval; if retrieval is empty, it directly returns a custom refusal message without calling the chat model at all; only when there's a basis does it generate an answer, and the output is masked as it streams back via server-sent events (SSE), with an audit record left behind. This chain turns "can the answer be trusted" into a series of checkable steps rather than hoping the model behaves. The low-confidence fallback and the no-basis refusal are two different gates: the former handles cases where retrieval found something but it isn't good enough, the latter handles cases where nothing was retrieved at all, and lumping them together would miss half the scenarios. Without these two gates, the model will confidently produce paragraphs that sound like sources when there's no basis; such errors are hard to spot during the demo stage and only surface when employees act on them.

## How models and keys are backed up

Bring-your-own-key (BYOK) is, in my view, the design most worth copying from this system. Chat, embedding, and vision models are configured independently, and anything with an OpenAI-compatible interface can be connected, treating cloud services and self-hosted gateways the same. Neither addresses nor keys are written into source code or images; they're encrypted and stored in the database.

A few details show the authors have been through the pitfalls: keys are encrypted with AES-256-GCM, and the admin API returns only a boolean flag for whether a key is set, never the plaintext; leaving the input box empty means not modifying the existing key; after saving, the Agent side caches it and it takes effect automatically in about fifteen seconds, so switching providers or rotating keys requires no restart; the Go backend and the Agent runtime must be configured with the same encryption key, and changing this value invalidates all stored keys, requiring re-entry. These constraints keep both rotation cost and exposure surface very low. There's also a magnitude easily overlooked during technology selection: the embedding dimension is controlled by an environment variable, defaulting to 1536, while pgvector's hierarchical navigable small world (HNSW) index has an upper limit of 2000, beyond which you have to switch index schemes.

On the content security side, sensitive words are split into two levels: warning and prohibited. On the input side, you can choose to show a prompt but continue, or block and refuse outright. Output masking is done during streaming returns, and a small tail buffer is kept to catch terms that span chunks; otherwise, if a word is split into two parts and sent to the frontend, it can't be blocked. Rule changes made in the backend take effect immediately, and there's a test panel where you can see hit results before deciding to go live. There's a design choice on the page that I think is very practical: HTTP tools registered as such execute on the server, accept only http or https addresses, have timeouts and output character limits, and the documentation explicitly states they should only connect to trusted intranet interfaces. Writing tool-call permission boundaries into the documentation is more effective than repeating "pay attention to security" a hundred times in the prompt.

```json
{
  "method": "POST",
  "url": "https://internal.example.com/api/order?q={{query}}",
  "headers": { "Authorization": "Bearer {{token}}" },
  "input_schema": {
    "type": "object",
    "properties": { "query": { "type": "string", "description": "用户问句" } },
    "required": ["query"]
  },
  "response_path": "data.items",
  "timeout_ms": 8000,
  "max_output_chars": 4000
}
```

In this configuration, placeholders are replaced at call time with the parameters given by the model, response fields are extracted using dot paths, and output has a character limit to avoid blowing up the context. The only built-in tools are current time and knowledge base retrieval; they are enabled by default with database migration, and can be disabled but not deleted.

## How high is the onboarding cost really?

Deployment orchestration is in the deploy directory, with a template based on Docker Compose plus Traefik. The shortest path is to copy several environment variable samples, change the configuration for the database, Redis, object storage, identity system, and encryption key, and then start the containers.

```bash
cd deploy
cp .env.example .env
cp agentdesk-api.env.example agentdesk-api.env
cp agentdesk-agent.env.example agentdesk-agent.env
docker compose up -d --build
```

Then go into the business backend directory and run a database migration once. After it starts, there are three entry points: the chat frontend on port 5173, the operations admin on port 5174, and the Go API health check on port 8080. The most common pitfall here is still the encryption key mentioned earlier: the two services must be configured with the same value, otherwise the Agent cannot decrypt the keys stored by the admin, and the knowledge base and Q&A features will simply be unusable. Vector embedding dimensions are an operations-level configuration, defaulting to 1536; if you change it, you must rebuild the vector index, so don't wait until the vectors are full to find out.

## What scenarios are worth following, and when should you stay away

It explicitly does not bind itself to a single industry. The e-commerce content that appears in the repository is all fictional examples; the code itself has no product, order, or transaction logic. According to the public documentation, five categories fit well: enterprise knowledge assistants, customer service and pre-sales Q&A, channel partner enablement, compliant content generation, and documentation preview sites. The documentation preview site is another independent static site example; the first four categories draw on the same set of capabilities, but each relies more heavily on different components. Enterprise knowledge assistants need multi-library retrieval and incremental updates; customer service Q&A relies on streaming dialogue, fallback scripts, and multi-turn memory; channel enablement needs permission tiers and Q&A auditing; compliant content generation uses pre-input sensitive-word blocking plus script templates. Mapping scenarios to components is the only way to judge whether this system really fits.

In my judgment, there are two cases where you don't need it. One is if you only want to know how to tune vector retrieval for better accuracy; this system is too heavy for that, and building a prototype directly with Mastra or LangChain is faster. The other is a purely external, high-concurrency chat product; its design focus is intranet controllability and enterprise acceptance, not throughput and elasticity at that scale. There is also an intermediate case to watch for: if you don't have the conditions for private deployment and data must remain in a public cloud managed service, then the biggest selling point—data never leaves the intranet—is lost, and you need to see whether the remaining capabilities are still worth the deployment cost.

If your question stops at how to make retrieval more accurate, this reference implementation has little value. But if what you need to answer is how to hand this knowledge base to the whole company, with security, compliance, and auditability all clearly explained, then starting from a project that has already completed the second column of the checklist saves far more than filling it in from scratch. The code is at https://github.com/bl8ds/AgentDesk-Private-Deployable-Knowledge-Base-Agent-Platform and is MIT licensed. I suggest reading the constraints in the design document and the checklist in the deployment guide first, then deciding whether to build on it.
