<?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: IFRAH ASHRAF</title>
    <description>The latest articles on DEV Community by IFRAH ASHRAF (@ifrah_ashraf_a3600e049d51).</description>
    <link>https://dev.to/ifrah_ashraf_a3600e049d51</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1605762%2F999443b1-90b5-4e70-8cff-1620e3f71b45.jpeg</url>
      <title>DEV Community: IFRAH ASHRAF</title>
      <link>https://dev.to/ifrah_ashraf_a3600e049d51</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ifrah_ashraf_a3600e049d51"/>
    <language>en</language>
    <item>
      <title>From Documents to Answers: How RAG Works</title>
      <dc:creator>IFRAH ASHRAF</dc:creator>
      <pubDate>Sun, 22 Feb 2026 18:48:17 +0000</pubDate>
      <link>https://dev.to/ifrah_ashraf_a3600e049d51/from-documents-to-answers-how-rag-works-ofc</link>
      <guid>https://dev.to/ifrah_ashraf_a3600e049d51/from-documents-to-answers-how-rag-works-ofc</guid>
      <description>&lt;p&gt;The main steps to build a RAG pipeline are divided into two major processes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;RAG Indexing&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;RAG Query&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  RAG INDEXING
&lt;/h2&gt;

&lt;p&gt;The indexing phase converts raw documents into structured vector representations so they can be efficiently retrieved using similarity search later.&lt;/p&gt;

&lt;h4&gt;
  
  
  Architecture diagram
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjpuo737yc3knl62nijrd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjpuo737yc3knl62nijrd.png" alt="architecture diagram of RAG Indexing" width="671" height="529"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  1) Document ingestion and preprocessing
&lt;/h3&gt;

&lt;p&gt;The first process starts with ingestion, cleaning, and converting the data into a proper format. This involves transforming raw data from the Bronze layer to the Gold layer.&lt;/p&gt;

&lt;p&gt;This is the very first and most crucial step, and it requires proper care before moving to the next stages.   &lt;/p&gt;

&lt;p&gt;Ex- Suppose raw data is in bullet points like this &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RAW DATA&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INTRODUCTION TO DATA SCIENCE!!!
• DATA is everywhere in today's world  
• MACHINE learning helps in prediction  
• tools like PYTHON , R , SQL are used
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;AFTER PREPROCCESSING AND NORMALISATION&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Section: Introduction to Data Science  
Content: Data is everywhere in today's world. Machine learning helps in prediction. Tools like Python, R, and SQL are used.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2) Chunking
&lt;/h3&gt;

&lt;p&gt;Chunking means breaking large text into smaller pieces so the computer can understand and search it more effectively.&lt;/p&gt;

&lt;p&gt;Imagine you have a 5000-page book and you want to perform Q&amp;amp;A on top of it. To process the context properly, you split the text content based on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Topics&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Headings&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Paragraphs&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Recursive patterns using delimiters like "\n\n" and "."&lt;/li&gt;
&lt;li&gt;Other chunking &lt;a href="https://www.pinecone.io/learn/chunking-strategies/" rel="noopener noreferrer"&gt;strategies.&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once the chunks are ready with metadata such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;chunk_id&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;chunk_index&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code&gt;chunking.json&lt;/code&gt; file (or Parquet for large-scale data) is stored, or it can be directly fed from memory into embedding models.  &lt;/p&gt;

&lt;p&gt;Ex - &lt;code&gt;chunk.json&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
  {
    "chunk_id": "ml_intro_chunk_0001",
    "chunk_index": 0,
    "doc_id": "machine_learning_basics",
    "section": "Introduction to Machine Learning",
    "content": "What is AI, Types of Algorithms",
    "page_start": 1,
    "page_end": 1,
    "char_start": 0,
    "word_count": 6,
    "language": "en"
  }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3) Embeddings
&lt;/h3&gt;

&lt;p&gt;The real juice lies here where all the data is converted into numbers so computers can understand its meaning.&lt;/p&gt;

&lt;p&gt;Let’s say we embed the following sentence into a 3D space (in real-world scenarios, this can be 4000+ dimensions):&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The dog and cat are friends&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feju1wlgw42w23pppl56a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feju1wlgw42w23pppl56a.png" alt="vector representation in 3 dimension" width="800" height="563"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As shown in the image, the vectors for word "&lt;strong&gt;dog&lt;/strong&gt;" and "&lt;strong&gt;cat&lt;/strong&gt;" point in a similar direction (the cosine angle between them is small). However, the vector for the word "&lt;strong&gt;cricket&lt;/strong&gt;" points in a different direction compared to "dog" or "cat".&lt;/p&gt;

&lt;p&gt;At this stage, all document chunks are converted into &lt;strong&gt;vector embeddings&lt;/strong&gt; and stored inside the &lt;strong&gt;vector database&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The indexing phase is now complete. The system has built a searchable semantic space.&lt;/p&gt;

&lt;p&gt;Now let’s understand how the system responds when a user submits a query.&lt;/p&gt;

&lt;h2&gt;
  
  
  RAG QUERY
&lt;/h2&gt;

&lt;p&gt;When a user submits a query, it is first converted into an embedding using the same model used during indexing. The retrieved results are then passed to an &lt;strong&gt;LLM&lt;/strong&gt; for output generation and reasoning&lt;/p&gt;

&lt;h4&gt;
  
  
  Query Processing Diagram
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frvjc25uvsxch2x0a3pay.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frvjc25uvsxch2x0a3pay.png" alt=" " width="440" height="387"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;u&gt;Step 1: Convert User Query to Embedding&lt;/u&gt;
&lt;/h3&gt;

&lt;p&gt;Convert the user query into vector embeddings using the same model that was used during document vector storage.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;u&gt;Step 2: Similarity Search&lt;/u&gt;
&lt;/h3&gt;

&lt;p&gt;Once the user query is converted into a vector, it is compared with all the stored document vectors in the vector database.&lt;/p&gt;

&lt;p&gt;Using cosine similarity, the system measures how close the query vector is to each document vector. The closest ones (top-k results) are selected and sent to the LLM.&lt;/p&gt;

&lt;p&gt;Ex - Suppose the user asks:&lt;/p&gt;

&lt;p&gt;What are the types of algorithms ?&lt;/p&gt;

&lt;p&gt;The system compares this query vector with stored chunks like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;What is AI&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Types of Algorithms&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;History of Computers&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The chunk &lt;strong&gt;Types of Algorithms&lt;/strong&gt; will have the highest similarity score, so it gets selected and passed to the LLM for generating the final answer.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;u&gt;Step 3: LLM Response Generation&lt;/u&gt;
&lt;/h3&gt;

&lt;p&gt;The LLM takes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The original user query&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The retrieved document chunks (if found)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It appends the retrieved content to the query context and generates the final output answer&lt;/p&gt;

&lt;p&gt;I’m currently learning more about &lt;strong&gt;RAG&lt;/strong&gt; and &lt;strong&gt;Agentic AI&lt;/strong&gt; step by step. If this helped you understand the pipeline better, feel free to like or follow for more as I share my journey.&lt;/p&gt;

</description>
      <category>rag</category>
      <category>agents</category>
      <category>ai</category>
      <category>vectordatabase</category>
    </item>
  </channel>
</rss>
