How To · LLM TechniqueIntermediate

How to Build an AI Agent That Follows Your Organization's RAG

How to build an AI agent grounded in your organization's knowledge with retrieval-augmented generation: corpus design, chunking, hybrid retrieval, permissions, agentic RAG, and evaluation.

Document pipelineEmbeddingsHybrid searchRe-rankerLLM with tool use15 min · 6 steps · Updated 2026-06-02
The short answer

To build an AI agent that follows your organization's knowledge, build a retrieval-augmented generation (RAG) pipeline: ingest and chunk internal documents with metadata, index them with hybrid (vector + keyword) search, filter results by the asking user's permissions, and have the agent retrieve, cite, and reason over those chunks — refusing to answer when retrieval comes back empty.

What you’ll build

  • A hybrid retrieval pipeline (vector + keyword + re-ranker) over your internal docs
  • An agent that cites sources on every claim and refuses when retrieval is empty
  • Query-time permission filtering wired to your identity provider
  • An agentic loop that handles multi-hop questions with iterative search
  • A golden-set evaluation harness with weekly hit-rate and groundedness scores

Before you start

  • 01Read access to two or three priority knowledge sources, with their ACLs
  • 02An embedding model plus a vector store and a keyword (BM25) index
  • 03Identity provider integration to resolve users and group memberships
  • 04An LLM endpoint that supports tool use / function calling
  • 0550+ real employee questions with verified answers for the golden set

Key takeaways

  • 01

    RAG quality is determined more by corpus hygiene and chunking than by model choice — a better model cannot compensate for retrieving the wrong text.

  • 02

    Hybrid retrieval (dense vectors + BM25 keyword) with a re-ranker outperforms either method alone on enterprise queries, especially for IDs, acronyms, and product names.

  • 03

    Permission filtering must happen at query time against live ACLs; baking permissions into the index goes stale the moment access changes.

  • 04

    Agentic RAG — letting the model decide when to search, reformulate queries, and iterate — beats single-shot retrieval on multi-hop questions by a wide margin.

  • 05

    An enterprise agent must be instructed to answer only from retrieved context and to say "I don't know" on empty retrievals; this single rule eliminates most hallucinated policy answers.

01

What "following your organization's RAG" actually means

A general-purpose LLM knows the world; it knows nothing about your travel policy, your deployment runbook, or which discount tiers sales can offer. Retrieval-augmented generation closes that gap by fetching relevant internal content at question time and instructing the model to answer from it — turning the model from a confident generalist into a grounded specialist that cites sources.

The "agent" framing adds one more layer: instead of a fixed retrieve-then-answer pipeline, the model itself decides when to search, what to search for, and whether the results are sufficient — looping until it can answer or honestly conclude that it cannot.

02

Corpus design: where RAG projects are won or lost

Most failed RAG deployments fail at the corpus, not the model. Indexing everything indiscriminately fills the store with duplicates, drafts, and obsolete policies — and retrieval faithfully surfaces that garbage. Start narrow: pick the two or three sources that answer the most actual questions (usually the HR policy space and the engineering wiki), and expand only after quality is proven.

Treat metadata as a first-class citizen. Every chunk should carry its source URL, document owner, last-modified date, and access-control list. Freshness metadata enables recency boosts; ownership enables "ask the owner" escalation; ACLs enable permission filtering. Retrofitting metadata after indexing is far more painful than capturing it on ingest.

03

Chunking and embedding choices

Chunking is the highest-leverage tuning knob in the pipeline. Fixed-size splitting tears tables from their headers and steps from their procedures; structure-aware splitting along headings and paragraphs keeps semantic units intact. Aim for 300–800 tokens with 10–15% overlap, and always prepend the document title and heading path to the chunk text — the embedding then encodes context that the raw chunk lacks.

For embeddings, modern general-purpose models are sufficient for most corpora; domain fine-tuning matters less than getting chunking and hybrid retrieval right. Re-embed the corpus when you change models — mixed-model indexes silently degrade similarity.

04

Hybrid retrieval and re-ranking

Dense vector search excels at paraphrase ("how much PTO do I get" → vacation policy) but is weak on exact tokens — error codes, SKUs, acronyms, people's names. Keyword search (BM25) has exactly the opposite profile. Enterprise queries are full of exact tokens, so run both and merge with reciprocal rank fusion; then apply a cross-encoder re-ranker over the merged top ~50 to produce the final 5–10 chunks.

This three-stage pattern — broad hybrid recall, precise re-rank — is the de facto standard because it is cheap where volume is high and accurate where it counts. Measure it with retrieval hit rate against a golden set before ever debugging the generation side: if the right chunk is not in the top 10, no prompt will save the answer.

05

Permissions: the enterprise deal-breaker

The fastest way to get a RAG agent banned is answering a salary-band question from a restricted HR doc. Permission filtering must be enforced server-side at query time: resolve the asking user's identity, fetch their live group memberships, and filter candidate chunks against each document's ACL before anything reaches the model.

Two non-negotiables. First, filter before generation, not after — a model that has seen restricted text can leak it in paraphrase. Second, make empty-after-filtering indistinguishable from genuinely-empty retrieval, so the agent never reveals that a restricted document exists.

06

From pipeline to agent: agentic RAG

Single-shot retrieval handles single-hop questions. Real questions are messier: "compare our parental leave to the new policy draft" needs two searches; "why did checkout latency spike last week" needs a search, a follow-up, and synthesis. Agentic RAG exposes retrieval as a tool: the model writes its own queries, inspects results, reformulates, and searches again until it has enough to answer.

Constrain the loop — maximum 3–5 retrieval calls, a token budget, and required citations on every factual claim. Add a final groundedness instruction: if the answer is not supported by retrieved chunks, say so and name the document owner to ask. An agent that reliably says "I don't know, ask the policy owner" earns more trust than one that always answers.

07

Evaluation and the improvement loop

Build a golden set of at least 100 real questions with verified answers and source documents, stratified across departments. Track three numbers weekly: retrieval hit rate (right chunk in top 10), answer groundedness (claims supported by retrieved text), and deflection (questions resolved without human escalation). Wire user feedback into a triage queue — and notice that most thumbs-down answers trace to corpus problems (stale doc, missing doc, duplicate) rather than model problems. The loop that fixes documents, not prompts, is the loop that compounds.

Step-by-step build

  1. 1

    Inventory and prioritize the corpus

    Catalog knowledge sources (wikis, drives, tickets, policies), rank them by query value and freshness, and start with the two or three sources that answer the most real employee questions.

  2. 2

    Build the ingestion pipeline

    Extract clean text per format, preserve heading structure and metadata (owner, date, ACL, source URL), and re-ingest incrementally on document change events.

  3. 3

    Chunk with structure awareness

    Split along heading and paragraph boundaries into 300–800 token chunks with modest overlap, prepending each chunk with its document title and heading path.

  4. 4

    Index with hybrid retrieval

    Embed chunks into a vector store and index the same chunks in a keyword engine; at query time run both, merge with reciprocal rank fusion, and re-rank the top ~50 down to 5–10.

  5. 5

    Wire the agent with retrieval as a tool

    Expose search as a tool the LLM calls with self-written queries, allow iterative re-querying, enforce permission filters server-side, and require citations on every claim.

  6. 6

    Evaluate and close the loop

    Build a golden set of 100+ real questions with known answers, track retrieval hit rate and answer groundedness weekly, and route thumbs-down answers into a triage queue that fixes the corpus, not just the prompt.

Common pitfalls

The mistakes that show up in real deployments — each one costs a week if you learn it the hard way.

Boiling the ocean at ingest

Indexing every wiki space and shared drive on day one buries good answers under stale duplicates. Start with the two sources that answer the most real questions; expand only after hit rates hold.

Fixed-size chunking

Splitting every 500 characters tears tables from headers and steps from procedures. Chunk along heading boundaries and prepend the title path — it is the single highest-leverage retrieval fix.

Vector-only retrieval

Pure embedding search whiffs on error codes, acronyms, and product names — exactly what enterprise queries are full of. Run hybrid (vector + BM25) with rank fusion from the start.

Baking permissions into the index

Filtering at index time goes stale the moment access changes. Resolve the asking user’s live entitlements and filter at query time, before generation — never after.

Debugging generation when retrieval is broken

Most “hallucinations” are retrieval misses wearing a trench coat. Measure retrieval hit rate against the golden set before touching a single prompt.

Frequently asked questions

What is the difference between RAG and fine-tuning for organizational knowledge?

RAG retrieves current documents at question time, so answers update the moment a document changes and every answer can cite its source. Fine-tuning bakes knowledge into weights — it goes stale immediately, cannot cite, and cannot enforce per-user permissions. For organizational knowledge, RAG is almost always correct; fine-tune only for style or format.

What chunk size works best for enterprise RAG?

Structure-aware chunks of 300–800 tokens with 10–15% overlap are the reliable default. Split along headings and paragraphs rather than fixed character counts, and prepend each chunk with its document title and heading path for dramatically better retrieval.

How do I stop a RAG agent from hallucinating?

Instruct it to answer only from retrieved context and to explicitly say "I don't know" when retrieval is empty or weak; require a citation for every factual claim; and measure groundedness against a golden set weekly. Hallucination in enterprise RAG is usually a retrieval failure surfacing as a generation failure.

How are document permissions handled in RAG?

Resolve the asking user's identity and live group memberships at query time, filter candidate chunks against each source document's ACL server-side before generation, and treat permission-filtered-empty exactly like genuinely-empty retrieval so restricted documents are never revealed to exist.

What is agentic RAG?

Agentic RAG exposes retrieval as a tool the model invokes itself — writing queries, inspecting results, reformulating, and iterating across multiple searches before answering. It significantly outperforms single-shot retrieve-then-answer pipelines on multi-hop and comparative questions.

Want this built for your team?

From architecture review to a deployed, evaluated system your engineers own — we ship it with you.

FAQ

Working with us

How soon can this build work start?

Typically within a week or two of a scope being agreed. The first delivery is deliberately a small batch so you can check the output against your expectations before volume ramps.

What do you need from our team?

One process owner who knows the workflow, one engineer with access to the systems involved, and a weekly 45-minute review. No standing committee, and no requirement for an ML specialist on your side.

Who owns the output and the data?

You do. Datasets, labels, weights, evaluation suites and runbooks are yours and are handed over at the end. Your data trains your models only, with zero-retention provider settings by default.

Can you scale volume up quickly if we need it?

Yes, and the quality bar holds because the rubric and gold set are already agreed by that point. Ramping is a staffing question, not a re-scoping one, so it usually takes days rather than a new engagement.

We already have a vendor for this. Why switch?

Often you should not. The cases where teams move to us are when they cannot get a quality number out of their current vendor, or when the work is delivered as an opaque batch with no trace of how disagreements were resolved.

What happens after the engagement ends?

We stay on-call for 30 days at no extra cost, then move to an optional support retainer. Most teams also keep a quarterly evaluation review with us to catch drift early.

Copyright © 2026
ReinforcedX, Inc.
All rights reserved