<?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: Anushka Gupta</title>
    <description>The latest articles on DEV Community by Anushka Gupta (@itsanushkaguptaa).</description>
    <link>https://dev.to/itsanushkaguptaa</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%2F3971417%2F78cabfe3-5b0b-4758-aeea-41cba51bf830.png</url>
      <title>DEV Community: Anushka Gupta</title>
      <link>https://dev.to/itsanushkaguptaa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/itsanushkaguptaa"/>
    <language>en</language>
    <item>
      <title>RAG from Scratch: Building a Document Q&amp;A System with LangChain, ChromaDB &amp; Free AI Models</title>
      <dc:creator>Anushka Gupta</dc:creator>
      <pubDate>Sat, 22 Aug 2026 19:20:20 +0000</pubDate>
      <link>https://dev.to/itsanushkaguptaa/rag-from-scratch-building-a-document-qa-system-with-langchain-chromadb-free-ai-models-3gon</link>
      <guid>https://dev.to/itsanushkaguptaa/rag-from-scratch-building-a-document-qa-system-with-langchain-chromadb-free-ai-models-3gon</guid>
      <description>&lt;p&gt;In this blog, we'll build a RAG pipeline from scratch using LangChain, and understand what happens at every step: from loading a document to generating the final answer.&lt;/p&gt;

&lt;p&gt;I want you to keep this diagram in mind.&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️⃣ Document Loader
     ↓
📃 Documents
     ↓
2️⃣ Text Splitter ✂️
     ↓
🧩 Chunks
     ↓
🧠 Embedding Model
     ↓
🔢 Vectors
     ↓
3️⃣ ChromaDB 🗄️
     ↓
4️⃣ Retriever 🔎
     ↓
Relevant Chunks
     ↓
🤖 LLM
     ↓
💬 Final Answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we'll go through each component one by one and understand both the theory behind it and how it works practically. &lt;/p&gt;

&lt;h2&gt;
  
  
  1. Component 1 — Document Loader
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Reads your files (PDF, DOCX, TXT, etc.) and extracts their content.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Imagine you have:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;employee_handbook.pdf&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Your Python application can't simply reason over the PDF itself.&lt;/p&gt;

&lt;p&gt;The Document Loader reads the file and converts it into a format that LangChain can work with.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;employee_handbook.pdf
        ↓
   PDF Loader
        ↓
LangChain Document objects
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A LangChain Document generally contains:&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="nc"&gt;Document&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;page_content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Employees are entitled to 20 days...&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;metadata&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;source&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;employee_handbook.pdf&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;page&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So you get two important things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;page_content&lt;/strong&gt; - The actual text.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;metadata&lt;/strong&gt; - Information about the text.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For RAG, metadata is incredibly useful because later you can tell the user:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"This answer came from Employee Handbook, page 10."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practical example:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For a PDF, you can use a PDF loader such as &lt;strong&gt;PyPDFLoader&lt;/strong&gt; or &lt;strong&gt;PyMuPDF&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For this blog, I'll use &lt;strong&gt;PyMuPDFLoader&lt;/strong&gt; because it generally offers better performance and text extraction for real-world RAG applications. If you're just &lt;strong&gt;getting started or working with simple PDFs&lt;/strong&gt;, &lt;strong&gt;PyPDFLoader&lt;/strong&gt; is also an excellent choice.&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_community.document_loaders&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;PyMuPDFLoader&lt;/span&gt;

&lt;span class="n"&gt;loader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;PyMuPDFLoader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;employee_handbook.pdf&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;documents&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PDF
 ↓
PyMuPDFLoader
 ↓
documents
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can inspect:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;print(documents[0].page_content)&lt;/li&gt;
&lt;li&gt;print(documents[0].metadata)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are many others document loaders in the LangChain ecosystem. Some of them are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;PDF&lt;/strong&gt;       → PyMuPDFLoader&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TXT&lt;/strong&gt;       → TextLoader&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DOCX&lt;/strong&gt;      → Docx2txtLoader&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CSV&lt;/strong&gt;       → CSVLoader&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Web page&lt;/strong&gt;  → WebBaseLoader&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Component 2 — Text Splitter ✂️
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Breaks large documents into smaller, meaningful chunks that are easier for the AI to process.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now suppose your PDF has 100 pages.&lt;/p&gt;

&lt;p&gt;You don't want to treat it as one giant block.&lt;/p&gt;

&lt;p&gt;Instead:&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
     ↓
     ✂️
     ↓
Chunk 1
Chunk 2
Chunk 3
Chunk 4
...
Chunk 500
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This process is called &lt;strong&gt;chunking&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A chunk is simply a smaller piece of the original document.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why do we need chunks?
&lt;/h2&gt;

&lt;p&gt;You don't necessarily want to embed the entire 100-page document.&lt;/p&gt;

&lt;p&gt;We split large documents into smaller chunks so the AI can process and understand information more effectively.&lt;/p&gt;

&lt;p&gt;It also helps the retriever find only the &lt;strong&gt;most relevant pieces&lt;/strong&gt; instead of searching through the entire document.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which splitter should we use?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;RecursiveCharacterTextSplitter&lt;/strong&gt; is a great starting point.&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;text_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;500&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;50&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;text_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;Conceptually:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Document&lt;br&gt;
   ↓&lt;br&gt;
Try paragraphs&lt;br&gt;
   ↓&lt;br&gt;
Too large?&lt;br&gt;
   ↓&lt;br&gt;
Try smaller boundaries&lt;br&gt;
   ↓&lt;br&gt;
Eventually split further&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It tries to keep related text together rather than blindly chopping at arbitrary positions.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is chunk overlap?
&lt;/h2&gt;

&lt;p&gt;Imagine:&lt;/p&gt;

&lt;p&gt;Chunk 1:&lt;br&gt;
&lt;code&gt;A B C D E F&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Chunk 2:&lt;br&gt;
&lt;code&gt;E F G H I J&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
E F is the overlap.&lt;/p&gt;

&lt;p&gt;Why? Because important information might sit around a boundary.&lt;/p&gt;

&lt;p&gt;Without overlap, you could separate related information. A small overlap helps preserve continuity.&lt;/p&gt;
&lt;h2&gt;
  
  
  Few other text splitters :
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CharacterTextSplitter&lt;/strong&gt;- Simple splitting based on a character separator.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TokenTextSplitter&lt;/strong&gt;- Splits based on tokens, useful when working with token limits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MarkdownHeaderTextSplitter&lt;/strong&gt;- Useful for Markdown documents while preserving headings/structure.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SemanticChunker&lt;/strong&gt;- Splits text based on semantic meaning rather than just character count.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  3. Component 3 — Embedding Model
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Stores the chunks as numerical embeddings so they can be searched by meaning.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Employees receive 20 days of annual leave."
                  ↓
          Embedding Model
                  ↓
[0.023, -0.421, 0.812, ...]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That list of numbers is an embedding vector.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Embedding model should we use?
&lt;/h2&gt;

&lt;p&gt;Since I want free local open models, I can use a &lt;strong&gt;Hugging Face/Sentence Transformers embedding model&lt;/strong&gt; locally. &lt;a href="https://huggingface.co/models" rel="noopener noreferrer"&gt;Hugging Face models&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Good candidates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;BAAI/bge-small-en-v1.5&lt;/li&gt;
&lt;li&gt;intfloat/e5-base-v2&lt;/li&gt;
&lt;li&gt;all-MiniLM-L6-v2&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To start with, I'd recommend: &lt;a href="https://huggingface.co/BAAI/bge-small-en-v1.5" rel="noopener noreferrer"&gt;BAAI/bge-small-en-v1.5&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open model&lt;/li&gt;
&lt;li&gt;Can run locally&lt;/li&gt;
&lt;li&gt;No per-request API fee&lt;/li&gt;
&lt;li&gt;Good for semantic retrieval&lt;/li&gt;
&lt;li&gt;Lightweight enough for experimentation&lt;/li&gt;
&lt;li&gt;Well suited to RAG/semantic search&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can use it through LangChain's Hugging Face integration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What about Gemini?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here's an important distinction.&lt;/p&gt;

&lt;p&gt;Gemini is an LLM/model family from Google, but your &lt;strong&gt;RAG pipeline&lt;/strong&gt; needs &lt;strong&gt;two different model&lt;/strong&gt; capabilities:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Embedding model
        +
Generation model
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You need an &lt;strong&gt;embedding model&lt;/strong&gt; to turn chunks/questions into vectors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You need a &lt;strong&gt;generative LLM&lt;/strong&gt; to produce the final answer.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So your architecture could be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PDF
 ↓
LangChain (RecursiveCharacterTextSplitter)
 ↓
Chunks
 ↓
Embedding Model (BGE ← embedding model)
 ↓
Vector DB (ChromaDB)
 ↓
Retriever
 ↓
LLM (Gemini ← generation model)
 ↓
Answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Component 4 — Vector Database 🗄️
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Stores the chunks as numerical embeddings so they can be searched by meaning.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now we have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Chunk
 ↓
Embedding model
 ↓
Vector
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We need somewhere to store those vectors. That's where &lt;strong&gt;Vector Database&lt;/strong&gt; comes in.&lt;/p&gt;

&lt;p&gt;I'll go with &lt;strong&gt;ChromaDB&lt;/strong&gt; because it's simple, local, free to experiment with, and integrates nicely with LangChain.&lt;/p&gt;

&lt;p&gt;Think of ChromaDB as a specialized database for your AI application's semantic search.&lt;/p&gt;

&lt;p&gt;Chunk 1 → Vector 1&lt;br&gt;
Chunk 2 → Vector 2&lt;br&gt;
Chunk 3 → Vector 3&lt;br&gt;
Chunk 4 → Vector 4&lt;/p&gt;

&lt;p&gt;Chroma stores the vectors along with associated information such as document content and metadata.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why not just use a normal database?
&lt;/h2&gt;

&lt;p&gt;Traditional databases are great for exact keyword or structured searches, but RAG needs to find information based on meaning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vector search helps find that semantic relationship.&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;code&gt;Question: “How many vacation days do employees get?”&lt;br&gt;
Document: “Employees receive 20 days of annual leave.”&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;A vector database can recognize that “vacation days” and “annual leave” have similar meanings by comparing their embeddings, even though the exact words are different.&lt;/p&gt;
&lt;h2&gt;
  
  
  Practical ChromaDB implementation
&lt;/h2&gt;

&lt;p&gt;LangChain provides a Chroma integration.&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="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain_chroma&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Chroma&lt;/span&gt;

&lt;span class="n"&gt;vectorstore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Chroma&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_documents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;documents&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;embedding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;embedding_model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;persist_directory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;./chroma_db&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;h2&gt;
  
  
  Some other Vector database examples:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;FAISS&lt;/strong&gt; — Free, open-source, excellent for local projects and learning.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Qdrant&lt;/strong&gt; — Open-source vector database with strong filtering and search capabilities.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Weaviate&lt;/strong&gt; — Open-source vector database with a free self-hosted option.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Milvus&lt;/strong&gt;— Open-source and designed for large-scale vector search.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. Component 5 — Retriever 🔎
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Finds and returns the most relevant chunks from the vector database based on the user's question.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The retriever is the component that says:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Given this question, which chunks should I bring back?"&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;code&gt;How many annual leaves do employees get?&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
The process becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Question
   ↓
Embedding Model
   ↓
Question Vector
   ↓
ChromaDB
   ↓
Similarity Search
   ↓
Top relevant chunks
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example:&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;retriever&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;vectorstore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;as_retriever&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;search_kwargs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;k&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, k = 3. Means return the 3 most relevant chunks.&lt;/p&gt;

&lt;p&gt;Therefore, &lt;br&gt;
🥇 Chunk 32 → 0.92 similarity&lt;br&gt;
🥈 Chunk 31 → 0.84 similarity&lt;br&gt;
🥉 Chunk 89 → 0.71 similarity&lt;/p&gt;

&lt;p&gt;The top results are sent to the LLM.&lt;/p&gt;

&lt;p&gt;These retrieved chunks become the &lt;strong&gt;context&lt;/strong&gt; provided to the LLM to generate the answer.&lt;/p&gt;
&lt;h2&gt;
  
  
  But how is this "similarity" actually calculated?
&lt;/h2&gt;

&lt;p&gt;One of the most common methods is &lt;strong&gt;cosine similarity&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Look at the direction of two vectors and see how similar they are.&lt;/p&gt;

&lt;p&gt;If two vectors point in similar directions: &lt;strong&gt;Similarity → HIGH&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If they point in very different directions: &lt;strong&gt;Similarity → LOW&lt;/strong&gt;&lt;/p&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0bhmbdgiknfo3u1bgdva.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0bhmbdgiknfo3u1bgdva.png" alt="Cosine Similarity" width="800" height="525"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Formula for cosine sinilarity is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;              A · B
cosine = ─────────────
         ||A|| × ||B||
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;A = question vector&lt;/li&gt;
&lt;li&gt;B = chunk vector&lt;/li&gt;
&lt;li&gt;A · B = dot product&lt;/li&gt;
&lt;li&gt;||A|| = magnitude of vector A&lt;/li&gt;
&lt;li&gt;||B|| = magnitude of vector B&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;(This is just for knowledge purposes, you don't have to worry about the formula as Retriever is taking care of all the calculations bts.)&lt;/p&gt;

&lt;p&gt;So conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Similar meaning
      ↓
Similar vector direction
      ↓
High similarity score
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look at these two sentences:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"How many vacation days do employees get?"&lt;br&gt;
&lt;/code&gt;&lt;code&gt;"Employees receive 20 days of annual leave."&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
They don't share many exact words. But their meaning is related.&lt;/p&gt;

&lt;p&gt;The embedding model has learned &lt;strong&gt;semantic relationships&lt;/strong&gt;, so their vectors can end up relatively close in the embedding space.&lt;/p&gt;

&lt;p&gt;That's why vector search can find:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;annual leave&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
when the user asks about:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;vacation days&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ChromaDB doesn't generate the answer.&lt;/li&gt;
&lt;li&gt;ChromaDB doesn't understand the question like an LLM.&lt;/li&gt;
&lt;li&gt;It performs vector similarity search.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Question Vector
       ↓
[0.11, -0.43, 0.76, 0.24...]

       ↕
       ↕ similarity
       ↕

Chunk 1 Vector
[0.12, -0.45, 0.78, 0.21...]

Chunk 2 Vector
[0.15, -0.40, 0.72, 0.18...]

Chunk 3 Vector
[-0.72, 0.31, -0.15, 0.84...]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The system calculates how similar the vectors are.&lt;/p&gt;
&lt;h2&gt;
  
  
  6. Prompt — Giving the LLM the Right Context 📝
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Combines the user's question with the retrieved context and tells the LLM how to answer.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For example, the user asks:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"How many annual leave days do employees get?"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The retriever might find:&lt;/p&gt;

&lt;p&gt;Context:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Employees are entitled to 20 days of annual leave&lt;br&gt;
per calendar year. Employees must submit their&lt;br&gt;
leave requests through the HR portal.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Instead of simply sending the question &lt;em&gt;How many annual leave days do employees get?&lt;/em&gt; to the LLM, we provide the LLM with both:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;📚 Context
+
❓ User Question
+
📝 Instructions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now the LLM has the information it needs.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;LLM&lt;/strong&gt; combines the &lt;strong&gt;retrieved context with its own language understanding to generate a relevant, natural-language answer to the user's question.&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;User Question
"How many vacation days do employees get?"
          ↓

📚 Retrieved Context
"Employees receive 20 days of annual leave....."
          +
🧠 LLM's language understanding
          ↓

💬 Answer
"Employees receive 20 days of annual leave per year."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Prompt Template in LangChain
&lt;/h2&gt;

&lt;p&gt;Instead of manually creating strings every time, LangChain lets us create a reusable Prompt Template.&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 python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain_core.prompts&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ChatPromptTemplate&lt;/span&gt;

&lt;span class="n"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ChatPromptTemplate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_template&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
You are a helpful assistant.

Answer the question using only the provided context.
If the answer is not present in the context,
say that you don&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;t have enough information.

Context:
{context}

Question:
{question}

Answer:
&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;Now every time a user asks a question, we can insert:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;context&lt;br&gt;
+&lt;br&gt;
question&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;into the template.&lt;/p&gt;
&lt;h2&gt;
  
  
  Which LLM to use?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Gemini Flash&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For this project, we'll use &lt;strong&gt;Gemini&lt;/strong&gt; through its &lt;strong&gt;free API tier&lt;/strong&gt;. If you specifically need an open-weight model that can run locally, &lt;strong&gt;Gemma&lt;/strong&gt; is a suitable alternative.&lt;/p&gt;

&lt;p&gt;Why Gemini?&lt;br&gt;
✅ Free tier available&lt;br&gt;
✅ Very capable for RAG question answering&lt;br&gt;
✅ Easy to integrate with LangChain&lt;br&gt;
✅ Works nicely in Google Colab&lt;br&gt;
✅ No need to run a large LLM locally&lt;/p&gt;

&lt;p&gt;(FYI: Gemini is not an open-source model. It is Google's proprietary model family that currently offers a free API tier for certain models/usage.)&lt;/p&gt;

&lt;p&gt;Your code sends the request to Google's API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Your Python code
      ↓
Gemini API
      ↓
Google's servers run Gemini
      ↓
Answer returned
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Few other LLMs:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Llama&lt;/strong&gt;— Meta's open-weight models, widely used for local AI and RAG applications.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mistral&lt;/strong&gt;— Efficient open-weight models that work well for RAG and text-generation tasks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Qwen&lt;/strong&gt;— Alibaba's open-weight models, offering strong performance across many AI tasks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GPT-OSS&lt;/strong&gt; — OpenAI's open-weight models designed to run on your own infrastructure.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Grounding
&lt;/h2&gt;

&lt;p&gt;The prompt can also instruct the LLM to ground its answer in the retrieved context.&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;❌ Don't make up information.

✅ Answer using the provided context.

❓ If the context doesn't contain the answer,
   say that you don't know.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is important because LLMs can sometimes generate plausible-sounding information that isn't actually present in your documents.&lt;/p&gt;

&lt;p&gt;RAG helps reduce this problem by providing relevant external context.&lt;/p&gt;

&lt;p&gt;RAG doesn't magically eliminate hallucinations, but &lt;strong&gt;good retrieval + good prompting&lt;/strong&gt; &lt;strong&gt;can significantly improve grounded responses.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Generation — The LLM Generates the Answer 🤖
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Generation is the final step where the LLM uses the retrieved context along with its language understanding &lt;strong&gt;to generate a relevant, natural-language answer&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Example:&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 receive 20 days of annual leave."
Question: "How many vacation days do employees get?"
                    ↓
                  🤖 LLM
                    ↓
Answer: "Employees receive 20 days of annual leave per year."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In simple words: Retrieve the information → Give it to the LLM → LLM generates the answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion 🚀
&lt;/h2&gt;

&lt;p&gt;And that's RAG from scratch! We've walked through the complete journey of a document, from loading and chunking the content to creating embeddings, storing them in ChromaDB, retrieving relevant context, and finally using an LLM to generate an answer.&lt;/p&gt;

&lt;p&gt;The key takeaway is that RAG isn't just about using an LLM, it's about giving the LLM the right information at the right time. By combining retrieval with generation, we can build AI applications that can work with our own documents and knowledge sources.&lt;/p&gt;

&lt;p&gt;I hope this breakdown made the RAG pipeline a little less intimidating and a lot more understandable. 😊&lt;br&gt;
Now it's your turn, try it with your own documents and see what you can build!&lt;/p&gt;

&lt;h2&gt;
  
  
  💻 Try It Yourself
&lt;/h2&gt;

&lt;p&gt;Want to experiment with the complete pipeline? I've put together a practical notebook that walks through the implementation step by step. You can run it, experiment with different documents, models, chunk sizes, and retrieval settings, and see how each component affects the final answer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://colab.research.google.com/drive/1lRHmTogSbfcfmgcNX5JPTS-0a82dlnZ0?usp=sharing" rel="noopener noreferrer"&gt;🔗 Open the Google Colab Notebook&lt;/a&gt;&lt;/p&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fi0b5njsa2k5waz4htz6d.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fi0b5njsa2k5waz4htz6d.png" alt="Thank You" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>rag</category>
      <category>langchain</category>
      <category>beginners</category>
    </item>
    <item>
      <title>AI Tokens Explained: The Tiny Building Blocks Behind ChatGPT and Generative AI🧩🧩</title>
      <dc:creator>Anushka Gupta</dc:creator>
      <pubDate>Wed, 22 Jul 2026 21:00:37 +0000</pubDate>
      <link>https://dev.to/itsanushkaguptaa/ai-tokens-explained-the-tiny-building-blocks-behind-chatgpt-and-generative-ai-5fob</link>
      <guid>https://dev.to/itsanushkaguptaa/ai-tokens-explained-the-tiny-building-blocks-behind-chatgpt-and-generative-ai-5fob</guid>
      <description>&lt;p&gt;Let's start with the simplest definition:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A &lt;strong&gt;token&lt;/strong&gt; is a small piece of text that an AI model processes as input or generates as output.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;An AI model doesn't read text exactly the way humans do.&lt;/p&gt;

&lt;p&gt;You see:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"I love learning AI."&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
The AI might break this into tokens somewhat like:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"I"&lt;br&gt;
" love"&lt;br&gt;
" learning"&lt;br&gt;
" AI"&lt;br&gt;
"."&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The exact tokenization depends on the model and tokenizer.&lt;/p&gt;

&lt;p&gt;So, a &lt;strong&gt;token&lt;/strong&gt; can be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A complete word&lt;/li&gt;
&lt;li&gt;Part of a word&lt;/li&gt;
&lt;li&gt;A punctuation mark&lt;/li&gt;
&lt;li&gt;A space combined with a word&lt;/li&gt;
&lt;li&gt;Sometimes special symbols&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tokens Are Not the Same Across Models&lt;/strong&gt;&lt;br&gt;
Different AI models may tokenize text differently.&lt;/p&gt;

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

&lt;p&gt;&lt;code&gt;"GenerativeAI"&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
might be:&lt;/p&gt;

&lt;p&gt;Model A:&lt;br&gt;
&lt;code&gt;["Generative", "AI"]&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Model B:&lt;br&gt;
&lt;code&gt;["Gener", "ative", "AI"]&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
The exact number of tokens depends on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Model&lt;/li&gt;
&lt;li&gt;Tokenizer&lt;/li&gt;
&lt;li&gt;Language&lt;/li&gt;
&lt;li&gt;Text&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Therefore, &lt;strong&gt;you should not assume&lt;/strong&gt;: 1 word = 1 token&lt;/p&gt;
&lt;h2&gt;
  
  
  Why Does AI Use Tokens?
&lt;/h2&gt;

&lt;p&gt;Computers work with numbers.&lt;/p&gt;

&lt;p&gt;An LLM cannot directly process "&lt;em&gt;I love learning AI&lt;/em&gt;".&lt;/p&gt;

&lt;p&gt;Instead, the text goes through a process:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Human Text
     ↓
Tokenizer
     ↓
Tokens
     ↓
Token IDs (Numbers)
     ↓
Neural Network
     ↓
Predicted Token IDs
     ↓
Text
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This whole process of breaking text into tokens is called &lt;strong&gt;Tokenization&lt;/strong&gt;.&lt;/p&gt;

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

&lt;p&gt;Input:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"I love Pizza!"&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Tokenizer:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;I&lt;br&gt;
love&lt;br&gt;
Pizza&lt;br&gt;
!&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then each token is mapped to a number called a &lt;strong&gt;token ID&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;I          → 12345&lt;br&gt;
love       → 4567&lt;br&gt;
Pizza      → 234&lt;br&gt;
!          → 45&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Is Token ID the same as Vectors?
&lt;/h2&gt;

&lt;p&gt;Now, here comes an important question: if token IDs represent words as numbers, then what are vectors?&lt;/p&gt;

&lt;p&gt;(I have already discussed about &lt;strong&gt;Vectors and Embeddings&lt;/strong&gt; in my previous blog. I would recommend you to check that out to fully understand the context here.)&lt;/p&gt;

&lt;p&gt;Coming to the point. The answer of the above question is &lt;strong&gt;No&lt;/strong&gt;. &lt;strong&gt;Token IDs and vectors are not the same thing&lt;/strong&gt;, although both are represented using numbers. This is a very common confusion when learning how LLMs work.&lt;/p&gt;

&lt;p&gt;The process is:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Text → Token IDs → Vectors → LLM processing&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 HUMAN TEXT
                     │
                     ▼
               ┌───────────┐
               │ Tokenizer │
               └───────────┘
                     │
                     ▼
                 TOKEN IDs
               [40, 1832, 2456]
                     │
                     ▼
            ┌─────────────────┐
            │ Embedding Layer │
            └─────────────────┘
                     │
                     ▼
            VECTOR REPRESENTATION
           [0.12, -0.45, 0.87, ...]
                     │
                     ▼
                    LLM
                     │
                     ▼
             NEXT TOKEN PREDICTION
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Token IDs are identifiers. Vectors are numerical representations.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's take an example to clearly understand the concept of Token IDs, Vectors and Embeddings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; "I love pizza"
      ↓
   TOKENIZER
      ↓
  Token IDs (Identifies a token)
[45, 782, 1234]
      ↓
EMBEDDING MODEL
      ↓
  Embedding 
[0.21, -0.45, 0.87, ...]
(This list of nos. is a vector created to represent meaning)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explaination:&lt;/p&gt;

&lt;p&gt;🏷️ &lt;strong&gt;Token ID&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"Which token is this?"&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
pizza → 1234&lt;/p&gt;

&lt;p&gt;It's just an &lt;strong&gt;identifier&lt;/strong&gt;. 1234 does not mean "pizza" mathematically.&lt;/p&gt;

&lt;p&gt;🔢 &lt;strong&gt;Vector&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"What is the numerical format?"&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
[0.21, -0.45, 0.87, 0.12]&lt;/p&gt;

&lt;p&gt;Just a &lt;strong&gt;list of numbers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;🧠 &lt;strong&gt;Embedding&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"What does this data mean?"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;An AI model converts:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"I love pizza"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;into an embedding, which is represented as a vector:&lt;/p&gt;

&lt;p&gt;[0.21, -0.45, 0.87, 0.12]&lt;/p&gt;

&lt;p&gt;The numbers collectively capture &lt;strong&gt;semantic information about the text&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remember this:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Token ID&lt;/strong&gt; = Identifier 🏷️ (tells the AI &lt;em&gt;what token it is&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vector&lt;/strong&gt; = List of numbers 🔢 () (&lt;em&gt;numerical form used to represent data&lt;/em&gt;.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Embedding&lt;/strong&gt; = Meaning represented as a vector 🧠 (represent &lt;em&gt;what the data means&lt;/em&gt;)&lt;/li&gt;
&lt;/ul&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frbskz9756z88wl22b3vo.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frbskz9756z88wl22b3vo.png" alt="Token ID vs Vector vs Embedding" width="800" height="640"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Tokens and LLMs
&lt;/h2&gt;

&lt;p&gt;Now let's understand how tokens actually work when you talk to ChatGPT or another LLM.&lt;/p&gt;

&lt;p&gt;Suppose you type:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"What is RAG?"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The process 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;Your Question
      ↓
Tokenization
      ↓
Token IDs
      ↓
LLM processes tokens
      ↓
Model predicts next token
      ↓
Another token
      ↓
Another token
      ↓
Final Response

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The model generates the answer one token at a time.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For example, it might generate:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;RAG&lt;br&gt;
→ stands&lt;br&gt;
→ for&lt;br&gt;
→ Retrieval&lt;br&gt;
→ Augmented&lt;br&gt;
→ Generation&lt;br&gt;
→ ...&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Each generated token is selected based on probabilities learned by the model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does the AI Generate the Whole Answer at Once?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;No.&lt;/strong&gt;&lt;br&gt;
You must have noticed when ChatGPT generates a response. Word by word, right?! It keeps predicting the next token until it decides the response is complete.&lt;/p&gt;

&lt;p&gt;This is why LLMs are sometimes called &lt;strong&gt;autoregressive models&lt;/strong&gt; in the context of next-token prediction.&lt;/p&gt;
&lt;h2&gt;
  
  
  Tokens and AI Pricing 💰
&lt;/h2&gt;

&lt;p&gt;Before I tell you about the token cost, I'll first explain to you what we mean by &lt;strong&gt;token usage&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Tokens are generally divided into two categories:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Input Tokens:&lt;/strong&gt; The tokens you send to the model.&lt;/p&gt;

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

&lt;p&gt;User:&lt;br&gt;
&lt;code&gt;Explain RAG in simple terms.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Your input might include:&lt;br&gt;
System instructions + Your question + Conversation history + RAG context/documents + Tool results&lt;/p&gt;

&lt;p&gt;All of these consume input tokens.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Output Tokens:&lt;/strong&gt; The tokens the model generates.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;RAG stands for Retrieval-Augmented Generation...&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
So, for a basic request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input Tokens
     +
Output Tokens
     =
Total Token Usage
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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;Your request
      ↓
Input: 5,000 tokens
      +
Output: 2,000 tokens
      ↓
Total: 7,000 tokens
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the model's available &lt;strong&gt;context window&lt;/strong&gt; is 128K, you're well within the limit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wait, What Is a Context Window?
&lt;/h2&gt;

&lt;p&gt;This is another extremely important concept.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An LLM has a maximum amount of text it can process at one time.&lt;/strong&gt; This is called its &lt;strong&gt;context window&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;┌───────────────────────────────┐
│       Context Window          │
│                               │
│ System Instructions           │
│ +                             │
│ Previous Conversation         │
│ +                             │
│ User Prompt                   │
│ +                             │
│ Retrieved Documents (RAG)     │
│ +                             │
│ Generated Response            │
│                               │
└───────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything needs to fit within the model's context limits.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Happens When You Exceed the Context Window?
&lt;/h2&gt;

&lt;p&gt;Suppose:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Context Window = 100,000 tokens&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
But you try to send:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;120,000 tokens&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
The model cannot process all of them within that request.&lt;/p&gt;

&lt;p&gt;Depending on the application, you may see:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An API error&lt;/li&gt;
&lt;li&gt;Input truncation&lt;/li&gt;
&lt;li&gt;Older conversation content removed&lt;/li&gt;
&lt;li&gt;Context being summarized&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The exact behavior depends on the model and platform.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Coming to &lt;strong&gt;Token pricing&lt;/strong&gt;. It is one of the most important topics to understand if you're building GenAI applications using APIs. &lt;/p&gt;

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

&lt;blockquote&gt;
&lt;p&gt;You are generally charged based on how many tokens your application sends to the model and how many tokens the model generates.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The cost may depend on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input token price&lt;/li&gt;
&lt;li&gt;Output token price&lt;/li&gt;
&lt;li&gt;Model being used&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This means developers need to manage tokens carefully.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simple Example:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's imagine a fictional model with pricing:&lt;/p&gt;

&lt;p&gt;Input:&lt;br&gt;
&lt;code&gt;$1 per 1 million tokens&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Output:&lt;br&gt;
&lt;code&gt;$5 per 1 million tokens&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Suppose your application uses:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input = 100,000 tokens&lt;/li&gt;
&lt;li&gt;Output = 20,000 tokens&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Input cost&lt;br&gt;
&lt;code&gt;100,000 / 1,000,000 × $1&lt;br&gt;
= $0.10&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Output cost&lt;br&gt;
&lt;code&gt;20,000 / 1,000,000 × $5&lt;br&gt;
= $0.10&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Total&lt;br&gt;
&lt;code&gt;$0.10 + $0.10&lt;br&gt;
= $0.20&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So the request costs &lt;strong&gt;$0.20&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This is just a hypothetical example to explain the calculation. Real model prices vary significantly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Token Cost vs Context Window
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Don't confuse these two.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Model Context Window = 128K tokens&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
This means the model can process a certain amount of context within its supported limits.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;It doesn't mean: "You have to use 128K tokens."&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
You could send:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;2,000 tokens&lt;/code&gt; and still use the same model.&lt;/p&gt;

&lt;p&gt;You pay based on your actual usage according to the provider's pricing, not simply because the model supports a 128K context window.&lt;/p&gt;

&lt;p&gt;Think of it like a backpack:&lt;/p&gt;

&lt;p&gt;🎒 Backpack capacity = &lt;strong&gt;Context window&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;📦 What you actually put inside = &lt;strong&gt;Token usage&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;💰 What you pay for = The &lt;strong&gt;actual usage&lt;/strong&gt; according to the pricing model&lt;/p&gt;

&lt;p&gt;One simple formula to remember:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Total LLM Cost ≈ (Input Tokens × Input Rate) + (Output Tokens × Output Rate)&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Where Are Tokens Used?
&lt;/h2&gt;

&lt;p&gt;Tokens are used across almost every part of modern Generative AI.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Chatbots&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;User Question&lt;br&gt;
→ Tokens&lt;br&gt;
→ LLM&lt;br&gt;
→ Output Tokens&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. RAG&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;Question&lt;br&gt;
→ Tokens&lt;br&gt;
→ Retrieve Context&lt;br&gt;
→ LLM&lt;br&gt;
→ Answer&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. AI Agents&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;Goal&lt;br&gt;
→ Tokens&lt;br&gt;
→ Reason&lt;br&gt;
→ Tool Call&lt;br&gt;
→ Tool Result&lt;br&gt;
→ Tokens&lt;br&gt;
→ Final Answer&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Summarization&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;Long Document&lt;br&gt;
→ Tokens&lt;br&gt;
→ LLM&lt;br&gt;
→ Summary Tokens&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Simplest Way to Remember:
&lt;/h2&gt;

&lt;p&gt;Think of an LLM like a chef.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Tokens are the ingredients 🧱&lt;/strong&gt;- The model processes language as small pieces.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The context window is the kitchen counter 🏠&lt;/strong&gt;- You can only have a limited amount of ingredients on the counter at once.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The LLM is the chef 👨‍🍳&lt;/strong&gt;- It uses the available ingredients to prepare the answer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Token limits are the counter size 📏&lt;/strong&gt;- If you bring too many ingredients, everything won't fit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Token costs are the grocery bill 💰&lt;/strong&gt;- The more ingredients you use, the more you may pay.&lt;/li&gt;
&lt;/ul&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flx2fcaezsyix3sfdqevs.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flx2fcaezsyix3sfdqevs.png" alt="Thank you for reading" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Vectors and Embeddings in Generative AI🤖(How AI Understands Meaning Instead of Just Words)</title>
      <dc:creator>Anushka Gupta</dc:creator>
      <pubDate>Wed, 15 Jul 2026 18:39:11 +0000</pubDate>
      <link>https://dev.to/itsanushkaguptaa/vectors-and-embeddings-in-generative-aihow-ai-understands-meaning-instead-of-just-words-136k</link>
      <guid>https://dev.to/itsanushkaguptaa/vectors-and-embeddings-in-generative-aihow-ai-understands-meaning-instead-of-just-words-136k</guid>
      <description>&lt;p&gt;One of the most confusing concepts in Generative AI is the difference between &lt;strong&gt;embeddings&lt;/strong&gt; and &lt;strong&gt;vectors&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Many people use these terms interchangeably, but are they actually the same?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Not exactly.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Understanding this difference is essential if you're working with RAG (Retrieval-Augmented Generation), semantic search, recommendation systems, or AI chatbots.&lt;/p&gt;

&lt;p&gt;Let's start with a simple example :&lt;/p&gt;

&lt;p&gt;Imagine You're Organizing a Library 📚&lt;/p&gt;

&lt;p&gt;Suppose your library contains these books:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Book 1&lt;/strong&gt;&lt;br&gt;
"Introduction to Machine Learning"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Book 2&lt;/strong&gt;&lt;br&gt;
"How to Bake a Chocolate Cake"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Book 3&lt;/strong&gt;&lt;br&gt;
"Deep Learning with Python"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Book 4&lt;/strong&gt;&lt;br&gt;
"Indian Desert Recipes"&lt;/p&gt;

&lt;p&gt;Now someone asks:&lt;/p&gt;

&lt;p&gt;"&lt;em&gt;I want books about Artificial Intelligence.&lt;/em&gt;"&lt;/p&gt;

&lt;p&gt;Would you search for the exact keyword Artificial Intelligence?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Book 3 doesn't even contain those exact words. Yet you know it's related.&lt;/p&gt;

&lt;p&gt;Humans understand meaning. Computers don't...unless we convert meaning into numbers.&lt;/p&gt;

&lt;p&gt;That's where &lt;strong&gt;embeddings&lt;/strong&gt; come in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Can't AI Understand Words Directly?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Computers only understand numbers.&lt;/p&gt;

&lt;p&gt;They don't know what&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Dog&lt;br&gt;
Cat&lt;br&gt;
Car&lt;br&gt;
Love&lt;br&gt;
Pizza&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;mean.&lt;/p&gt;

&lt;p&gt;To a computer they're simply characters.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;D&lt;br&gt;
o&lt;br&gt;
g&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Nothing more.&lt;/p&gt;

&lt;p&gt;So before AI can compare meanings, &lt;strong&gt;it converts words into numbers.&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is an Embedding?
&lt;/h2&gt;

&lt;p&gt;An embedding is a &lt;strong&gt;numerical representation of data that captures its meaning and context.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Think of it as translating human language into a mathematical language that AI can understand.&lt;/p&gt;

&lt;p&gt;Instead of storing&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Machine Learning&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;AI stores something like&lt;/p&gt;

&lt;p&gt;&lt;code&gt;[0.42, -0.18, 0.91, 0.13, ...]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This list of numbers represents the meaning of the text.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Notice something...That list itself is actually a vector.&lt;/p&gt;
&lt;h2&gt;
  
  
  Wait... Then What's a Vector?
&lt;/h2&gt;

&lt;p&gt;This is where most people get confused.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A vector is simply an ordered list of numbers.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;[1, 5, 9]&lt;/code&gt;&lt;br&gt;
or&lt;br&gt;
&lt;code&gt;[0.27, -0.83, 0.15, 0.92]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A vector has no inherent meaning.&lt;/strong&gt; It's just numbers.&lt;/p&gt;

&lt;p&gt;An &lt;strong&gt;embedding&lt;/strong&gt; is a special type of vector whose numbers have been learned by an AI model &lt;strong&gt;to represent semantic meaning&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In other words:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Every embedding is a vector, but not every vector is an embedding.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Think of it like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every mango is a fruit.&lt;/li&gt;
&lt;li&gt;But not every fruit is a mango.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;A Real-Life Analogy&lt;/strong&gt; :&lt;/p&gt;

&lt;p&gt;Imagine Google Maps.&lt;/p&gt;

&lt;p&gt;Every city has coordinates.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Mumbai&lt;br&gt;
(19.0760, 72.8777)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Delhi&lt;br&gt;
(28.6139, 77.2090)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Coordinates don't describe the city. They simply tell you where it is.&lt;/p&gt;

&lt;p&gt;Embeddings work similarly.&lt;/p&gt;

&lt;p&gt;Instead of physical location, they represent semantic location.&lt;/p&gt;

&lt;p&gt;Words with similar meanings end up close together.&lt;/p&gt;

&lt;p&gt;Example : Suppose we have four words.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;King&lt;br&gt;
Queen&lt;br&gt;
Apple&lt;br&gt;
Banana&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Their embeddings might conceptually look like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;King     → [0.91, 0.77]&lt;br&gt;
Queen    → [0.90, 0.79]&lt;br&gt;
Apple    → [-0.83, 0.21]&lt;br&gt;
Banana   → [-0.79, 0.25]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Notice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;King and Queen are close.&lt;/li&gt;
&lt;li&gt;Apple and Banana are close.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The AI has learned relationships without anyone explicitly programming them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Are Embeddings Created?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is where the &lt;strong&gt;embedding model&lt;/strong&gt; comes in.&lt;/p&gt;

&lt;p&gt;Popular embedding models include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;OpenAI text-embedding models&lt;/li&gt;
&lt;li&gt;BAAI BGE&lt;/li&gt;
&lt;li&gt;E5&lt;/li&gt;
&lt;li&gt;Sentence Transformers&lt;/li&gt;
&lt;li&gt;Cohere Embed&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Suppose your document says:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Employees receive 20 annual leaves.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The embedding model reads the sentence and produces something like:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;[0.22,&lt;br&gt;
-0.63,&lt;br&gt;
0.89,&lt;br&gt;
0.11,&lt;br&gt;
...1536 numbers...]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Those numbers encode meaning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where Are Embeddings Stored?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Embeddings are stored inside a &lt;strong&gt;Vector Database&lt;/strong&gt;.&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;Pinecone&lt;/li&gt;
&lt;li&gt;Chroma&lt;/li&gt;
&lt;li&gt;FAISS&lt;/li&gt;
&lt;li&gt;Milvus&lt;/li&gt;
&lt;li&gt;Weaviate&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  How Does the Vector Database Know Which Documents Are Similar?
&lt;/h2&gt;

&lt;p&gt;Imagine this 2D space.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 AI

                  ● Machine Learning

             ● Deep Learning

--------------------------------------------

      ● Pizza

             ● Burger
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When someone asks:&lt;/p&gt;

&lt;p&gt;"&lt;em&gt;Tell me about AI.&lt;/em&gt;"&lt;/p&gt;

&lt;p&gt;The query embedding lands near:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Machine Learning&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Deep Learning&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Not near&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Pizza&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The vector database doesn't search words. &lt;strong&gt;It searches distances between vectors.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Measuring Similarity?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The database compares vectors using mathematical &lt;strong&gt;distance metrics.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Common ones include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Cosine Similarity (most common for text)&lt;/li&gt;
&lt;li&gt;Euclidean Distance&lt;/li&gt;
&lt;li&gt;Dot Product&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Imagine throwing a dart onto a map, the database returns the nearest neighbors to where your query landed.&lt;/p&gt;

&lt;p&gt;The closer two vectors are, the more similar their meanings are.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Are Embeddings So Powerful?
&lt;/h2&gt;

&lt;p&gt;They enable:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Semantic search instead of keyword search.&lt;/li&gt;
&lt;li&gt;Better document retrieval for RAG.&lt;/li&gt;
&lt;li&gt;Product recommendations.&lt;/li&gt;
&lt;li&gt;Similarity search.&lt;/li&gt;
&lt;li&gt;Duplicate detection.&lt;/li&gt;
&lt;li&gt;Personalized content.&lt;/li&gt;
&lt;li&gt;Question answering.&lt;/li&gt;
&lt;li&gt;Document clustering.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Keyword Search vs Semantic Search
&lt;/h2&gt;

&lt;p&gt;Suppose your document says:&lt;/p&gt;

&lt;p&gt;"Employees are entitled to 20 days of annual leave."&lt;/p&gt;

&lt;p&gt;You ask:&lt;/p&gt;

&lt;p&gt;"&lt;em&gt;How many vacation days do I get?&lt;/em&gt;"&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;keyword&lt;/strong&gt; search might fail because the document says annual leave, not vacation days.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;vector&lt;/strong&gt; search succeeds because the embeddings for "vacation days" and "annual leave" are close in semantic space.&lt;/p&gt;

&lt;p&gt;This is one of the biggest advantages of embeddings.&lt;/p&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fndyt6visk1frzuoq79cr.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fndyt6visk1frzuoq79cr.png" alt="Vector Vs Embedding" width="800" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Takeaway
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Vectors&lt;/strong&gt; are simply numerical arrays. &lt;strong&gt;Embeddings&lt;/strong&gt; are vectors that have been learned by AI models to capture semantic meaning. In a Generative AI application, documents and user queries are converted into embeddings and stored in a vector database. When a user asks a question, the query embedding is compared with stored embeddings to find the most semantically relevant information, which is then passed to the LLM to generate an accurate response.&lt;/p&gt;

&lt;p&gt;In short:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Vectors are the language of mathematics. Embeddings are the language of meaning.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's what makes modern AI systems capable of understanding concepts rather than just matching keywords.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>machinelearning</category>
      <category>nlp</category>
      <category>rag</category>
    </item>
    <item>
      <title>RAG vs Agentic RAG : Explained with Real-World Examples</title>
      <dc:creator>Anushka Gupta</dc:creator>
      <pubDate>Mon, 13 Jul 2026 16:27:59 +0000</pubDate>
      <link>https://dev.to/itsanushkaguptaa/rag-vs-agentic-rag-explained-with-real-world-examples-5911</link>
      <guid>https://dev.to/itsanushkaguptaa/rag-vs-agentic-rag-explained-with-real-world-examples-5911</guid>
      <description>&lt;p&gt;Imagine you ask an AI:&lt;/p&gt;

&lt;p&gt;"&lt;em&gt;What is my company's leave policy?&lt;/em&gt;"&lt;/p&gt;

&lt;p&gt;There are two ways the AI can answer:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It guesses based on what it learned during training.&lt;/li&gt;
&lt;li&gt;It opens your company's HR documents, finds the correct policy, and then answers.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The second approach is &lt;strong&gt;Retrieval-Augmented Generation (RAG)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now imagine instead of just looking up one document, the AI:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Decides which documents to search.&lt;/li&gt;
&lt;li&gt;Realizes it needs more information.&lt;/li&gt;
&lt;li&gt;Searches multiple sources.&lt;/li&gt;
&lt;li&gt;Compares conflicting information.&lt;/li&gt;
&lt;li&gt;Uses a calculator if needed.&lt;/li&gt;
&lt;li&gt;Asks you a follow-up question if your request is ambiguous.&lt;/li&gt;
&lt;li&gt;Verifies its answer before responding.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's &lt;strong&gt;Agentic RAG&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Was RAG Needed?
&lt;/h2&gt;

&lt;p&gt;Large Language Models (LLMs) like ChatGPT are trained on enormous datasets.&lt;/p&gt;

&lt;p&gt;But they have limitations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They don't know your private documents.&lt;/li&gt;
&lt;li&gt;They don't know today's latest information unless connected to external sources.&lt;/li&gt;
&lt;li&gt;They sometimes hallucinate (confidently generate incorrect information).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Imagine asking:&lt;/p&gt;

&lt;p&gt;"&lt;em&gt;What's the refund policy in my company's employee handbook?&lt;/em&gt;"&lt;/p&gt;

&lt;p&gt;The LLM has never seen your handbook.&lt;/p&gt;

&lt;p&gt;Without RAG it might answer:&lt;/p&gt;

&lt;p&gt;"&lt;em&gt;Most companies allow refunds within 30 days...&lt;/em&gt;"&lt;/p&gt;

&lt;p&gt;That sounds reasonable...but could be completely wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is RAG?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Retrieval-Augmented Generation (RAG)&lt;/strong&gt; is a technique that allows an AI model to retrieve relevant information from external knowledge sources before generating an answer.&lt;/p&gt;

&lt;p&gt;Instead of relying only on its training, the AI first looks up the information, then writes a response using what it found.&lt;/p&gt;

&lt;p&gt;Think of it like an open-book exam instead of a memory test.&lt;/p&gt;

&lt;h2&gt;
  
  
  Everyday Analogy :
&lt;/h2&gt;

&lt;p&gt;Imagine you're a chef.&lt;/p&gt;

&lt;p&gt;Someone asks:&lt;/p&gt;

&lt;p&gt;"&lt;em&gt;How many grams of salt does Grandma's lasagna recipe use?&lt;/em&gt;"&lt;/p&gt;

&lt;p&gt;Option 1:&lt;/p&gt;

&lt;p&gt;You guess.&lt;/p&gt;

&lt;p&gt;Option 2:&lt;/p&gt;

&lt;p&gt;You open Grandma's recipe book,&lt;br&gt;
read the recipe,&lt;br&gt;
then answer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RAG is Option 2.&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How RAG Works
&lt;/h2&gt;

&lt;p&gt;Suppose your company has thousands of PDF files.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HR Policy.pdf&lt;/li&gt;
&lt;li&gt;Employee Handbook.pdf&lt;/li&gt;
&lt;li&gt;Travel Policy.pdf&lt;/li&gt;
&lt;li&gt;Insurance Guide.pdf&lt;/li&gt;
&lt;li&gt;IT Security.pdf&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now someone asks:&lt;/p&gt;

&lt;p&gt;"&lt;em&gt;How many casual leaves do employees get?&lt;/em&gt;"&lt;/p&gt;

&lt;p&gt;The workflow 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 (Query)
      │
      ▼
Convert question into embeddings
      │
      ▼
Search Vector Database
      │
      ▼
Retrieve most relevant documents (Context)
      │
      ▼
Send retrieved content + question
to the LLM (Query + Context)
      │
      ▼
Generate final answer

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The AI doesn't search every document. Instead, it retrieves only the most relevant ones.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of RAG
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Up-to-date Information&lt;/strong&gt;&lt;br&gt;
No retraining needed. Just update documents.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Private Knowledge&lt;/strong&gt;&lt;br&gt;
Works with company documents.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reduced Hallucination&lt;/strong&gt;&lt;br&gt;
Answers come from retrieved evidence.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Easy Maintenance&lt;/strong&gt;&lt;br&gt;
Updating a PDF updates the AI's knowledge.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lower Cost&lt;/strong&gt;&lt;br&gt;
No need to retrain expensive models.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Limitations of RAG
&lt;/h2&gt;

&lt;p&gt;RAG is powerful but still limited.&lt;/p&gt;

&lt;p&gt;Suppose you ask:&lt;/p&gt;

&lt;p&gt;"&lt;em&gt;Compare all cloud providers, recommend one, calculate the yearly cost, and prepare a migration strategy.&lt;/em&gt;"&lt;/p&gt;

&lt;p&gt;Simple RAG retrieves documents.&lt;br&gt;
It doesn't think step by step.&lt;br&gt;
It retrieves once.&lt;br&gt;
Answers once.&lt;/p&gt;

&lt;p&gt;That's where &lt;strong&gt;Agentic RAG&lt;/strong&gt; comes in.&lt;/p&gt;

&lt;p&gt;You ask:&lt;/p&gt;

&lt;p&gt;"&lt;em&gt;I'm taking my parents out for dinner. Recommend a restaurant within ₹1500, serving vegetarian food, within 5 km, and book a table for 7 PM.&lt;/em&gt;"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Traditional RAG :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;RAG searches restaurant documents or reviews and replies:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Restaurant A&lt;/li&gt;
&lt;li&gt;Restaurant B&lt;/li&gt;
&lt;li&gt;Restaurant C&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Maybe it summarizes reviews.&lt;/p&gt;

&lt;p&gt;Done.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Check your budget&lt;/li&gt;
&lt;li&gt;Filter by distance&lt;/li&gt;
&lt;li&gt;Check table availability&lt;/li&gt;
&lt;li&gt;Make a booking&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It simply retrieved information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Agentic RAG :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The AI thinks 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;Step 1: Find vegetarian restaurants
↓
Step 2: Filter within 5 km
↓
Step 3: Check average pricing
↓
Step 4: Check table availability
↓
Step 5: Book a table
↓
Step 6: Send confirmation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the AI is planning and taking actions, not just retrieving information.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Agentic RAG?
&lt;/h2&gt;

&lt;p&gt;Agentic RAG extends traditional RAG by giving the AI decision-making capabilities.&lt;/p&gt;

&lt;p&gt;Instead of following a fixed retrieve-then-answer pipeline, the AI acts like an intelligent agent that can plan, reason, choose tools, retrieve information multiple times, and validate its own results before responding.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Agentic RAG Workflow :&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;User Question
      │
      ▼
Understand Goal
      │
      ▼
Plan Steps
      │
      ▼
Retrieve Information
      │
      ▼
Need More?
     Yes
      │
Retrieve Again
      │
Use Tools
      │
Reason
      │
Validate
      │
Generate Final Answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice retrieval can happen multiple times.&lt;/p&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6rk5abworka9wdpeakhy.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6rk5abworka9wdpeakhy.png" alt="RAG vs Agentic RAG" width="800" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Takeaway
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Retrieval-Augmented Generation (RAG)&lt;/strong&gt; make LLMs far more useful by allowing them to access external knowledge instead of relying solely on what they memorized during training. It reduces hallucinations, keeps responses current, and enables AI to answer questions using private or domain-specific data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Agentic RAG&lt;/strong&gt; takes this a step further. Rather than following a single retrieve-and-answer pipeline, it behaves like an intelligent agent: it plans, retrieves information iteratively, uses tools, reasons through complex tasks, and validates its work before producing an answer.&lt;/p&gt;

&lt;p&gt;A simple way to remember the difference is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;RAG&lt;/strong&gt; helps an AI know more.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Agentic RAG&lt;/strong&gt; helps an AI think and do more&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>npm vs pnpm: The Package Manager Battle Every React Developer Should Know</title>
      <dc:creator>Anushka Gupta</dc:creator>
      <pubDate>Sun, 05 Jul 2026 20:41:50 +0000</pubDate>
      <link>https://dev.to/itsanushkaguptaa/npm-vs-pnpm-the-package-manager-battle-every-react-developer-should-know-m68</link>
      <guid>https://dev.to/itsanushkaguptaa/npm-vs-pnpm-the-package-manager-battle-every-react-developer-should-know-m68</guid>
      <description>&lt;p&gt;If you've started learning React or Node.js, you've probably come across commands like &lt;code&gt;npm install&lt;/code&gt; or &lt;code&gt;pnpm install&lt;/code&gt;. Both npm and pnpm are package managers, they help you install and manage the libraries your project depends on.&lt;/p&gt;

&lt;p&gt;Think of them as delivery services for your code. Need React? Axios? Tailwind CSS? Your package manager fetches and installs them for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is npm?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;npm (Node Package Manager)&lt;/strong&gt; is the default package manager that comes with Node.js. It's widely used and works great for most projects.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install &lt;br&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is pnpm?
&lt;/h2&gt;

&lt;p&gt;Interestingly, pnpm doesn't officially stand for a fixed expansion. The name is commonly interpreted as: &lt;strong&gt;Performant Node Package Manager&lt;/strong&gt;.&lt;br&gt;
pnpm is a faster and more disk-efficient alternative to npm. Instead of downloading the same package multiple times for different projects, pnpm stores it once and reuses it wherever needed.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pnpm install&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  The Key Difference :
&lt;/h2&gt;

&lt;p&gt;The main difference between npm and pnpm is how they install and manage dependencies. Both can be used to create and manage React projects, but &lt;strong&gt;pnpm is generally faster and more space-efficient.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine you have two projects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Project A uses React and Axios&lt;/li&gt;
&lt;li&gt;Project B uses React only&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With &lt;strong&gt;npm&lt;/strong&gt;, each project keeps its own copy of the dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Project A
node_modules/
    react
    axios

Project B
node_modules/
    react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This duplicates packages across projects.&lt;/p&gt;

&lt;p&gt;With &lt;strong&gt;pnpm&lt;/strong&gt;, packages are stored once in a global store and linked to projects when needed. This saves both installation time and disk space.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Global Store
react
axios
lodash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each project's node_modules contains links to these packages instead of full copies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Project A
node_modules -&amp;gt; links

Project B
node_modules -&amp;gt; links
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;**&lt;br&gt;
Why Developers Love pnpm&lt;br&gt;
**&lt;br&gt;
✅ Faster installs&lt;/p&gt;

&lt;p&gt;✅ Less disk usage&lt;/p&gt;

&lt;p&gt;✅ Better dependency management&lt;/p&gt;

&lt;p&gt;✅ Excellent support for monorepos&lt;/p&gt;
&lt;h2&gt;
  
  
  A Real-World Example
&lt;/h2&gt;

&lt;p&gt;Suppose Project B doesn't have Axios listed in its &lt;code&gt;package.json&lt;/code&gt;, but your code tries to use it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With pnpm, you'll immediately get an error because Axios wasn't declared as a dependency.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;Error: Cannot find module 'axios'

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, your project can only access packages that are explicitly listed in its own package.json&lt;/p&gt;

&lt;p&gt;While this may seem strict, it actually prevents the classic "works on my machine" problem and makes projects more reliable for teams.&lt;/p&gt;

&lt;p&gt;The key thing to understand is that pnpm's global store is not the same as your project's dependencies.&lt;/p&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F779tjcuq7b4k2ojbz45t.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F779tjcuq7b4k2ojbz45t.png" alt="pnpm: dependency isolation explained" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With &lt;strong&gt;npm&lt;/strong&gt;, the behavior is different because dependencies can sometimes be accidentally accessible.&lt;/p&gt;

&lt;p&gt;Suppose Project B doesn't have Axios in its package.json:&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;"dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&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;span class="nl"&gt;"react"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^19.0.0"&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;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;Now, when you do :&lt;br&gt;
&lt;code&gt;import axios from "axios";&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
What can happen?&lt;br&gt;
If another package in node_modules already installed Axios as its own dependency, your code might still work with npm.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Project B
│
├── package.json
│   └── react
│
└── node_modules
    ├── react
    ├── some-library
    │   └── axios
    └── ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your application may successfully import axios even though you never declared it.&lt;/p&gt;

&lt;p&gt;The problem: Another developer or your CI/CD pipeline may install a slightly different dependency tree where Axios isn't present at that location. Suddenly, the same code fails.&lt;/p&gt;

&lt;p&gt;This leads to the classic:&lt;/p&gt;

&lt;p&gt;✅ Works on my machine&lt;br&gt;
❌ Fails on yours&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;npm is reliable, popular, and perfectly fine for many projects. But if you're starting a new React application, pnpm offers faster installs, better dependency isolation, and significant disk space savings.&lt;/p&gt;

&lt;p&gt;That's why many modern development teams are making the switch to pnpm.&lt;/p&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5xi6z9njfn1umpj75zu5.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5xi6z9njfn1umpj75zu5.png" alt="npm vs pnpm" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
