Skip to main content
Insyrge - Zoho CRM & Business Automation Consulting
← Back to All ArticlesAI & Business Automation

What's the Best Way to Build Retrieval-Augmented Generation (RAG) Over Internal Company Documents?

A practical architecture for RAG over internal documents: ingestion, chunking, retrieval, permissions and security, evaluation and private deployment

•Insyrge

The best way to build RAG over internal company documents: architecture, chunking, permissions and security, evaluation, and private RAG options, with sources.

TL;DR: The best way to build RAG over internal documents is to treat it as a search and permissions problem first and a language model problem second. Ingest only the documents you trust, split them into well-sized chunks that keep their meaning, retrieve with both keyword and meaning-based search, and filter results by who is allowed to see them before anything reaches the model. Then measure retrieval and answers on a set of real questions, and keep the whole pipeline inside your own cloud or network if the documents are sensitive.

Key takeaways

  • RAG retrieves relevant passages from your documents and gives them to a language model to write the answer, so answers can cite your own content.
  • Chunking is critical. Microsoft notes oversized or irrelevant chunks raise cost and can give inaccurate answers.
  • Enforce access control at retrieval time, so people only get answers built from documents they could already open.
  • Treat documents as untrusted input. OWASP lists prompt injection, sensitive information disclosure and vector weaknesses as RAG-relevant risks.
  • Test with a fixed question set before launch and after each change. Private RAG keeps data in your environment.

Everyone wants to ask questions of their own policies, contracts, wikis and support tickets. RAG is the usual way to do it, and it is easy to demo and hard to get right. This guide walks through the architecture we would use, in platform-neutral terms. For deeper dives, see private RAG and RAG chunking.

Want RAG over your own documents that people can trust? Contact Insyrge or book a call.

What is RAG and why use it for internal documents?

Retrieval-augmented generation looks up relevant content from your documents when a question is asked, then gives that content to a language model so it can write an answer grounded in it (AWS Prescriptive Guidance on RAG). Compared with retraining a model on your data, it is easier to update, because you change the documents, and easier to audit, because the answer can point to its sources.

What does a good RAG architecture look like?

  1. Connect and ingest. Pull documents from drives, wikis, ticket systems and databases. Record the source, owner, date and permissions for each.
  2. Clean and parse. Extract text, tables and headings. Remove boilerplate and duplicates. Poor parsing is a common hidden cause of poor answers.
  3. Chunk. Split into passages that keep their meaning.
  4. Embed and index. Store both the text and a vector for meaning-based search, with metadata such as permissions and dates.
  5. Retrieve. Search by keywords and by meaning, filter by permission, then rerank the best passages.
  6. Generate. Give the passages to the model with clear instructions to answer only from them and to say when they do not contain the answer.
  7. Cite and log. Show the sources and record the question, passages and answer for review.

Microsoft's guide to designing and evaluating a RAG solution walks through these phases, from preparation through chunking, embedding, search and evaluation (Microsoft RAG solution design and evaluation guide).

How should you chunk documents?

Chunking breaks documents into passages that each hold semantically relevant content. Microsoft says it is crucial to a successful RAG implementation: passing whole documents or oversized chunks is expensive, can overwhelm token limits and can give worse results, while chunks that are too small may lack the context to answer (Microsoft's RAG chunking phase guide). Practical rules:

  • Split on structure first (headings, sections, clauses), then by size.
  • Keep a title and section path with each chunk so it makes sense on its own.
  • Use a small overlap where ideas run across boundaries.
  • Treat tables, code and slides differently from prose.
  • Try two or three chunk sizes on your own questions and compare results, rather than copying a number from a blog.

How do you handle permissions and security?

This is where internal RAG most often goes wrong. If the index mixes every document and the model sees everything, a junior employee can get answers built from board papers.

  • Carry permissions into the index. Store who can read each chunk. Azure AI Search describes document-level access controls (Azure AI Search document-level access overview) and a security filter pattern that trims results by user or group identity (Azure AI Search's security filter pattern). Other platforms have equivalents.
  • Filter before generation. The model should never see a passage the user could not open.
  • Keep permissions fresh. When access changes in the source system, the index must follow, so re-sync permissions on a schedule or on change.
  • Guard against prompt injection. Text inside a document can try to instruct the model. OWASP lists this as its first LLM risk (OWASP LLM01: Prompt Injection). Treat retrieved text as data, restrict what tools the model can call, and review sources you ingest.
  • Prevent sensitive disclosure. OWASP covers how models can reveal confidential information (OWASP LLM02: Sensitive Information Disclosure). Redact or exclude regulated fields, and test with adversarial questions.
  • Know the vector risks. OWASP also describes weaknesses specific to vectors and embeddings, including access control and data leakage in vector stores (OWASP LLM08: Vector and Embedding Weaknesses).

We cover this in more depth in Prompt Injection: Protect Your RAG and Agents.

What about private RAG?

If your documents are confidential, choose where each part runs. Options range from using a managed model inside your own cloud account, to running open models on your own servers. Keep the vector index, the documents and the logs in your own environment, check each provider's data-retention terms, and make sure prompts and documents are not used for training unless you have agreed to it. Our guide to private RAG covers the options.

How do you evaluate RAG?

Evaluate retrieval and answers separately, because a good answer from a bad passage is luck. Microsoft's guide recommends gathering test documents and test queries early and evaluating each phase (Microsoft RAG solution design and evaluation guide). A simple approach:

  • Collect 50 or more real questions from users, with the document that should answer each.
  • Measure whether the right passage shows up in the top results.
  • Have a person grade answers for correctness, completeness and whether they stick to the sources.
  • Include questions the documents cannot answer, and check the system says so.
  • Include permission tests with users who should not see certain documents.
  • Re-run the set after every change to chunking, models or prompts.

For the retrieval step, see hybrid search, which combines keywords and vectors.

Sources

Frequently asked questions

What is the best way to build RAG over internal company documents?

Ingest trusted documents with their permissions, chunk them along their structure, index them for both keyword and meaning-based search, filter results by user access before generation, cite sources, and evaluate with real questions. Keep it in your own environment if the data is sensitive.

How should I chunk documents for RAG?

Split by structure such as headings and sections, then by size. Keep a title and section path with each chunk, use small overlaps, handle tables and code separately, and test a few chunk sizes on your own questions.

How do I stop RAG from leaking confidential documents?

Store access permissions with each chunk, filter results by the asking user before the model sees them, keep permissions in sync with the source, and test with users who should not have access.

What is private RAG?

Private RAG keeps documents, vector index, logs and model calls inside your own cloud account or network, with data-retention terms you control, so confidential content does not leave your environment.

How do I evaluate a RAG system?

Collect real questions with known source documents, measure whether retrieval finds the right passage, grade answers for correctness and faithfulness to sources, include unanswerable and permission tests, and re-run after each change.

Is RAG better than fine-tuning for company documents?

They solve different problems. RAG is usually easier to keep current and audit because you update documents and can cite them. Fine-tuning changes model behaviour and is not a good way to add facts that change often.

Insyrge will help you build RAG over your documents

We design the ingestion, chunking, retrieval and permission model, build it in your own environment, and test it on your real questions before anyone relies on it. Contact Insyrge or book a call.

See also: RAG knowledge bots and AI agent development.

Related resources

About the Author

Manav Sharma is the founder of Insyrge and a CRM solutions architect. He works across Zoho, Salesforce, HubSpot, Odoo and more, designing the CRM setups, integrations and automations that keep sales and operations teams working from the same data.

Need Help Implementing This in Your Business?

Our certified Zoho consultants and automation experts can help you design and deploy custom workflows tailored to your operations.

Book Free Consultation