<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Blogs]]></title><description><![CDATA[Blogs]]></description><link>https://linuxhunting.hashnode.dev</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1593680282896/kNC7E8IR4.png</url><title>Blogs</title><link>https://linuxhunting.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Thu, 10 Sep 2026 17:24:13 GMT</lastBuildDate><atom:link href="https://linuxhunting.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[RAG(Retrieval-Augmented Generation): The Good, the Bad, and the Hallucinations]]></title><description><![CDATA[Understanding RAG: How It Improves LLM Answers—and Where It Can Still Fail
Large Language Models (LLMs) such as ChatGPT can answer questions, write code, summarize documents, and generate content in s]]></description><link>https://linuxhunting.hashnode.dev/understanding-rag</link><guid isPermaLink="true">https://linuxhunting.hashnode.dev/understanding-rag</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[GenAI Cohort]]></category><category><![CDATA[genai]]></category><dc:creator><![CDATA[Vibhu Khati]]></dc:creator><pubDate>Thu, 09 Jul 2026 17:05:59 GMT</pubDate><content:encoded><![CDATA[<h2>Understanding RAG: How It Improves LLM Answers—and Where It Can Still Fail</h2>
<p>Large Language Models (LLMs) such as ChatGPT can answer questions, write code, summarize documents, and generate content in seconds. But they have an important limitation: they do not automatically know your latest company documents, private files, product details, or newly published information.</p>
<p>An LLM only knows what it learned during training and what is included in the conversation. If you ask it about information outside that scope, it may guess, give outdated information, or confidently provide an incorrect answer.</p>
<p>This is where <strong>Retrieval-Augmented Generation (RAG)</strong> becomes useful.</p>
<p>RAG is a technique that gives an LLM relevant external information before it generates a response. Instead of relying only on its training data, the model can retrieve useful documents, policies, notes, FAQs, or database content and use them as context.</p>
<p>However, RAG is not a magic solution. It can improve answer quality significantly, but it cannot guarantee that every response will be correct.</p>
<p>This article explains what RAG is, how it works, where it is useful, and why it can still fail.</p>
<hr />
<h2>The Limitation of an LLM Without External Knowledge</h2>
<p>Imagine you build a chatbot for an e-commerce company.</p>
<p>A user asks:</p>
<blockquote>
<p>What is the return policy for electronics purchased during a sale?</p>
</blockquote>
<p>A normal LLM may try to answer based on general knowledge. It may say that electronics can be returned within 30 days, even if your company policy allows only 7 days for sale items.</p>
<p>The model is not intentionally trying to mislead the user. It simply does not have access to the company's actual policy document.</p>
<p>The same issue happens when users ask about:</p>
<ul>
<li><p>Internal company documentation</p>
</li>
<li><p>Product manuals</p>
</li>
<li><p>Customer support policies</p>
</li>
<li><p>Legal guidelines</p>
</li>
<li><p>Personal notes</p>
</li>
<li><p>Private databases</p>
</li>
<li><p>Recently updated information</p>
</li>
<li><p>Research papers published after the model's training period</p>
</li>
</ul>
<p>Without external context, an LLM often has two choices: say it does not know, or generate an answer that sounds plausible.</p>
<p>RAG helps reduce this problem by giving the model relevant information before it answers.</p>
<hr />
<h2>What Is RAG?</h2>
<p><strong>RAG stands for Retrieval-Augmented Generation.</strong></p>
<p>It combines two steps:</p>
<ol>
<li><p><strong>Retrieval</strong>: Find relevant information from an external knowledge source.</p>
</li>
<li><p><strong>Generation</strong>: Give that information to an LLM so it can generate a better answer.</p>
</li>
</ol>
<p>Instead of asking the model to answer from memory alone, a RAG system first searches a knowledge base.</p>
<p>For example, if a user asks:</p>
<blockquote>
<p>How do I reset my account password?</p>
</blockquote>
<p>The system can search company help documents, find the password reset instructions, and provide those instructions to the LLM. The LLM then creates a clear response based on the retrieved content.</p>
<p>A simple RAG flow looks like this:</p>
<pre><code class="language-text">User Query → Retrieval → LLM → Response
</code></pre>
<p>The LLM is still responsible for generating the final answer, but it now has useful context to work with.</p>
<hr />
<h2>How a Basic RAG Pipeline Works</h2>
<p>A basic RAG pipeline usually has four main steps.</p>
<h3>1. Store Knowledge in a Searchable Form</h3>
<p>First, documents are collected from sources such as:</p>
<ul>
<li><p>PDFs</p>
</li>
<li><p>Documentation pages</p>
</li>
<li><p>FAQs</p>
</li>
<li><p>Product manuals</p>
</li>
<li><p>Support tickets</p>
</li>
<li><p>Database records</p>
</li>
<li><p>Internal company wikis</p>
</li>
<li><p>Blog posts</p>
</li>
</ul>
<p>These documents are usually broken into smaller pieces called <strong>chunks</strong>.</p>
<p>For example, a 50-page employee handbook might be divided into many smaller sections such as:</p>
<pre><code class="language-text">Chunk 1: Leave policy
Chunk 2: Remote work policy
Chunk 3: Expense reimbursement policy
Chunk 4: Employee benefits
</code></pre>
<p>Each chunk is then stored in a searchable knowledge base.</p>
<hr />
<h3>2. Convert the User Query into a Searchable Format</h3>
<p>When a user asks a question, the RAG system tries to understand its meaning.</p>
<p>For example:</p>
<blockquote>
<p>Can I work from home on Fridays?</p>
</blockquote>
<p>The system searches for chunks related to remote work, work-from-home rules, flexible schedules, or company attendance policies.</p>
<p>The goal is not only to match exact words. A good retrieval system should also understand related meaning.</p>
<p>For example, the phrases below may all be related:</p>
<pre><code class="language-text">Work from home
Remote work
Hybrid work
Flexible location policy
</code></pre>
<hr />
<h3>3. Retrieve Relevant Chunks</h3>
<p>The system selects the most relevant chunks from the knowledge base.</p>
<p>For the question:</p>
<blockquote>
<p>Can I work from home on Fridays?</p>
</blockquote>
<p>It may retrieve:</p>
<pre><code class="language-text">Remote Work Policy:
Employees may work remotely up to two days per week with manager approval.
</code></pre>
<p>This retrieved text becomes context for the LLM.</p>
<hr />
<h3>4. Generate the Final Response</h3>
<p>The LLM receives both the user question and the retrieved context.</p>
<pre><code class="language-text">User Question:
Can I work from home on Fridays?

Retrieved Context:
Employees may work remotely up to two days per week with manager approval.
</code></pre>
<p>The LLM can then generate a response such as:</p>
<blockquote>
<p>Yes, you may be able to work from home on Fridays if it fits within the two remote days allowed per week and your manager approves it.</p>
</blockquote>
<p>This answer is more reliable than asking the LLM to guess the company policy.</p>
<hr />
<h2>RAG Architecture Diagram</h2>
<pre><code class="language-text">                ┌──────────────────┐
                │   User Question  │
                └────────┬─────────┘
                         │
                         ▼
                ┌──────────────────┐
                │ Retrieval System │
                │ Search Knowledge │
                │      Base        │
                └────────┬─────────┘
                         │
                         ▼
                ┌──────────────────┐
                │ Relevant Context │
                │ Documents/Chunks │
                └────────┬─────────┘
                         │
                         ▼
                ┌──────────────────┐
                │       LLM        │
                │ Generates Answer │
                └────────┬─────────┘
                         │
                         ▼
                ┌──────────────────┐
                │ Final Response   │
                └──────────────────┘
</code></pre>
<hr />
<h2>Where RAG Works Well</h2>
<p>RAG is especially useful when an application needs answers based on specific, changing, or private information.</p>
<p>Common use cases include:</p>
<h3>Customer Support Chatbots</h3>
<p>A support chatbot can retrieve answers from help articles, return policies, troubleshooting guides, and product documentation.</p>
<p>For example:</p>
<blockquote>
<p>How do I cancel my subscription?</p>
</blockquote>
<p>Instead of guessing, the chatbot can retrieve the exact cancellation instructions.</p>
<hr />
<h3>Internal Company Knowledge Assistants</h3>
<p>Employees often need information from internal documents.</p>
<p>Examples include:</p>
<ul>
<li><p>How to request leave</p>
</li>
<li><p>How to submit expenses</p>
</li>
<li><p>Security policies</p>
</li>
<li><p>Engineering documentation</p>
</li>
<li><p>HR policies</p>
</li>
<li><p>Onboarding guides</p>
</li>
</ul>
<p>A RAG system can help employees search internal knowledge using natural language.</p>
<hr />
<h3>Product Documentation Search</h3>
<p>Software products often have large documentation websites.</p>
<p>A user may ask:</p>
<blockquote>
<p>How do I configure OAuth in this product?</p>
</blockquote>
<p>A RAG system can retrieve the relevant documentation section and help generate a direct explanation.</p>
<hr />
<h3>Legal, Medical, or Financial Document Search</h3>
<p>Professionals often work with large sets of documents.</p>
<p>For example:</p>
<ul>
<li><p>Legal contracts</p>
</li>
<li><p>Compliance policies</p>
</li>
<li><p>Medical research papers</p>
</li>
<li><p>Financial reports</p>
</li>
</ul>
<p>RAG can help users locate relevant sections quickly. However, these domains require extra care because incorrect answers can have serious consequences.</p>
<hr />
<h3>Personal Knowledge Assistants</h3>
<p>RAG can also be used with personal notes, bookmarks, PDFs, or saved articles.</p>
<p>For example:</p>
<blockquote>
<p>What did I write about my project idea last month?</p>
</blockquote>
<p>The system can search your notes and provide a summary based on the retrieved content.</p>
<hr />
<h2>Good Retrieval vs Poor Retrieval</h2>
<p>The quality of a RAG system depends heavily on retrieval.</p>
<p>Consider this question:</p>
<blockquote>
<p>What is the refund policy for annual subscriptions?</p>
</blockquote>
<h3>Good Retrieval</h3>
<p>The system retrieves:</p>
<pre><code class="language-text">Annual subscriptions can be refunded within 14 days of purchase if less than 20% of the service has been used.
</code></pre>
<p>The LLM can now produce a useful answer.</p>
<h3>Poor Retrieval</h3>
<p>The system retrieves:</p>
<pre><code class="language-text">Monthly subscriptions can be canceled at any time.
</code></pre>
<p>This information is related to subscriptions, but it does not answer the user's question about annual refunds.</p>
<p>The LLM may still generate a confident response, but the answer may be wrong because the context was wrong.</p>
<p>A simple comparison looks like this:</p>
<pre><code class="language-text">Good Retrieval:
Question → Correct policy document → Accurate response

Poor Retrieval:
Question → Unrelated document → Incorrect or confusing response
</code></pre>
<p>RAG quality is often limited by the quality of the retrieved information.</p>
<hr />
<h2>Why RAG Sometimes Gives Incorrect Answers</h2>
<p>Many people assume that adding RAG automatically makes an LLM accurate. In reality, RAG improves the chances of a correct answer, but several things can still go wrong.</p>
<hr />
<h2>1. Poor Retrieval and Missing Context</h2>
<p>The system may fail to find the correct document.</p>
<p>For example, a user asks:</p>
<blockquote>
<p>What happens if I miss a payment deadline?</p>
</blockquote>
<p>But the retrieval system finds a document about account cancellation instead of late payment fees.</p>
<p>The LLM may use the wrong document and create an inaccurate answer.</p>
<p>Sometimes the correct document exists, but the search system does not retrieve it because:</p>
<ul>
<li><p>The query uses different wording</p>
</li>
<li><p>Important keywords are missing</p>
</li>
<li><p>The document is poorly indexed</p>
</li>
<li><p>The document is stored in the wrong category</p>
</li>
<li><p>The retrieval system returns only a few results</p>
</li>
<li><p>The relevant content is ranked too low</p>
</li>
</ul>
<p>If the LLM does not receive the right context, it cannot reliably produce the right answer.</p>
<hr />
<h2>2. Poor Chunking Can Hurt Response Quality</h2>
<p>Before documents are stored in a RAG system, they are usually split into chunks.</p>
<p>Chunking is important because an LLM cannot receive an entire library of documents for every question.</p>
<p>However, bad chunking can remove important context.</p>
<p>Imagine this policy:</p>
<pre><code class="language-text">Employees may work remotely up to two days per week.
Remote work requires manager approval.
Remote work is not allowed during the first 30 days of employment.
</code></pre>
<p>If this is split badly, the system may retrieve only:</p>
<pre><code class="language-text">Employees may work remotely up to two days per week.
</code></pre>
<p>The LLM may answer:</p>
<blockquote>
<p>Yes, you can work remotely two days per week.</p>
</blockquote>
<p>But it may miss the important conditions about manager approval and the first 30 days of employment.</p>
<p>A better chunk keeps related information together:</p>
<pre><code class="language-text">Employees may work remotely up to two days per week with manager approval.
Remote work is not allowed during the first 30 days of employment.
</code></pre>
<h3>Chunking Comparison</h3>
<pre><code class="language-text">Poor Chunking:
[Employees may work remotely up to two days per week.]

[Remote work requires manager approval.]

[Remote work is not allowed during the first 30 days.]

Result: Important rules may be separated.

Better Chunking:
[Employees may work remotely up to two days per week with manager approval.
Remote work is not allowed during the first 30 days of employment.]

Result: The LLM receives complete context.
</code></pre>
<p>Chunk size, overlap between chunks, headings, and document structure can all affect response quality.</p>
<hr />
<h2>3. Context Window Limitations</h2>
<p>LLMs have a limited amount of text they can process at one time. This limit is called the <strong>context window</strong>.</p>
<p>A RAG system may retrieve many relevant documents, but not all of them can always fit into the model's context.</p>
<p>For example, imagine a user asks:</p>
<blockquote>
<p>Compare all security requirements across our 20 internal policy documents.</p>
</blockquote>
<p>The system may find useful information in many documents. But if only a few chunks fit into the context window, some important details may be left out.</p>
<pre><code class="language-text">Knowledge Base:
Document A
Document B
Document C
Document D
Document E
Document F

LLM Context Window:
Document A
Document B
Document C

Missing:
Document D
Document E
Document F
</code></pre>
<p>If the missing documents contain exceptions or updated rules, the final answer may be incomplete.</p>
<p>Even when a model has a large context window, sending too much information can create other problems:</p>
<ul>
<li><p>More cost</p>
</li>
<li><p>Slower responses</p>
</li>
<li><p>Important details getting buried in too much text</p>
</li>
<li><p>Lower-quality reasoning due to irrelevant context</p>
</li>
</ul>
<p>RAG is not just about retrieving more documents. It is about retrieving the most useful documents.</p>
<hr />
<h2>4. Hallucinations Can Still Happen</h2>
<p>RAG reduces hallucinations, but it does not eliminate them.</p>
<p>A hallucination happens when an LLM generates information that is not supported by the available context.</p>
<p>For example, the retrieved document says:</p>
<pre><code class="language-text">Users can request a refund within 14 days.
</code></pre>
<p>But the model answers:</p>
<blockquote>
<p>Users can request a full refund within 30 days, and processing takes 3 business days.</p>
</blockquote>
<p>The model may have added details that were never present in the retrieved content.</p>
<p>This can happen because LLMs are trained to generate fluent, helpful-sounding language. If the context is incomplete, the model may fill gaps with assumptions.</p>
<p>To reduce hallucinations, RAG systems can be designed to:</p>
<ul>
<li><p>Ask the model to answer only from the provided context</p>
</li>
<li><p>Show source citations with the answer</p>
</li>
<li><p>Tell the model to say “I don’t know” when information is missing</p>
</li>
<li><p>Use confidence checks</p>
</li>
<li><p>Verify answers against retrieved documents</p>
</li>
<li><p>Limit unsupported claims</p>
</li>
</ul>
<p>Still, no prompt or system design can guarantee zero hallucinations.</p>
<hr />
<h2>5. Knowledge Bases Can Become Outdated</h2>
<p>A RAG system is only as current as its knowledge base.</p>
<p>Imagine a company updates its refund policy from 30 days to 14 days. If the old document remains in the knowledge base, the system may retrieve outdated information.</p>
<p>This can lead to confusing or incorrect answers.</p>
<p>Knowledge bases need regular maintenance:</p>
<ul>
<li><p>Add new documents</p>
</li>
<li><p>Remove outdated documents</p>
</li>
<li><p>Update changed policies</p>
</li>
<li><p>Track document versions</p>
</li>
<li><p>Re-index content after updates</p>
</li>
<li><p>Mark old content as archived</p>
</li>
</ul>
<p>For fast-changing information, such as product pricing, stock availability, regulations, or live system status, a static RAG knowledge base may not be enough.</p>
<p>In these cases, the system may need direct access to live APIs or databases.</p>
<hr />
<h2>When RAG Is Not the Right Solution</h2>
<p>RAG is useful, but it is not the best solution for every problem.</p>
<h3>When You Need Real-Time Data</h3>
<p>If users ask questions like:</p>
<blockquote>
<p>What is my current account balance?</p>
</blockquote>
<p>or:</p>
<blockquote>
<p>Is this product in stock right now?</p>
</blockquote>
<p>A RAG system may not be enough because these answers change frequently.</p>
<p>A direct database query or API call is usually better.</p>
<hr />
<h3>When You Need Calculations</h3>
<p>If the task requires precise calculations, RAG alone is not ideal.</p>
<p>For example:</p>
<blockquote>
<p>Calculate the total tax for these 500 transactions.</p>
</blockquote>
<p>The system should use a calculator, code execution tool, or financial system instead of relying only on retrieved text.</p>
<hr />
<h3>When You Need Strict Accuracy</h3>
<p>Some tasks require deterministic and verifiable answers.</p>
<p>Examples include:</p>
<ul>
<li><p>Bank transfers</p>
</li>
<li><p>Medical diagnosis</p>
</li>
<li><p>Legal decisions</p>
</li>
<li><p>Tax filing</p>
</li>
<li><p>Security permissions</p>
</li>
<li><p>Database updates</p>
</li>
</ul>
<p>RAG can help retrieve relevant information, but the final decision should not rely only on an LLM-generated response.</p>
<hr />
<h3>When the Knowledge Base Is Small and Structured</h3>
<p>If you have a small database with clearly structured fields, traditional search or database queries may be simpler.</p>
<p>For example:</p>
<pre><code class="language-text">Find all orders placed by user ID 123.
</code></pre>
<p>A database query is faster, more accurate, and easier to validate than using RAG.</p>
<hr />
<h2>RAG Improves Answers, But Does Not Guarantee Correctness</h2>
<p>RAG is powerful because it gives LLMs access to information beyond their training data.</p>
<p>It can make chatbots more useful, help employees search internal documentation, improve customer support, and provide answers based on private or recent knowledge.</p>
<p>But RAG systems can still fail when:</p>
<ul>
<li><p>The wrong documents are retrieved</p>
</li>
<li><p>Important context is missing</p>
</li>
<li><p>Documents are chunked poorly</p>
</li>
<li><p>The model reaches context window limits</p>
</li>
<li><p>The model hallucinates details</p>
</li>
<li><p>The knowledge base is outdated</p>
</li>
<li><p>The task requires live data or exact calculations</p>
</li>
</ul>
<p>The key idea is simple:</p>
<blockquote>
<p>RAG improves the information available to an LLM, but it does not guarantee that the LLM will always interpret or use that information correctly.</p>
</blockquote>
<p>A strong RAG system needs more than an LLM and a document search feature. It needs good data, good chunking, accurate retrieval, updated knowledge sources, and careful evaluation.</p>
<p>When used for the right problems, RAG can make AI applications much more useful. When used without understanding its limitations, it can still produce answers that sound confident but are incomplete or wrong.</p>
]]></content:encoded></item><item><title><![CDATA[From Prompt to Response: How LLMs Like ChatGPT Actually Work]]></title><description><![CDATA[Ever wondered what actually happens after you press Enter in ChatGPT? How can an AI understand your question, write code, explain complex concepts, or even generate stories?
This article walks through]]></description><link>https://linuxhunting.hashnode.dev/from-prompt-to-response-how-llms-like-chatgpt-actually-work</link><guid isPermaLink="true">https://linuxhunting.hashnode.dev/from-prompt-to-response-how-llms-like-chatgpt-actually-work</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[GenAI Cohort]]></category><dc:creator><![CDATA[Vibhu Khati]]></dc:creator><pubDate>Wed, 01 Jul 2026 15:12:17 GMT</pubDate><content:encoded><![CDATA[<p><em>Ever wondered what actually happens after you press</em> <em><strong>Enter</strong></em> <em>in ChatGPT? How can an AI understand your question, write code, explain complex concepts, or even generate stories?</em></p>
<p>This article walks through the complete journey—from typing a prompt to receiving a response—while introducing the core concepts behind modern Large Language Models (LLMs).</p>
<hr />
<h1>What is an LLM?</h1>
<p><strong>LLM</strong> stands for <strong>Large Language Model</strong>.</p>
<p>It is an AI model trained on enormous amounts of text so that it can understand and generate human language.</p>
<p>Think of it as a system that has learned the statistical patterns of language by reading billions (or even trillions) of words from books, articles, websites, documentation, research papers, and other publicly available or licensed sources.</p>
<p>Instead of memorizing answers, an LLM learns relationships between words, sentences, and ideas.</p>
<p>For example, after seeing millions of examples like:</p>
<pre><code class="language-plaintext">The capital of France is Paris.
</code></pre>
<p>and</p>
<pre><code class="language-plaintext">Paris is one of Europe's largest cities.
</code></pre>
<p>the model gradually learns that <strong>France</strong> and <strong>Paris</strong> are strongly connected.</p>
<p>It doesn't "know" facts the way humans do—it learns patterns that help it predict what text is likely to come next.</p>
<hr />
<h2>What Problems Do LLMs Solve?</h2>
<p>Before LLMs, many Natural Language Processing (NLP) tasks required separate models.</p>
<p>For example:</p>
<ul>
<li><p>One model for translation</p>
</li>
<li><p>Another for summarization</p>
</li>
<li><p>Another for question answering</p>
</li>
<li><p>Another for sentiment analysis</p>
</li>
</ul>
<p>LLMs changed this dramatically.</p>
<p>A single model can perform many language tasks simply by changing the prompt.</p>
<p>For example:</p>
<pre><code class="language-plaintext">Translate this to Spanish.
</code></pre>
<pre><code class="language-plaintext">Summarize this article.
</code></pre>
<pre><code class="language-plaintext">Explain recursion like I'm five.
</code></pre>
<pre><code class="language-plaintext">Write Python code for binary search.
</code></pre>
<p>Same model.</p>
<p>Different prompts.</p>
<hr />
<h2>Popular Examples of LLMs</h2>
<p>Some well-known LLMs include:</p>
<ul>
<li><p>ChatGPT (OpenAI)</p>
</li>
<li><p>Claude (Anthropic)</p>
</li>
<li><p>Gemini (Google)</p>
</li>
<li><p>Llama (Meta)</p>
</li>
<li><p>Mistral</p>
</li>
<li><p>DeepSeek</p>
</li>
</ul>
<p>Each model has different strengths, but they all rely on the same fundamental architecture: <strong>Transformers</strong>.</p>
<hr />
<h2>Everyday Applications of LLMs</h2>
<p>Today, LLMs power countless applications:</p>
<ul>
<li><p>AI chatbots</p>
</li>
<li><p>Writing assistants</p>
</li>
<li><p>Code generation</p>
</li>
<li><p>Customer support</p>
</li>
<li><p>Email drafting</p>
</li>
<li><p>Translation</p>
</li>
<li><p>Text summarization</p>
</li>
<li><p>Search assistants</p>
</li>
<li><p>Document analysis</p>
</li>
<li><p>AI agents</p>
</li>
</ul>
<p>You probably interact with an LLM multiple times a day—even if you don't realize it.</p>
<hr />
<h1>What Happens When You Send a Message to ChatGPT?</h1>
<p>Suppose you type:</p>
<blockquote>
<p>Explain recursion in simple words.</p>
</blockquote>
<p>To you, this looks like plain English.</p>
<p>To the computer, it's only the beginning of a processing pipeline.</p>
<p>The journey looks something like this:</p>
<pre><code class="language-text">You
 │
 ▼
Type Prompt
 │
 ▼
Tokenization
 │
 ▼
Convert Tokens into Numbers
 │
 ▼
Transformer Processes Context
 │
 ▼
Predict Next Token
 │
 ▼
Generate Response
</code></pre>
<p>Let's go through each step.</p>
<hr />
<h2>Step 1: You Type a Prompt</h2>
<p>You write:</p>
<pre><code class="language-plaintext">Explain recursion simply.
</code></pre>
<p>This is just text.</p>
<p>The AI cannot directly understand letters like:</p>
<pre><code class="language-plaintext">E
x
p
l
a
i
n
</code></pre>
<p>Computers only understand numbers.</p>
<p>So the first task is converting your text into numbers.</p>
<hr />
<h2>Step 2: Tokenization</h2>
<p>Before converting text into numbers, the sentence is split into <strong>tokens</strong>.</p>
<p>We'll discuss tokenization in detail shortly, but imagine:</p>
<pre><code class="language-plaintext">Explain recursion simply.
</code></pre>
<p>becoming</p>
<pre><code class="language-plaintext">["Explain", "recursion", "simply", "."]
</code></pre>
<p>or sometimes</p>
<pre><code class="language-plaintext">["Expl", "ain", " recursion", " simply", "."]
</code></pre>
<p>Different models tokenize differently.</p>
<hr />
<h2>Step 3: Tokens Become Numbers</h2>
<p>Every token has an ID.</p>
<p>Example:</p>
<table>
<thead>
<tr>
<th>Token</th>
<th>ID</th>
</tr>
</thead>
<tbody><tr>
<td>Explain</td>
<td>5481</td>
</tr>
<tr>
<td>recursion</td>
<td>9243</td>
</tr>
<tr>
<td>simply</td>
<td>284</td>
</tr>
<tr>
<td>.</td>
<td>13</td>
</tr>
</tbody></table>
<p>Now the model works with:</p>
<pre><code class="language-plaintext">5481
9243
284
13
</code></pre>
<p>instead of English.</p>
<hr />
<h2>Step 4: The Transformer Processes Everything</h2>
<p>Now the Transformer examines:</p>
<ul>
<li><p>your entire prompt</p>
</li>
<li><p>relationships between words</p>
</li>
<li><p>grammar</p>
</li>
<li><p>context</p>
</li>
<li><p>previous conversation (within the context window)</p>
</li>
</ul>
<p>It tries to understand what you're asking.</p>
<hr />
<h2>Step 5: Predicting the Next Token</h2>
<p>Here's the surprising part:</p>
<p>An LLM doesn't generate an entire paragraph instantly.</p>
<p>It predicts <strong>one token at a time</strong>.</p>
<p>For example:</p>
<p>Input:</p>
<pre><code class="language-plaintext">Explain recursion simply.
</code></pre>
<p>Possible first prediction:</p>
<pre><code class="language-plaintext">Recursion
</code></pre>
<p>Then:</p>
<pre><code class="language-plaintext">is
</code></pre>
<p>Then:</p>
<pre><code class="language-plaintext">when
</code></pre>
<p>Then:</p>
<pre><code class="language-plaintext">a
</code></pre>
<p>Then:</p>
<pre><code class="language-plaintext">function
</code></pre>
<p>And so on.</p>
<p>Thousands of these predictions happen extremely quickly.</p>
<hr />
<h2>Step 6: You Receive the Response</h2>
<p>Finally, all predicted tokens are joined together into readable text.</p>
<p>What you see is the finished response.</p>
<hr />
<h1>Are ChatGPT's Responses Copied from the Internet?</h1>
<p>One of the biggest misconceptions is:</p>
<blockquote>
<p>"ChatGPT just searches Google."</p>
</blockquote>
<p>It doesn't.</p>
<p>Instead, it generates text by predicting the most probable next token based on what it learned during training and the current conversation.</p>
<p>If it were copying and pasting:</p>
<ul>
<li><p>responses would always be identical</p>
</li>
<li><p>creativity wouldn't exist</p>
</li>
<li><p>code would always be exactly the same</p>
</li>
<li><p>stories couldn't be unique</p>
</li>
</ul>
<p>Instead, every response is generated dynamically.</p>
<hr />
<h1>Why Computers Don't Understand Human Language</h1>
<p>Humans naturally understand:</p>
<pre><code class="language-plaintext">Hello
</code></pre>
<p>Computers do not.</p>
<p>Computers only understand binary:</p>
<pre><code class="language-plaintext">0
1
</code></pre>
<p>Everything—from images to videos to music—is ultimately represented using numbers.</p>
<p>Language is no different.</p>
<p>Before an AI can process:</p>
<pre><code class="language-plaintext">I love programming.
</code></pre>
<p>it must become something like:</p>
<pre><code class="language-plaintext">[491, 82, 9921, 13]
</code></pre>
<p>Only then can the model perform mathematical operations.</p>
<hr />
<h1>What Are Tokens?</h1>
<p>A token is the smallest unit of text that a model processes.</p>
<p>Depending on the tokenizer, a token could be:</p>
<ul>
<li><p>a word</p>
</li>
<li><p>part of a word</p>
</li>
<li><p>punctuation</p>
</li>
<li><p>numbers</p>
</li>
<li><p>symbols</p>
</li>
</ul>
<p>For example:</p>
<pre><code class="language-plaintext">ChatGPT is amazing!
</code></pre>
<p>may become:</p>
<pre><code class="language-plaintext">["Chat", "G", "PT", " is", " amazing", "!"]
</code></pre>
<p>Another tokenizer might produce something completely different.</p>
<hr />
<h2>Why Not Split by Words?</h2>
<p>Because words alone are inefficient.</p>
<p>Imagine the word:</p>
<pre><code class="language-plaintext">unbelievable
</code></pre>
<p>If the model had never seen it, a word-based tokenizer would struggle.</p>
<p>Instead, it may split it into:</p>
<pre><code class="language-plaintext">un
believe
able
</code></pre>
<p>Now it can understand even unfamiliar words by combining known pieces.</p>
<p>This is why modern LLMs usually tokenize using <strong>subwords</strong> rather than whole words.</p>
<hr />
<h2>More Examples</h2>
<p>Sentence:</p>
<pre><code class="language-plaintext">I love AI.
</code></pre>
<p>Possible tokens:</p>
<pre><code class="language-plaintext">["I", " love", " AI", "."]
</code></pre>
<p>Sentence:</p>
<pre><code class="language-plaintext">playing
</code></pre>
<p>Possible tokens:</p>
<pre><code class="language-plaintext">play
ing
</code></pre>
<p>Sentence:</p>
<pre><code class="language-plaintext">unhappiness
</code></pre>
<p>Possible tokens:</p>
<pre><code class="language-plaintext">un
happy
ness
</code></pre>
<p>This approach greatly reduces vocabulary size while improving flexibility.</p>
<hr />
<h1>Why Tokenization Matters</h1>
<p>Tokenization allows models to:</p>
<ul>
<li><p>handle unseen words</p>
</li>
<li><p>support multiple languages</p>
</li>
<li><p>reduce vocabulary size</p>
</li>
<li><p>process text efficiently</p>
</li>
<li><p>represent language numerically</p>
</li>
</ul>
<p>Without tokenization, modern LLMs wouldn't work effectively.</p>
<hr />
<h1>Transformers: The Breakthrough Behind Modern AI</h1>
<p>In 2017, researchers introduced the <strong>Transformer</strong> architecture in the paper:</p>
<blockquote>
<p><strong>Attention Is All You Need</strong></p>
</blockquote>
<p>This fundamentally changed Natural Language Processing.</p>
<p>Nearly every modern LLM—including ChatGPT, Claude, Gemini, Llama, and Mistral—is built upon Transformers.</p>
<hr />
<h2>What Makes Transformers Special?</h2>
<p>Older models processed words one after another.</p>
<p>Transformers process the entire sentence together.</p>
<p>This allows them to understand relationships between distant words.</p>
<p>Example:</p>
<pre><code class="language-plaintext">The animal didn't cross the road because it was tired.
</code></pre>
<p>What does "it" refer to?</p>
<p>The Transformer examines the whole sentence to determine the correct relationship.</p>
<hr />
<h2>Attention: The Secret Ingredient</h2>
<p>Transformers use a mechanism called <strong>Attention</strong>.</p>
<p>Instead of treating every word equally, attention lets the model focus on the most relevant words.</p>
<p>For example:</p>
<pre><code class="language-plaintext">The cat sat on the mat because it was soft.
</code></pre>
<p>The word:</p>
<pre><code class="language-plaintext">it
</code></pre>
<p>is strongly related to:</p>
<pre><code class="language-plaintext">mat
</code></pre>
<p>Attention helps discover these relationships.</p>
<hr />
<h2>Why Transformers Changed AI</h2>
<p>Transformers introduced several advantages:</p>
<ul>
<li><p>Better understanding of long documents</p>
</li>
<li><p>Parallel processing during training</p>
</li>
<li><p>Better context handling</p>
</li>
<li><p>Higher accuracy</p>
</li>
<li><p>Scalability to billions of parameters</p>
</li>
</ul>
<p>Without Transformers, today's LLM revolution wouldn't exist.</p>
<hr />
<h1>Understanding the Context Window</h1>
<p>LLMs cannot remember unlimited information.</p>
<p>They only consider a limited amount of recent input called the <strong>context window</strong>.</p>
<p>Imagine it as a sliding window.</p>
<pre><code class="language-text">Conversation History

□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□

             ↑
      Context Window
</code></pre>
<p>Anything inside the window is visible to the model.</p>
<p>Older information may eventually fall outside the window if the conversation becomes too long.</p>
<p>Larger context windows allow models to handle longer documents, larger codebases, and extended conversations.</p>
<hr />
<h1>Temperature: Why the Same Prompt Can Produce Different Answers</h1>
<p>Temperature controls how predictable or creative the model's responses are.</p>
<h3>Low Temperature (e.g., 0.2)</h3>
<p>Prompt:</p>
<blockquote>
<p>Give a title for an article about AI.</p>
</blockquote>
<p>Possible output:</p>
<pre><code class="language-plaintext">Introduction to Artificial Intelligence
</code></pre>
<p>Predictable.</p>
<p>Consistent.</p>
<p>Great for factual tasks.</p>
<hr />
<h3>High Temperature (e.g., 1.2)</h3>
<p>Same prompt:</p>
<pre><code class="language-plaintext">The Machines Are Learning: A Journey Into Modern AI
</code></pre>
<p>More creative.</p>
<p>More varied.</p>
<p>Better for brainstorming, storytelling, and creative writing.</p>
<hr />
<h1>Putting Everything Together</h1>
<p>When you send a prompt, here's the complete high-level workflow:</p>
<pre><code class="language-text">User
 │
 ▼
Prompt
 │
 ▼
Tokenization
 │
 ▼
Convert Tokens into IDs
 │
 ▼
Embeddings
 │
 ▼
Transformer Layers
 │
 ▼
Attention Mechanism
 │
 ▼
Next Token Prediction
 │
 ▼
Repeat Until Complete
 │
 ▼
Final Response
</code></pre>
<p>Every answer generated by an LLM follows this process, thousands of times per second.</p>
<hr />
<h1>Visualization Diagrams</h1>
<h3>1. What LLM does?</h3>
<pre><code class="language-text">User
 │
 ▼
Prompt
 │
 ▼
LLM
 │
 ▼
Response
</code></pre>
<hr />
<h3>2. What Transformer Does?</h3>
<pre><code class="language-text">Text
 │
 ▼
Tokens
 │
 ▼
Numbers
 │
 ▼
Transformer
 │
 ▼
Generated Text
</code></pre>
<hr />
<h3>3. Context Window Visualization</h3>
<pre><code class="language-text">Conversation History

□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□

        ┌─────────────────────┐
        │ Current Context      │
        └─────────────────────┘
</code></pre>
<hr />
<h3>4. Low vs High Temperature</h3>
<pre><code class="language-text">Prompt
   │
   ├── Temperature = 0.2
   │        │
   │        ▼
   │  Predictable Answer
   │
   └── Temperature = 1.2
            │
            ▼
      Creative Answer
</code></pre>
<hr />
<h3>5. Complete LLM Workflow</h3>
<pre><code class="language-text">User
 │
 ▼
Prompt
 │
 ▼
Tokenizer
 │
 ▼
Token IDs
 │
 ▼
Embeddings
 │
 ▼
Transformer
 │
 ▼
Attention
 │
 ▼
Predict Next Token
 │
 ▼
Repeat
 │
 ▼
Final Response
</code></pre>
<hr />
<h1>Conclusion</h1>
<p>Large Language Models may seem almost magical, but their operation follows a well-defined pipeline. Your text is first broken into tokens, converted into numerical representations, processed by Transformer layers using attention mechanisms, and then used to predict one token at a time until a complete response is formed.</p>
<p>What makes modern LLMs remarkable isn't that they search the web or retrieve prewritten answers—it's their ability to generate coherent, context-aware text by learning statistical patterns from vast amounts of language data. Understanding concepts like tokenization, Transformers, context windows, and temperature provides a solid foundation for exploring more advanced AI topics such as embeddings, fine-tuning, Retrieval-Augmented Generation (RAG), AI agents, and multimodal models.</p>
<p>Whether you're a developer, student, or AI enthusiast, mastering these fundamentals is the first step toward understanding the technology shaping the future of software and human-computer interaction.</p>
]]></content:encoded></item><item><title><![CDATA[Linux Under the hood

]]></title><description><![CDATA[When the linux OS runs your program , it creates a process. That process gets its
. own Virtual address space
. own file descriptors
.own memory
Linux kernel (monolithic kernel) tracks all of this in ]]></description><link>https://linuxhunting.hashnode.dev/linux-under-the-hood</link><guid isPermaLink="true">https://linuxhunting.hashnode.dev/linux-under-the-hood</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Vibhu Khati]]></dc:creator><pubDate>Tue, 21 Apr 2026 17:00:58 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/681626f70cd940f6021c2255/cafa1466-3455-47c4-a65a-bf10aaf3455d.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When the linux OS runs your program , it creates a process. That process gets its</p>
<p>. own Virtual address space</p>
<p>. own file descriptors</p>
<p>.own memory</p>
<p>Linux kernel (monolithic kernel) tracks all of this in a single data structure called task_struct { ... }. That isolation is not just software. The CPU has a register called CR3 that points to the process's page tables. Every memory address your program uses goes through tables. Another process has a completely different CR3 that points to its own page tables.</p>
<p>A thread is just another task_struct { ... } but created with one key difference. It shares the same page tables as its parent. Same heap, same globals, same file descriptors. The only things that are its own are its stack and its CPU registers.</p>
<p>Creating a process means copying the entire page table tree. That takes time and it scales with how much memory your process uses. Creating a thread skips all of that. It just sets up a stack and points at the same address space. That's why thread creation is 10 to 30 times faster. But sharing memory is exactly what causes race conditions.</p>
<p>When you spawn a process, the linux kernel calls fork() (a system call). It copies the entire page tables tree , every level , every entry. Your child process gets its own address space before it runs a single instruction. Threads skip all of that. They call clone with one flag Clone_VM i.e. clone(CLONE_VM). This tells the kernel to share the existing address space instead of copying it. No duplication and no setup. That's the reason thread creation is 10 times faster than fork().</p>
<p>Once both process and thread are running , the CPU scheduler sees no difference between them. Linux's CFS Scheduler keeps a sorted tree of tasks by how much CPU time each has consumed. It always picks the one first that got least time , process or thread , it does not matter. But switching between processes costs more time. Every context switch between processes loads a new value into CR3,(the register that points to page tables). This flushes the TLB (your CPU's cache of address translations). Every memory access after this is a miss until it warms up again.</p>
<p>In context switching between threads , the CR3 stays the same (doesn't change). TLB stays warm. You are just swapping registers and a stack pointer. That's why high performance servers use thread pools instead of forking per request. So, we have two tools fork() for isolation and clone() for speed.</p>
<p>In real world:</p>
<ol>
<li><p>Chrome runs each tab as a separate process, not a thread. If one tab hits a bug ,it seg faults (segmentation fault), the kernel kills that process. The other tabs keep running because they have different page tables. That's the isolation via fork(), as we discussed.</p>
</li>
<li><p>Python has a global interpreter lock (GIL). Only one thread can execute Python byte code at a time. So, if you spawn 10 threads to crunch numbers, you still get 1 core. To actually use multiple cores in Python, we use use the multiprocessing module which calls fork() and gives each worker its own address space.</p>
</li>
<li><p>Apache used to fork() a new process for every incoming request. Each request got full isolation, but fork() is expensive and memory usage stacked up fast.</p>
</li>
<li><p>Nginx took a different approach. It uses a fixed pool of worker processes and inside each worker it handles 1000 of connections, using non-blocking IO on a single thread. So, Fixed workers -&gt; 1 thread, 1000 conns. Less overhead, same isolation at the worker level.</p>
</li>
<li><p>Most modern web frameworks use a thread pool inside a single process. Our Node JS server, Go HTTP handler, Java servlet container , all uses One process -&gt; many threads. Shared heap , fast to spin up, fast to context switch. The trade-off is that a memory corruption bug in one handler can take down the whole server. So, the pattern is the same everywhere.</p>
</li>
</ol>
<p><strong>What happens in a Linux Terminal?</strong></p>
<p>In a Linux terminal , if a linux user performs a simple task, a lot of things needs to happen to accomplish that task. For example, what happens when we simply read a file named hosts using command <strong>cat /etc/hosts.</strong> Following operations happens to accomplish a simple file read operation:</p>
<ol>
<li><p>The cat command must be read and loaded from disk in RAM. Only once it is in RAM, it can be used.</p>
</li>
<li><p>Related libraries must be found and loaded in RAM also.</p>
</li>
<li><p>The /etc/hosts file needs to be located on disk. Because that is what we want to read using cat.</p>
</li>
<li><p>Permissions of the current user need to be checked on this file.</p>
</li>
<li><p>If that is appropriate, then the file contents can be copied to RAM.</p>
</li>
</ol>
<p>All of these different tasks are provided through system calls and library calls.</p>
<p><strong>Understanding System calls</strong></p>
<p>. Processes cannot access the kernel directly.</p>
<p>. System calls are used as an interface for processes to the kernel. glibc provides a library interface to use system calls from programs.</p>
<p>. Common tasks like opening, listing, reading and writing to files all involve system calls.</p>
<p>. The fork() and exec() system calls determine how a process starts</p>
<p>. fork(): the kernel creates an almost identical copy of the current process and replaces that. That's how a process starts a child process. It firsts copy itself and then it will remove its code to be replaced by the code of the child process.</p>
<p>. exec(): the kernel starts a program, which replaced the current process</p>
<p><strong>Understanding Library calls</strong></p>
<p>. System calls are provide by kernel to give access to restricted parts.</p>
<p>. Library calls come from shared libraries and provide functionality.</p>
<p>. There is a large number of library calls, virtually unlimited because it all depends on the shared libraries that are loaded. Many of these library functions are part of the standard C library (libc). Some functions are part of other libraries e.g. math library, libm, or real time library, librt.</p>
<p><strong>Strict seperation between user space and kernel space</strong></p>
<p>. This seperation has been created so that hardware access is restricted to the kernel only. If you want your computer to be reliable , then application should not have an option to interface directly with hardware. The only interface to hardware is linux kernel and the drivers that has been verified to work with linux kernel.</p>
<p>. These drivers must be verified and that is also why Linux does not like proprietary drivers because linux kernel has no means of verifying what the proprietary drivers is doing. That is why you may have heard about Dented Kernels which are kernels that contains proprietary drivers , which will give you problems anyway.</p>
<p>. The kernel provides system calls for users and processes to access hardware. These system calls are the only way , for users and processes , to access hardware .</p>
<p>. User space is memory that is allocated by the kernel for user processes.</p>
<p>. Several elements are all running in user space. For example:</p>
<p>.Network configuration</p>
<p>.Services like a web server</p>
<p>. Applications</p>
<p>. User interfaces</p>
]]></content:encoded></item></channel></rss>