<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: neuroMl ai</title>
    <description>The latest articles on DEV Community by neuroMl ai (@neuroml_ai_7f8becf9c92ebc).</description>
    <link>https://dev.to/neuroml_ai_7f8becf9c92ebc</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4084481%2F37931221-43da-433e-bb29-f56d4da3c086.png</url>
      <title>DEV Community: neuroMl ai</title>
      <link>https://dev.to/neuroml_ai_7f8becf9c92ebc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/neuroml_ai_7f8becf9c92ebc"/>
    <language>en</language>
    <item>
      <title>How RAG Works: Building an AI Assistant That Can Answer Questions from Company Documents | NeuroML.ai</title>
      <dc:creator>neuroMl ai</dc:creator>
      <pubDate>Wed, 19 Aug 2026 07:25:16 +0000</pubDate>
      <link>https://dev.to/neuroml_ai_7f8becf9c92ebc/how-rag-works-building-an-ai-assistant-that-can-answer-questions-from-company-documents--3lfh</link>
      <guid>https://dev.to/neuroml_ai_7f8becf9c92ebc/how-rag-works-building-an-ai-assistant-that-can-answer-questions-from-company-documents--3lfh</guid>
      <description>&lt;p&gt;Imagine joining a company with hundreds or even thousands of internal documents.&lt;/p&gt;

&lt;p&gt;There are HR policies, employee handbooks, product documentation, technical guides, compliance documents, SOPs, and internal processes.&lt;/p&gt;

&lt;p&gt;Now an employee asks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;“How many unused paid leaves can I carry forward to next year?”&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You could search through folders, open PDFs, use Ctrl+F, or ask the HR team.&lt;/p&gt;

&lt;p&gt;But what if an AI assistant could answer the question in seconds — using the company's actual documents instead of guessing?&lt;/p&gt;

&lt;p&gt;That's where &lt;strong&gt;Retrieval-Augmented Generation (RAG)&lt;/strong&gt; becomes useful.&lt;/p&gt;

&lt;p&gt;In this article, we'll build a simplified version of a real-world RAG system and understand what's happening behind the scenes.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Problem Are We Solving?
&lt;/h2&gt;

&lt;p&gt;Let's imagine a company has this information:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/company-documents
    ├── employee-handbook.pdf
    ├── leave-policy.pdf
    ├── health-insurance.pdf
    ├── remote-work-policy.pdf
    ├── travel-policy.pdf
    └── expense-policy.pdf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An employee asks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Can I carry forward unused paid leaves to next year?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A general-purpose LLM may know something about leave policies in general.&lt;/p&gt;

&lt;p&gt;But it doesn't automatically know &lt;strong&gt;this company's specific policy&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We need to give the model access to the company's private knowledge.&lt;/p&gt;

&lt;p&gt;That's the problem RAG solves.&lt;/p&gt;




&lt;h1&gt;
  
  
  What Is RAG?
&lt;/h1&gt;

&lt;p&gt;RAG stands for &lt;strong&gt;Retrieval-Augmented Generation&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The basic idea is simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User Question
      ↓
Retrieve Relevant Information
      ↓
Give Information to LLM
      ↓
Generate Answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of asking the LLM to answer entirely from what it already knows, we first retrieve relevant information from our own knowledge base.&lt;/p&gt;

&lt;p&gt;The complete flow looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                User Question
                      ↓
              Generate Embedding
                      ↓
              Search Vector DB
                      ↓
             Retrieve Documents
                      ↓
          Relevant Context Found
                      ↓
             Context + Question
                      ↓
                    LLM
                      ↓
               Final Answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes the LLM much more useful for private or frequently changing information.&lt;/p&gt;




&lt;h1&gt;
  
  
  Step 1: Collect the Documents
&lt;/h1&gt;

&lt;p&gt;Our first step is to collect the company's documents.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HR Policy
Product Documentation
SOPs
Legal Documents
Technical Documentation
Employee Handbook
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These documents might come from:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PDFs&lt;/li&gt;
&lt;li&gt;Word documents&lt;/li&gt;
&lt;li&gt;Websites&lt;/li&gt;
&lt;li&gt;Databases&lt;/li&gt;
&lt;li&gt;Cloud storage&lt;/li&gt;
&lt;li&gt;Internal knowledge bases&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For our example, we'll assume the documents are PDFs.&lt;/p&gt;




&lt;h1&gt;
  
  
  Step 2: Extract the Text
&lt;/h1&gt;

&lt;p&gt;The PDF isn't immediately useful to the LLM.&lt;/p&gt;

&lt;p&gt;We first need to extract the text.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;documents&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;load_documents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;./company-documents&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Document 1:
Employee Leave Policy

Employees are entitled to 24 paid leaves per year...

Unused paid leaves may be carried forward up to a
maximum of 10 days...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we have machine-readable content.&lt;/p&gt;




&lt;h1&gt;
  
  
  Step 3: Split the Documents into Chunks
&lt;/h1&gt;

&lt;p&gt;Here's an important part of building a RAG system.&lt;/p&gt;

&lt;p&gt;We usually don't want to put an entire 100-page document into every LLM request.&lt;/p&gt;

&lt;p&gt;Instead, we split it into smaller pieces called &lt;strong&gt;chunks&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;100-page PDF
      ↓
    Chunks
      ↓
┌───────────────┐
│ Chunk 1       │
├───────────────┤
│ Chunk 2       │
├───────────────┤
│ Chunk 3       │
├───────────────┤
│ Chunk 4       │
├───────────────┤
│ ...           │
└───────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A simple implementation could look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain_text_splitters&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;RecursiveCharacterTextSplitter&lt;/span&gt;

&lt;span class="n"&gt;splitter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;RecursiveCharacterTextSplitter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;chunk_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;800&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;chunk_overlap&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;chunks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;splitter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split_documents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;documents&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The overlap helps preserve context between neighboring chunks.&lt;/p&gt;

&lt;p&gt;However, chunking isn't simply about choosing a number like 500 or 1,000 characters.&lt;/p&gt;

&lt;p&gt;Good chunking should consider the structure of the information.&lt;/p&gt;

&lt;p&gt;For example, keeping a policy heading together with its explanation is generally more useful than splitting them apart.&lt;/p&gt;




&lt;h1&gt;
  
  
  Step 4: Convert Text into Embeddings
&lt;/h1&gt;

&lt;p&gt;Now we have chunks of text.&lt;/p&gt;

&lt;p&gt;But how do we search them intelligently?&lt;/p&gt;

&lt;p&gt;This is where &lt;strong&gt;embeddings&lt;/strong&gt; come in.&lt;/p&gt;

&lt;p&gt;An embedding converts text into a numerical representation — a vector.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Employees can carry forward 10 unused leaves"
                 ↓
        Embedding Model
                 ↓
[0.12, -0.43, 0.81, 0.17, ...]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important idea is that text with similar meaning tends to have vectors that are close together in vector space.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"How many leaves can I carry forward?"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;should be semantically close to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Employees may carry forward up to 10 unused paid leaves."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;even though the wording is different.&lt;/p&gt;

&lt;p&gt;That's why vector search is so useful for RAG.&lt;/p&gt;




&lt;h1&gt;
  
  
  Step 5: Store the Embeddings in a Vector Database
&lt;/h1&gt;

&lt;p&gt;We need somewhere to store these vectors.&lt;/p&gt;

&lt;p&gt;Popular vector databases include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Qdrant&lt;/li&gt;
&lt;li&gt;Pinecone&lt;/li&gt;
&lt;li&gt;Weaviate&lt;/li&gt;
&lt;li&gt;Milvus&lt;/li&gt;
&lt;li&gt;Chroma&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Our architecture now looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Documents
    ↓
Text Extraction
    ↓
Chunking
    ↓
Embeddings
    ↓
Vector Database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each stored record can contain more than just the vector.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Employees may carry forward up to 10 unused paid leaves."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"document"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"leave-policy.pdf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"page"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"department"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"HR"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That metadata becomes extremely useful later.&lt;/p&gt;




&lt;h1&gt;
  
  
  Step 6: A User Asks a Question
&lt;/h1&gt;

&lt;p&gt;Now an employee asks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“How many paid leaves can I carry forward?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We convert that question into an embedding as well.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User Question
      ↓
Embedding Model
      ↓
Question Vector
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we search the vector database for the most relevant chunks.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;vector_store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;similarity_search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;How many paid leaves can I carry forward?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The database might return:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Result 1
Leave Policy — Page 7
"Employees may carry forward up to 10 unused paid leaves."

Result 2
Employee Handbook — Page 22
"Unused leave is subject to company leave policy."

Result 3
Leave Policy — Page 8
"Carry-forward balances are reset according to..."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we have relevant context.&lt;/p&gt;




&lt;h1&gt;
  
  
  Step 7: Give the Context to the LLM
&lt;/h1&gt;

&lt;p&gt;This is where generation happens.&lt;/p&gt;

&lt;p&gt;Instead of asking:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LLM:
"How many paid leaves can employees carry forward?"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we provide the retrieved information:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Context:
Employees may carry forward up to 10 unused paid leaves.

Question:
How many paid leaves can I carry forward?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The LLM can then generate:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Employees can carry forward up to 10 unused paid leaves to the next year, according to the company's leave policy.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is the fundamental idea behind RAG.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Complete Pipeline
&lt;/h1&gt;

&lt;p&gt;Our system now looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                     USER
                       │
                       ↓
              "How many leaves
               can I carry?"
                       │
                       ↓
                Query Embedding
                       │
                       ↓
              ┌─────────────────┐
              │  Vector Search  │
              └────────┬────────┘
                       ↓
             Relevant Documents
                       │
                       ↓
              ┌─────────────────┐
              │      LLM        │
              └────────┬────────┘
                       ↓
                  Final Answer
                       │
                       ↓
             Source: Leave Policy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a basic RAG application.&lt;/p&gt;

&lt;p&gt;But a production system needs more.&lt;/p&gt;




&lt;h1&gt;
  
  
  What Happens If the Answer Doesn't Exist?
&lt;/h1&gt;

&lt;p&gt;This is one of the most important parts of a real-world RAG system.&lt;/p&gt;

&lt;p&gt;Suppose an employee asks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Does the company provide free international travel insurance for personal vacations?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But the company documents don't contain this information.&lt;/p&gt;

&lt;p&gt;A poorly designed system might generate a confident answer.&lt;/p&gt;

&lt;p&gt;That's dangerous.&lt;/p&gt;

&lt;p&gt;A better system should recognize that there isn't enough evidence.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“I couldn't find information about personal international travel insurance in the available company documents.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is much better than making something up.&lt;/p&gt;




&lt;h1&gt;
  
  
  Preventing Hallucinations
&lt;/h1&gt;

&lt;p&gt;RAG can reduce hallucinations, but it doesn't magically eliminate them.&lt;/p&gt;

&lt;p&gt;A strong implementation should instruct the model to use the retrieved context and avoid unsupported claims.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You are an internal company assistant.

Answer the user's question using only the provided context.

If the answer cannot be found in the context,
clearly state that the information is unavailable.

Do not invent policies, numbers, dates, or procedures.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also add additional validation and evaluation layers.&lt;/p&gt;




&lt;h1&gt;
  
  
  Adding Sources to the Answer
&lt;/h1&gt;

&lt;p&gt;There's another useful feature we can add.&lt;/p&gt;

&lt;p&gt;Instead of simply returning:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“You can carry forward 10 leaves.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;we can return:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“You can carry forward up to 10 unused paid leaves.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Source:&lt;/strong&gt; Leave Policy, Page 7&lt;/p&gt;

&lt;p&gt;This makes the system easier to trust.&lt;/p&gt;

&lt;p&gt;The user can verify where the answer came from.&lt;/p&gt;

&lt;p&gt;For enterprise applications, source attribution can be extremely valuable.&lt;/p&gt;




&lt;h1&gt;
  
  
  Access Control Is Critical
&lt;/h1&gt;

&lt;p&gt;Here's a problem that's easy to overlook.&lt;/p&gt;

&lt;p&gt;Imagine the company has:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Public Documents
Employee Documents
Management Documents
Finance Documents
Legal Documents
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not every employee should be able to search everything.&lt;/p&gt;

&lt;p&gt;A RAG system therefore needs access control.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Employee
   ↓
Authentication
   ↓
Permission Check
   ↓
Allowed Documents
   ↓
Vector Search
   ↓
LLM
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Metadata filtering can help.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"department"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"HR"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"access_level"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"employee"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The retrieval system can then restrict searches based on the user's permissions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Never assume that because an LLM can retrieve something, the user should be allowed to see it.&lt;/strong&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  What About Updated Documents?
&lt;/h1&gt;

&lt;p&gt;Company policies change.&lt;/p&gt;

&lt;p&gt;Suppose the old leave policy says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Carry forward up to 10 days.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Six months later, the company changes it to:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Carry forward up to 15 days.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If we don't update the knowledge base, the AI may return outdated information.&lt;/p&gt;

&lt;p&gt;A production RAG system therefore needs a document ingestion pipeline:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;New Document
     ↓
Extract Text
     ↓
Chunk
     ↓
Generate Embeddings
     ↓
Update Vector DB
     ↓
Remove / Version Old Data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is one reason RAG is often preferable to relying on a model's static knowledge for frequently changing business information.&lt;/p&gt;




&lt;h1&gt;
  
  
  RAG vs Fine-Tuning
&lt;/h1&gt;

&lt;p&gt;A common question is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Why not just fine-tune the model with company documents?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Fine-tuning and RAG solve different problems.&lt;/p&gt;

&lt;h3&gt;
  
  
  RAG is useful when:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Information changes frequently.&lt;/li&gt;
&lt;li&gt;You need access to private documents.&lt;/li&gt;
&lt;li&gt;You need source citations.&lt;/li&gt;
&lt;li&gt;You need to update knowledge without retraining.&lt;/li&gt;
&lt;li&gt;You need document-level access control.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Fine-tuning is useful when:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You want to change model behavior.&lt;/li&gt;
&lt;li&gt;You need a particular output style.&lt;/li&gt;
&lt;li&gt;You need specialized task performance.&lt;/li&gt;
&lt;li&gt;You have a suitable training dataset.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In many real applications, you don't have to choose only one.&lt;/p&gt;

&lt;p&gt;You can combine techniques depending on the problem.&lt;/p&gt;




&lt;h1&gt;
  
  
  Improving Retrieval Quality
&lt;/h1&gt;

&lt;p&gt;The quality of your final answer is heavily influenced by the quality of retrieval.&lt;/p&gt;

&lt;p&gt;If the wrong documents are retrieved:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Bad Retrieval
      ↓
Wrong Context
      ↓
Potentially Wrong Answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some ways to improve retrieval include:&lt;/p&gt;

&lt;h3&gt;
  
  
  Better chunking
&lt;/h3&gt;

&lt;p&gt;Preserve meaningful sections.&lt;/p&gt;

&lt;h3&gt;
  
  
  Metadata filtering
&lt;/h3&gt;

&lt;p&gt;Restrict results by department, document type, date, permissions, etc.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hybrid search
&lt;/h3&gt;

&lt;p&gt;Combine semantic search with keyword-based search.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reranking
&lt;/h3&gt;

&lt;p&gt;Retrieve a larger candidate set and then rank the most relevant results.&lt;/p&gt;

&lt;h3&gt;
  
  
  Query transformation
&lt;/h3&gt;

&lt;p&gt;Rewrite or expand the user's question before searching.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User:
"What happens to unused leaves?"

        ↓

Search Query:
"paid leave carry-forward policy unused leave balance"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Production Architecture
&lt;/h1&gt;

&lt;p&gt;A production-ready version might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                         USER
                           │
                           ↓
                  ┌────────────────┐
                  │ Authentication │
                  └───────┬────────┘
                          ↓
                  ┌────────────────┐
                  │   API Gateway  │
                  └───────┬────────┘
                          ↓
                  ┌────────────────┐
                  │ RAG Application│
                  └───────┬────────┘
                          │
             ┌────────────┼─────────────┐
             ↓            ↓             ↓
        Query Engine   Permissions   Conversation
             │                         State
             ↓
       ┌─────────────┐
       │ Vector DB   │
       └──────┬──────┘
              ↓
        Relevant Context
              │
              ↓
       ┌─────────────┐
       │     LLM     │
       └──────┬──────┘
              ↓
        Validation
              ↓
       Answer + Sources
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Behind the scenes, you would also want:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Logging&lt;/li&gt;
&lt;li&gt;Monitoring&lt;/li&gt;
&lt;li&gt;Error handling&lt;/li&gt;
&lt;li&gt;Rate limiting&lt;/li&gt;
&lt;li&gt;Cost tracking&lt;/li&gt;
&lt;li&gt;Evaluation&lt;/li&gt;
&lt;li&gt;Data encryption&lt;/li&gt;
&lt;li&gt;Access control&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Common RAG Mistakes
&lt;/h1&gt;

&lt;h2&gt;
  
  
  1. Making chunks too large
&lt;/h2&gt;

&lt;p&gt;Large chunks can introduce irrelevant information.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Making chunks too small
&lt;/h2&gt;

&lt;p&gt;Tiny chunks may lose important context.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Ignoring metadata
&lt;/h2&gt;

&lt;p&gt;Metadata can dramatically improve retrieval and access control.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Sending too much context to the LLM
&lt;/h2&gt;

&lt;p&gt;More context doesn't always mean better answers.&lt;/p&gt;

&lt;p&gt;Irrelevant information can actually make responses worse.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Assuming RAG eliminates hallucinations
&lt;/h2&gt;

&lt;p&gt;It doesn't.&lt;/p&gt;

&lt;p&gt;You still need good prompts, validation, retrieval evaluation, and application-level controls.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Ignoring permissions
&lt;/h2&gt;

&lt;p&gt;Private company data requires strict access control.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Never evaluating retrieval quality
&lt;/h2&gt;

&lt;p&gt;You should test whether the system is actually retrieving the correct information.&lt;/p&gt;




&lt;h1&gt;
  
  
  How Would This Work in a Real Company?
&lt;/h1&gt;

&lt;p&gt;Let's return to our original example.&lt;/p&gt;

&lt;p&gt;An employee asks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;“How many paid leaves can I carry forward?”&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The system processes the request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Authenticate employee
             ↓
2. Receive question
             ↓
3. Generate query embedding
             ↓
4. Search permitted documents
             ↓
5. Retrieve leave-policy sections
             ↓
6. Send context to LLM
             ↓
7. Generate answer
             ↓
8. Attach source
             ↓
9. Return response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The employee gets:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;You can carry forward up to 10 unused paid leaves to the next year, according to the company's leave policy.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Source:&lt;/strong&gt; Employee Leave Policy — Page 7&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What previously required searching through documents or contacting HR can now happen in seconds.&lt;/p&gt;

&lt;p&gt;That's the practical value of RAG.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Takeaway
&lt;/h1&gt;

&lt;p&gt;RAG isn't simply:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;“Put documents into a vector database and connect an LLM.”&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A reliable RAG application is a complete software system.&lt;/p&gt;

&lt;p&gt;You need to think about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Document processing&lt;/li&gt;
&lt;li&gt;Chunking&lt;/li&gt;
&lt;li&gt;Embeddings&lt;/li&gt;
&lt;li&gt;Vector databases&lt;/li&gt;
&lt;li&gt;Retrieval&lt;/li&gt;
&lt;li&gt;Prompt design&lt;/li&gt;
&lt;li&gt;LLM selection&lt;/li&gt;
&lt;li&gt;Source attribution&lt;/li&gt;
&lt;li&gt;Access control&lt;/li&gt;
&lt;li&gt;Data freshness&lt;/li&gt;
&lt;li&gt;Evaluation&lt;/li&gt;
&lt;li&gt;Monitoring&lt;/li&gt;
&lt;li&gt;Security&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The LLM is only one part of the architecture.&lt;/p&gt;

&lt;p&gt;The real engineering challenge is building a system that retrieves the &lt;strong&gt;right information&lt;/strong&gt;, gives the model the &lt;strong&gt;right context&lt;/strong&gt;, and produces an answer that users can &lt;strong&gt;trust and verify&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;p&gt;In a follow-up article, we can take this concept further and build a complete RAG application using &lt;strong&gt;Python, FastAPI, a vector database, and an LLM&lt;/strong&gt;, including document ingestion and a simple API.&lt;/p&gt;

&lt;p&gt;If you're building a RAG application yourself, the most important question isn't:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Which LLM should I use?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Start with:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;“What information does my application need, who is allowed to access it, and how can I reliably retrieve it?”&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once you answer those questions, choosing the rest of the architecture becomes much easier.&lt;/p&gt;




&lt;h2&gt;
  
  
  About NeuroML.ai
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;NeuroML.ai&lt;/strong&gt; is an AI and software product engineering company helping startups, enterprises, agencies, and growing businesses build, modernize, and scale digital products.&lt;/p&gt;

&lt;p&gt;We work across AI/ML, Generative AI, RAG systems, AI agents, SaaS, custom software, web and mobile applications, automation, cloud, DevOps, and dedicated development teams.&lt;/p&gt;

&lt;p&gt;Our focus is simple: &lt;strong&gt;turn ideas and business problems into production-ready software.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you're exploring RAG, AI agents, or AI-powered software, we'd love to hear what you're building.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>agents</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
