<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yasiru Ramosh on Medium]]></title>
        <description><![CDATA[Stories by Yasiru Ramosh on Medium]]></description>
        <link>https://medium.com/@iAmrAmosh?source=rss-64b465829d14------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*EY8aw-Oo4Ov8t1lqo_MPGA.png</url>
            <title>Stories by Yasiru Ramosh on Medium</title>
            <link>https://medium.com/@iAmrAmosh?source=rss-64b465829d14------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 23:06:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@iAmrAmosh/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[What is n8n]]></title>
            <link>https://medium.com/@iAmrAmosh/what-is-n8n-60267f297d07?source=rss-64b465829d14------2</link>
            <guid isPermaLink="false">https://medium.com/p/60267f297d07</guid>
            <category><![CDATA[n8n]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[n8n-workflow]]></category>
            <dc:creator><![CDATA[Yasiru Ramosh]]></dc:creator>
            <pubDate>Sat, 17 Oct 2026 16:31:01 GMT</pubDate>
            <atom:updated>2026-10-17T16:31:01.810Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Goal is to understand n8n, how workflows operate, and how to build basic automations.</blockquote><p>Also, I’m thinking to plan for 8 levels which can move from beginner level to mastery with n8n</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*7CyzFBasVHZ10xXD--ESEQ.png" /></figure><h3>1. What is n8n?</h3><p><strong>n8n is a low-code workflow automation platform</strong> that connects applications, APIs, and services to automate repetitive tasks.</p><pre>New Email<br>    ↓<br>Extract Information<br>    ↓<br>Save to Google Sheets<br>    ↓<br>Send Notification</pre><p><strong>Why is it important?</strong></p><ul><li>Reduces repetitive work.</li><li>Connects different applications.</li><li>Supports complex business logic.</li><li>Automates AI-powered processes.</li><li>Can be self-hosted.</li></ul><h3>2. How Does n8n Work?</h3><p>n8n follows a simple workflow structure:</p><p><strong>Trigger → Processing → Action</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*moE8sni14Zjl7O0Uevi9Lw.png" /></figure><h3>3. Understanding Nodes</h3><p>Nodes are individual components that perform specific tasks.</p><h3>Essential nodes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*34RMEu1TOeFCGejlUDiINA.png" /></figure><h3>4. Understanding Data Flow</h3><p><em>n8n primarily processes data as </em><strong><em>JSON items.</em></strong></p><p>Example:</p><pre>{<br>  &quot;name&quot;: &quot;Kamal&quot;,<br>  &quot;age&quot;: 25,<br>  &quot;status&quot;: &quot;active&quot;<br>}</pre><p>To access a field, use an <strong>expression</strong>:</p><pre>{{ $json.name }}</pre><p>Output:</p><pre>Kamal</pre><p>Expressions allow nodes to access dynamic data from previous operations.</p><blockquote><strong>Why is this important?</strong></blockquote><blockquote>Without understanding JSON and expressions, you will struggle to connect nodes correctly.</blockquote><h3>5. Types of Workflow Triggers</h3><p>There are three main triggering approaches.</p><ol><li><strong>Manual </strong>— <em>Started by a user </em>— Testing</li><li><strong>Schedule </strong>— <em>Runs at configure time</em> — Daily Report</li><li><strong>Event Driven</strong> — <em>Response to an event </em>— Webhook receives data</li></ol><h3>6. Installing n8n</h3><p>You have two main options:</p><p><strong>n8n Cloud:</strong> Hosted by n8n, requiring no local installation.</p><p><strong>Self-hosted:</strong> Run n8n on your own computer or server.</p><p>For learning, Docker is a good choice.</p><h3>Docker installation</h3><p>First, install Docker.</p><p>Then execute:</p><pre>docker volume create n8n_data</pre><p>Run n8n:</p><pre>docker run -it --rm --name n8n -p 5678:5678 -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n</pre><blockquote>Open:</blockquote><blockquote><a href="http://localhost:5678/">http://localhost:5678</a></blockquote><p>Complete the account setup.</p><p>You can now create workflows.</p><h3>7. Workflow Execution and Debugging</h3><p>Two important execution concepts:</p><p><strong>Manual execution:</strong> Used while developing and testing workflows.</p><p><strong>Production execution:</strong> Workflows execute automatically through configured triggers after being published.</p><p>When something fails:</p><ol><li>Identify the failed node.</li><li>Inspect its input JSON.</li><li>Check its configuration.</li><li>Read the error message.</li><li>Fix and test again.</li></ol><p>n8n provides execution history to help investigate failures.</p><h3>8. Practical Exercise</h3><p>Build this simple workflow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*xv3GDAXwJNnFTtCAQ7_Ahg.png" /></figure><p><strong>Instructions:</strong></p><ol><li>Create a new workflow.</li><li>Add a Manual Trigger.</li><li>Add an HTTP Request node.</li><li>Use this testing API:</li><li><a href="https://jsonplaceholder.typicode.com/todos/1">https://jsonplaceholder.typicode.com/todos/1</a></li><li>Extract the title and completed fields.</li><li>Use an IF node to check whether completed is false.</li><li>Inspect the output of each branch.</li></ol><p><strong>Expected result:</strong> You understand how to fetch data, manipulate it, and execute conditional logic.</p><p>answer,</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60267f297d07" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Evals?]]></title>
            <link>https://medium.com/@iAmrAmosh/evals-c3e48cfcbdfe?source=rss-64b465829d14------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3e48cfcbdfe</guid>
            <category><![CDATA[agents]]></category>
            <category><![CDATA[evaluation]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[ai-evals]]></category>
            <category><![CDATA[rags]]></category>
            <dc:creator><![CDATA[Yasiru Ramosh]]></dc:creator>
            <pubDate>Sun, 27 Sep 2026 19:06:01 GMT</pubDate>
            <atom:updated>2026-09-27T19:06:01.971Z</atom:updated>
            <content:encoded><![CDATA[<h3>Evals</h3><p>For an AI Engineer Evals are most important as much as RAG,<br>Let&#39;s talk about Evals from 101 to deep.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*vSR31mTjdZtFm9C1qeHljQ.png" /></figure><p>In here we are talking about following topics</p><ol><li>what is Eval?</li><li>Build evaluation dataset</li><li>Online vs offline evals</li><li>Deterministic vs model-based evaluation</li><li>RAG evaluation</li><li>Classification metrics</li><li>Evaluation for agents</li><li>Regression testing</li><li>Understand A/B testing</li><li>Track cost and latency</li><li>Common tools/frameworks</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iMVt5VwDkK0TzTuPK2T-_g.png" /></figure><h3><strong>what is Eval?</strong></h3><p>In simply,</p><blockquote>How do we know this AI system is actually getting better?</blockquote><p>these are the factors ,</p><ul><li>Correctness</li><li>Relevance</li><li>Faithfulness / groundedness</li><li>Completeness</li><li>Safety</li><li>Latency</li><li>Cost</li><li>User satisfaction</li></ul><p>For example for a perfect RAG,It sould be with</p><ul><li>Retrieved documents are relevant</li><li>Final answer uses those documents correctly</li><li>No unsupported claims</li><li>Response arrives under 3 seconds</li><li>Cost stays below a target</li></ul><h3>Build evaluation dataset</h3><p>For that we need a representative set of test cases.</p><p>Example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*ubwUcpsFFeI-6jvGtcZTnA.png" /></figure><p>for a good eval it should contain:</p><ul><li>Normal cases</li><li>Edge cases</li><li>Ambiguous questions</li><li>Adversarial questions</li><li>Previously failed cases</li><li>Real production examples</li></ul><h3>Online vs offline evals</h3><p><strong>Offline evals</strong> happen before deployment.</p><p>Useful for:</p><ul><li>Prompt changes</li><li>Model comparisons</li><li>RAG changes</li><li>Agent changes</li></ul><p><strong>Online evals</strong> happen in production.</p><p>Useful for:</p><ul><li>User feedback</li><li>Task success</li><li>Abandonment</li><li>Error rate</li><li>Latency</li><li>Cost</li><li>Conversation escalation</li></ul><h3>Deterministic vs model-based evaluation</h3><p><strong>Deterministic</strong></p><p><em>Some things can be checked automatically.</em></p><pre>prediction == expected_answer</pre><p>Useful for:</p><ul><li>Classification</li><li>Structured extraction</li><li>JSON outputs</li><li>Function calls</li></ul><p>But LLM based answers are mostly open-ended</p><p>Therefore we need to use</p><p><strong>Model-based Evaluation</strong></p><p>So you may use an <strong>LLM-as-a-judge</strong>.</p><p>Example:</p><pre>Question:<br>What is the refund period?<br><br>Reference:<br>Refunds allowed within 30 days.<br><br>Model answer:<br>Customers can request refunds within 30 days.<br><br>Judge:<br>Correctness: 5/5<br>Faithfulness: 5/5</pre><p>You should understand the limitations:</p><ul><li>Judge bias</li><li>Position bias</li><li>Model preference</li><li>Inconsistent scoring</li><li>Judge/model contamination</li></ul><p>But for important Systems we can combine</p><p><strong>automated metrics + LLM judge + human review</strong>.</p><h3>RAG evaluation</h3><p>this is probably the most valuable area.</p><p><strong>RAG evaluation as two separate problems:</strong></p><blockquote>Evaluate the <strong>retriever</strong> separately from the <strong>generator</strong>.</blockquote><p>Retriever metrics:</p><ul><li>Recall@K</li><li>Precision@K</li><li>Hit Rate</li><li>MRR</li><li>NDCG</li></ul><p><em>Example:</em></p><p><em>Expected relevant document = </em><em>doc_17</em></p><p><strong>Evaluate <em>Retrieved:</em></strong></p><pre>doc_4<br>doc_17<br>doc_9</pre><p><em>If </em><em>doc_17 appears in top 3, Hit@3 = 1.</em></p><p><strong><em>Evaluate Generation:</em></strong></p><ul><li>Answer correctness</li><li>Context relevance</li><li>Faithfulness</li><li>Hallucination rate</li></ul><blockquote>A system can fail in two very different ways:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R8M_s6SXMYV-xXXI7ADu2Q.png" /></figure><h3>Classification metrics</h3><p>For ML systems we should know:</p><ul><li>Accuracy</li><li>Precision</li><li>Recall</li><li>F1</li><li>Micro F1</li><li>Macro F1</li><li>Confusion matrix</li></ul><blockquote>just a catch why accuracy misleading?</blockquote><p>Example:</p><pre>99% normal<br>1% fraud</pre><p>A model predicting “normal” every time gets <strong>99% accuracy</strong>, but is useless.</p><blockquote><em>SO where </em><strong><em>precision, recall and F1 </em></strong><em>become important.</em></blockquote><h3>Evaluation for agents</h3><p>Agent evals are becoming increasingly important.In here instead of only checking the final response, evaluate the whole trajectory:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/190/1*mV-jIuvJZXbI8qrwo-AsEA.png" /></figure><p><strong>for this the typical metrics:</strong></p><ul><li>Task success rate</li><li>Tool selection accuracy</li><li>Tool-call correctness</li><li>Number of unnecessary tool calls</li><li>Recovery from tool failure</li><li>Completion time</li><li>Cost per task</li></ul><p>Example:</p><p><em>User:</em></p><blockquote><em>Find my latest invoice and summarize it.</em></blockquote><p>Agent might:</p><pre>1. Search Drive<br>2. Retrieve invoice<br>3. Read file<br>4. Summarize</pre><p><strong>You evaluate whether each action was appropriate.</strong></p><h3>Regression Testing</h3><p>This is one of the most practical concepts.</p><p>Suppose version 1 works on:</p><pre>95 / 100 questions</pre><p>You change the prompt and recheck as version 2</p><p>Version 2 works on:</p><pre>97 / 100 questions</pre><p>So V2 Looks better.</p><blockquote>But maybe it broke 5 important questions that previously worked.</blockquote><blockquote>So we should track:</blockquote><blockquote>- new successes<br>- new failures<br>- unchanged successes<br>- unchanged failures</blockquote><blockquote><strong>Not just average score.</strong></blockquote><h3>A/B testing</h3><p>For production systems:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*hy_w6Mpq20f9wjDwxl7ZOg.png" /></figure><p>which Compare:</p><ul><li>Task success</li><li>User satisfaction</li><li>Conversion</li><li>Latency</li><li>Cost</li></ul><p>This tells us whether an improvement works with actual users.</p><h3>Track cost and latency</h3><blockquote>A model with 2% better quality but 10× cost may not be worth deploying.</blockquote><p>Evaluate:</p><pre>Quality<br>Latency<br>Token usage<br>Cost<br>Throughput</pre><p>Example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*SNH5qPhzXhEeO9Wn37qE8w.png" /></figure><p>Engineering decisions involve the trade-off, not only model quality.</p><h3>Evaluation pipelines</h3><p>A mature workflow looks roughly like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*NGHPccA2Vqsxnt7Yyo0YRQ.png" /></figure><p><strong>Ideally this becomes part of CI/CD.</strong></p><p>for Example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/1*JgYm2Oy5kOWxmn52EqQfNQ.png" /></figure><blockquote>That is what people mean by <strong>evaluation-driven development</strong>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KQbDAWIbJ6uE51O5BS16Ow.png" /></figure><h3>Common tools/frameworks</h3><ul><li><strong>RAGAS</strong>: Faithfulness, Context Precision, Context Recall, and Answer Relevancy</li><li><strong>DeepEval:</strong> A unit-testing tool to check if AI outputs are accurate and safe.</li><li><strong>LangSmith:</strong> Tracks, debugs, and monitors AI apps from testing to production.</li><li><strong>Arize Phoenix:</strong> Visualizes and debugs complex AI and search workflows.</li><li><strong>MLflow:</strong> Tracks different versions of AI experiments and scores their results.</li><li><strong>Weights &amp; Biases:</strong> Compares different models and prompts to find the best quality and cost.</li><li><strong>Promptfoo:</strong> Tests prompts quickly, checks for security flaws, and compares multiple models.</li><li><strong>OpenAI Evals:</strong> Runs standard tests to see how well prompt templates perform.</li><li><strong>TruLens:</strong> Scores how safe and accurate AI answers are using “feedback functions.”</li><li><strong>Giskard:</strong> Automatically scans AI apps for bias, safety risks, and jailbreaks.</li></ul><blockquote>But interviews usually care more about <strong>whether you understand evaluation methodology</strong> than whether you memorized a framework.</blockquote><p>So,</p><p>specifically, I’d recommend being able to explain an eval architecture like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*n9SkKOeQMuRjgofuKg60cw.png" /></figure><p>At the END you should know answers for below questions</p><blockquote><strong>How would you evaluate a RAG system?</strong><br>Evaluate <strong>retrieval</strong> and <strong>answer quality</strong> separately. Check whether the correct documents were retrieved, then measure correctness, relevance, and faithfulness of the final answer.</blockquote><blockquote><strong>How would you detect hallucinations?</strong><br>Compare the answer against the retrieved context. If the answer contains claims that are not supported by the context, flag them as hallucinations.</blockquote><blockquote><strong>How would you compare two prompts/models?</strong><br>Run both on the <strong>same eval dataset</strong> and compare quality, accuracy, latency, cost, and failure cases. Choose based on the required trade-offs.</blockquote><blockquote><strong>How would you create a reliable eval dataset?</strong><br>Use realistic examples from actual user queries and include normal cases, edge cases, difficult cases, and previous failures with expected answers or expected behavior.</blockquote><blockquote><strong>How would you prevent a model update from breaking production?</strong><br>Maintain a <strong>regression eval suite</strong>. Run it before every model/prompt update and compare results against the current production baseline. Don’t deploy if important metrics or critical cases regress.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3e48cfcbdfe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Jev ?]]></title>
            <link>https://medium.com/@iAmrAmosh/what-is-jev-3741243d5c35?source=rss-64b465829d14------2</link>
            <guid isPermaLink="false">https://medium.com/p/3741243d5c35</guid>
            <dc:creator><![CDATA[Yasiru Ramosh]]></dc:creator>
            <pubDate>Thu, 24 Sep 2026 14:06:02 GMT</pubDate>
            <atom:updated>2026-09-24T14:06:02.116Z</atom:updated>
            <content:encoded><![CDATA[<p>Jev, from TypeSafe AI, takes a different approach from chatbot models: it returns structured decisions instead of generating open-ended text.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/120/0*qPANrgUJeoPZeRUK" /><figcaption>logo of JEV</figcaption></figure><p>You provide context and focused questions. Jev returns choices, scores, or probabilities that your application can use directly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*pwqN7FdEmafVHZ4npSvFvA.png" /></figure><p><strong>Why this Hype for?</strong></p><ul><li><em>It can handle classification tasks without training a separate classifier for each task.</em></li><li><em>Speed improvements over selected LLM configurations in its evaluations.</em></li><li><em>Its published pricing charges for input tokens, with no output-token charge.</em></li><li><em>It is designed to evaluate multiple independent questions in parallel.</em></li></ul><p>These are product capabilities and company-reported results not a guarantee that Jev will outperform every alternative.</p><blockquote><strong>Can’t traditional machine learning already do this?</strong></blockquote><blockquote><strong><em>Yes. Classification and scoring are established ML tasks, and a well-trained traditional model can be fast, inexpensive, and accurate.</em></strong></blockquote><blockquote><em>Jev’s appeal is the ability to express different judgments through context and questions, reducing the need to build a separate task-specific classifier each time. General LLMs can also do this;</em></blockquote><blockquote><em>Jev focuses on making those decisions efficient and easy to use in software.</em></blockquote><p>Let’s look at its design, optimizations, use cases, and integration.</p><p>in here we are discussing about following points</p><ul><li><strong><em>How is Jev different from a chatbot model?</em></strong></li><li><strong><em>What optimisations does Jev use?</em></strong></li><li><strong><em>What Can’t Jev Do but LLM can?</em></strong></li><li><strong><em>What can each do that the other doesn’t?</em></strong></li><li><strong><em>What can we build with it?</em></strong></li><li><strong><em>How do we integrate it?</em></strong></li></ul><ol><li><strong>How is Jev different from a chatbot model?</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BcPaP4AsfONRfI7gZ9hKUg.png" /></figure><p>TypeSafe describes a new architecture, but its public introduction doesn’t provide enough detail for a complete layer-by-layer architectural comparison. Describe the <strong>published design</strong>, without guessing its internals.</p><p><strong>2. What optimizations does Jev use?</strong></p><ul><li><strong>Parallel outputs:</strong> Avoids generating a long response token by token.</li><li><strong>Constrained output types:</strong> Produces answers in the expected structure.</li><li><strong>RLCD training:</strong> <em>Reinforcement Learning for Calibrated Decisions</em>, intended to make probabilities reflect correctness.</li><li><strong>Focused decisions:</strong> Optimized for bounded judgments rather than open-ended generation.</li></ul><blockquote>TypeSafe reports speed and cost benefits on its evaluations; actual gains depend on your workload.</blockquote><p><strong>3. What Can’t Jev Do but LLM can?</strong></p><p>Jev focuses on classification: deciding which category an input belongs to. That means it isn’t a replacement for a general-purpose chatbot.</p><ul><li><strong>Generate open-ended content:</strong> <br>Classification does not provide the same functionality as writing articles, generating code or producing detailed explanations.</li><li><strong>Handle every task through labels:</strong> <br>Summarizing a document, translating a paragraph or holding an open-ended conversation requires capabilities beyond selecting categories.</li><li><strong>Guarantee correct predictions:</strong> <br>Ambiguous inputs, overlapping categories and unfamiliar terminology can still lead to mistakes.</li><li><strong>Remove the need for evaluation:</strong> <br>Zero-shot classification means you can attempt a task without providing labelled training examples. It does not guarantee reliable results on your particular data.</li></ul><p>Even if Jev outperforms a larger model on a classification benchmark, that result applies to the tested task and conditions not to every AI capability.</p><p><strong>4. What can each do that the other doesn’t?</strong></p><p>General LLMs can write articles, generate code, explain answers, and tackle extended reasoning. Jev’s API centres on three primitives:</p><ul><li><strong>Choice:</strong> Select an option.</li><li><strong>Score:</strong> Evaluate against a rubric.</li><li><strong>Noul:</strong> Return a probability for a true/false statement.</li></ul><p>General LLMs also support classification and structured outputs Jev’s distinction is its specialized implementation and efficiency claims, not exclusive ownership of those capabilities.</p><p><strong>5. What can we build with it?</strong></p><p><strong>Examples include support-ticket routing, document relevance scoring, selecting tools, and deciding whether an answer needs human review.</strong></p><p><strong>6. How do we integrate it?</strong></p><p>Usually, <strong>adapt your application’s workflow</strong>, rather than retraining your existing model:</p><ol><li>Give Jev the relevant context and small, explicit questions.</li><li>Evaluate independent questions together.</li><li>Combine results using ordinary code.</li><li>Send uncertain cases to a human or stronger reasoning model.</li><li>Use an LLM when you need a written response.</li></ol><p><strong>What should we test before using it?</strong></p><blockquote>A correctly formatted answer can still be wrong. Test Jev on representative examples and compare accuracy, response time, and total cost against an LLM and a traditional classifier. Check whether its confidence estimates help you reliably route uncertain cases for review.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3741243d5c35" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Evolution of AI]]></title>
            <link>https://medium.com/@iAmrAmosh/the-evolution-of-ai-00a352a1db91?source=rss-64b465829d14------2</link>
            <guid isPermaLink="false">https://medium.com/p/00a352a1db91</guid>
            <dc:creator><![CDATA[Yasiru Ramosh]]></dc:creator>
            <pubDate>Wed, 23 Sep 2026 12:09:00 GMT</pubDate>
            <atom:updated>2026-09-23T12:09:00.164Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*97TSkYMXV28gG33kjz8uog.png" /></figure><p>AI can recommend a video, write code, and generate images. But does that mean it can think as broadly as a human?</p><p>To understand the difference, here are five useful concepts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DHP6OtSWzDlAEClwLWf3VQ.png" /></figure><blockquote><strong>These are not five officially agreed stages some describe existing technology, while others describe possible futures.</strong></blockquote><p><strong>1. ANI: AI built for specific tasks</strong></p><p>Artificial Narrow Intelligence operates within particular tasks or domains.</p><p><strong><em>Real example:</em></strong><em> An email spam filter learns to identify unwanted messages. Being excellent at detecting spam doesn’t give it the ability to drive a car.</em></p><p>“Narrow” describes its scope, not how powerful it is.</p><p><strong>Generative AI: AI that creates content</strong></p><p>Generative AI produces content such as text, images, audio, and code.</p><p><strong><em>Real example:</em></strong><em> You ask ChatGPT to draft an email or explain a piece of code.</em></p><p>This is a different kind of label: “generative” describes what AI does, while ANI, AGI, and ASI describe the breadth or level of its capabilities. Creating convincing content doesn’t, by itself, demonstrate general intelligence.</p><p><strong>from here;</strong></p><blockquote><strong>Recursive self-improvement could begin with AGI or with more specialised systems and might contribute to ASI. It is a possible mechanism, not a separate intelligence level or a guaranteed outcome.</strong></blockquote><p><strong>2. AGI: AI with broad, human-level capabilities</strong></p><p>Artificial General Intelligence refers to AI that could learn and perform a wide range of intellectual tasks at a level comparable to humans. Researchers differ on the exact definition and how to test it.</p><p><strong>Imagined example:</strong></p><blockquote>A single system could learn an unfamiliar profession, apply knowledge from other fields, and adapt to new problems without a separate specialized system for every task.</blockquote><p><strong>Is GPT-Astra AGI?</strong></p><p>Whether AI has reached AGI remains disputed. Researchers disagree about what qualifies and what evidence would prove it.</p><p>An important distinction is between using information temporarily and learning lasting skills.</p><p>For example, following a new rule you provide during a conversation doesn’t necessarily mean the AI permanently learned that rule. Saving your preferences is different again.</p><p>AGI would require broad, dependable capabilities across unfamiliar tasks — not simply fluent answers or a good memory.</p><p><strong>When might it arrive?</strong></p><p>Nobody knows for certain. Futurist Ray Kurzweil predicts AGI by <strong>2029</strong>, but that is his forecast, not a scientific consensus or guaranteed deadline.</p><p>This illustrates the goal; it isn’t a verified real-world AGI example.</p><p><strong>3. ASI: AI beyond human intelligence</strong></p><p>Artificial Superintelligence is hypothetical AI that would substantially exceed human intellectual capabilities across many domains.</p><p>Some people say ASI will come with AGI.</p><p><strong>Imagined example:</strong></p><blockquote>A system could outperform leading human teams in scientific discovery, engineering, and strategic planning not merely beat humans at one game.</blockquote><p><strong>The singularity: a possible turning point</strong></p><p>The technological singularity is a hypothesis that technological progress could become so rapid that its consequences become difficult to predict.</p><p><strong>Imagined scenario:</strong></p><blockquote>AI helps build more capable AI, which then accelerates further AI development.</blockquote><p>This is a proposed scenario, not a type of AI or an inevitable next step.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=00a352a1db91" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Prompt Caching: The Hidden Optimization Every AI Engineer Should Know]]></title>
            <link>https://medium.com/@iAmrAmosh/prompt-caching-the-hidden-optimization-every-ai-engineer-should-know-c953fc17cc85?source=rss-64b465829d14------2</link>
            <guid isPermaLink="false">https://medium.com/p/c953fc17cc85</guid>
            <dc:creator><![CDATA[Yasiru Ramosh]]></dc:creator>
            <pubDate>Fri, 28 Aug 2026 19:21:14 GMT</pubDate>
            <atom:updated>2026-08-28T19:21:14.034Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v7T5zDapVot4kBVdJwzDsA.png" /></figure><p>When building an LLM application, we usually focus on model selection, prompt quality, RAG, embeddings, agents, and inference latency.</p><p>But there is another problem that can quietly become expensive:</p><p><strong>Your application may be sending the same context to the model again and again.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A_M0RwOewA4vVlKqRyyuxA.png" /></figure><p>Imagine an AI customer-support agent with:</p><ul><li>5,000 tokens of system instructions</li><li>10,000 tokens of company documentation</li><li>2,000 tokens of tool definitions</li><li>3,000 tokens of examples</li><li>500 tokens of conversation history</li></ul><p>If 100 users ask different questions, a large portion of that context may be repeated.</p><p>Without caching, the model repeatedly processes that common context.</p><p>This is where <strong>prompt caching</strong> becomes important.</p><h3>What is Prompt Caching?</h3><p>Prompt caching is a technique where an LLM provider reuses computation associated with previously processed input context instead of processing the same context from scratch on every request.</p><p>A simplified request might look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/1*10KCJqqROzvCg1fWmHfwEw.png" /></figure><p>If the first three sections remain unchanged while only the user question changes, caching can allow the provider to reuse the computation associated with the stable portion.</p><p>Conceptually:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*_ZIpBX2JXxr38u-1TDpB0A.png" /></figure><p>The important point is:</p><blockquote>Caching does not mean the model caches the answer.</blockquote><p>The dynamic question can still produce a new response every time.</p><h3>Why Does Prompt Caching Matter?</h3><p>There are three major reasons.</p><h3>1. Cost</h3><p>Large prompts can become expensive when repeated thousands of times.</p><p>If an agent repeatedly sends the same 20,000-token context, you’re potentially paying for that input repeatedly.</p><p><strong>Cached input tokens are generally priced differently from un-cached input tokens, depending on the provider and model.</strong></p><p><em>For example,</em></p><ul><li><a href="https://developers.openai.com/api/docs/guides/prompt-caching"><strong><em>OpenAI </em></strong><em>currently supports automatic and explicit prompt caching on supported models, with cached-token usage exposed through the API.</em></a></li><li><a href="https://ai.google.dev/gemini-api/docs/generate-content/caching#:~:text=The%20Gemini%20API%20offers,Explicit%20caching"><strong><em>Google’s Gemini</em></strong><em> API also supports implicit and explicit context caching.</em></a></li></ul><p>So, the important lesson isn’t:</p><blockquote><em>“Prompt caching always saves 90%.”</em></blockquote><p>Instead:</p><blockquote><strong>Caching can substantially reduce the cost of repeatedly sending large, stable contexts, but the exact savings depend on the provider, model, cache mechanism, and workload.</strong></blockquote><h3>2. Latency</h3><p>Processing a huge input repeatedly can also increase latency.</p><p>Suppose an agent repeatedly sends:</p><pre>20,000 static tokens + 200 dynamic tokens</pre><p>Without effective caching:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/241/1*psqV6wI1nRF2TUFgjiC1_Q.png" /></figure><p>With caching:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/249/1*P7lykwM6NOJhSB7tmkBxpA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/243/1*pK7PgZpz95rg9a04Q7ZJCg.png" /></figure><p><em>The exact latency improvement depends on the model and provider, but avoiding repeated processing of large common prefixes can be valuable in latency-sensitive applications.</em></p><h3>3. Scalability</h3><p>This becomes particularly important for production AI systems.</p><p>Imagine an AI agent serving:</p><pre>10 requests<br>100 requests<br>1,000 requests<br>10,000 requests</pre><p>If every request contains the same large system prompt, documentation, and tool definitions, the amount of repeated context grows with traffic.</p><p>Caching gives us an architectural optimization:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*WFAYUbPGp3tWXuURMQfQbw.png" /></figure><p>This is why prompt caching is not simply an API feature.</p><p><strong>It can be part of your AI system architecture.</strong></p><h3>Prompt Caching vs. Context Caching</h3><p>These terms are often used interchangeably, but there is a useful distinction.</p><h3>Prompt caching</h3><p>Prompt caching is the broader concept:</p><blockquote><em>Reusing computation from repeated input context.</em></blockquote><p>It can be automatic or explicitly controlled depending on the provider.</p><h3>Explicit context caching</h3><p>Some providers allow you to explicitly create a cache containing a large piece of context.</p><p>For example, Gemini allows you to create a cached content resource and then reference it in later requests.</p><p>Conceptually:</p><pre>Create cache<br>     ↓<br>cachedContents/abc123<br>     ↓<br>Request 1 ──┐<br>Request 2 ──┤<br>Request 3 ──┤──&gt; Gemini<br>Request 4 ──┤<br>Request 5 ──┘</pre><h3>Automatic vs. Explicit Caching</h3><p>There are two common approaches.</p><h3>Automatic / Implicit Caching</h3><p>The provider automatically attempts to identify reusable context.</p><p>You don’t necessarily have to create a cache object yourself.</p><p>For example, Gemini 2.5 and newer models currently support implicit caching, and Google recommends putting large, common content at the beginning of the prompt and sending similar prefixes close together in time to increase cache-hit probability.</p><p>OpenAI also supports automatic prompt caching for eligible requests.</p><p>The application simply sends the request normally.</p><pre>response = client.models.generate_content(<br>    model=&quot;gemini-2.5-pro&quot;,<br>    contents=prompt,<br>)</pre><p>The provider handles the caching mechanism.</p><h3>Explicit Caching</h3><p>Explicit caching gives you more control.</p><p>The basic workflow is:</p><pre>1. Create cache<br>       ↓<br>2. Store reusable context<br>       ↓<br>3. Receive cache ID<br>       ↓<br>4. Send queries referencing cache<br>       ↓<br>5. Monitor usage<br>       ↓<br>6. Extend or delete cache</pre><p>This is particularly useful when you know that a large corpus will be reused repeatedly.</p><p>Examples include:</p><ul><li>large documentation</li><li>source code</li><li>long transcripts</li><li>product manuals</li><li>large system instructions</li><li>repeated analysis of the same media</li><li>enterprise knowledge bases</li></ul><h3>Implementing Explicit Context Caching with Gemini</h3><p>Google’s current Python SDK is:</p><pre>pip install -U google-genai</pre><p>Then configure your API key:</p><pre>export GEMINI_API_KEY=&quot;your-api-key&quot;</pre><p>On Windows PowerShell:</p><pre>$env:GEMINI_API_KEY=&quot;your-api-key&quot;</pre><h3>Step 1: Initialize the Gemini Client</h3><pre>from google import genai<br>from google.genai import types</pre><pre>client = genai.Client()</pre><p>You can then choose a supported model.</p><pre>MODEL = &quot;gemini-2.5-pro&quot;</pre><p>Always verify the currently supported models and caching limits in Google’s documentation because these requirements can change.</p><h3>Step 2: Prepare the Context</h3><p>Suppose we have a large collection of documentation.</p><pre>large_reference_text = &quot;&quot;&quot;<br>Company Documentation</pre><pre>Product: ExampleAI</pre><pre>ExampleAI is an enterprise AI platform.</pre><pre>Authentication:<br>Users authenticate using OAuth 2.0.</pre><pre>API:<br>POST /api/v1/users<br>GET /api/v1/users/{id}</pre><pre>Error Handling:<br>401 = Unauthorized<br>403 = Forbidden<br>404 = Resource not found</pre><pre>...</pre><pre>&quot;&quot;&quot;</pre><p>In a real application, this could instead come from:</p><pre>PDFs<br>Documentation<br>Source code<br>Database exports<br>Transcripts<br>Product manuals</pre><h3>Step 3: Create the Cache</h3><pre>cache = client.caches.create(<br>    model=MODEL,<br>    config=types.CreateCachedContentConfig(<br>        display_name=&quot;company-documentation&quot;,<br>        system_instruction=(<br>            &quot;You are an expert technical support assistant. &quot;<br>            &quot;Answer questions using the provided company documentation.&quot;<br>        ),<br>        contents=[large_reference_text],<br>        ttl=&quot;900s&quot;,<br>    ),<br>)</pre><pre>print(&quot;Cache created:&quot;)<br>print(cache.name)<br>print(&quot;Expires:&quot;, cache.expire_time)</pre><p>The important part is:</p><pre>cached_content</pre><p>is now stored as a reusable cache resource.</p><p>Google’s current documentation describes explicit caching as passing content to the model once and then referring to the cached tokens in subsequent calls.</p><h3>Step 4: Use the Cache</h3><p>Now we don’t need to resend the large context manually.</p><pre>response = client.models.generate_content(<br>    model=MODEL,<br>    contents=&quot;How does authentication work?&quot;,<br>    config=types.GenerateContentConfig(<br>        cached_content=cache.name,<br>    ),<br>)</pre><pre>print(response.text)</pre><p>Another request:</p><pre>response = client.models.generate_content(<br>    model=MODEL,<br>    contents=&quot;What does HTTP 403 mean in our API?&quot;,<br>    config=types.GenerateContentConfig(<br>        cached_content=cache.name,<br>    ),<br>)</pre><pre>print(response.text)</pre><p>Notice what changed.</p><blockquote>The large documentation didn’t change. Only the question changed.</blockquote><pre>CACHE<br> ├── Company documentation<br> ├── System instruction<br> └── Shared context</pre><pre>        +</pre><pre>Question 1<br>Question 2<br>Question 3<br>Question 4</pre><p>That’s the fundamental idea behind context caching.</p><h3>How Do You Know the Cache Is Actually Being Used?</h3><p>This is one of the most important questions.</p><p>Don’t just assume caching is working.</p><p><strong>Measure it.</strong></p><p>For Gemini’s Generate Content API, the response usage metadata exposes cached token information.</p><p>For example:</p><pre>response = client.models.generate_content(<br>    model=MODEL,<br>    contents=&quot;Explain the authentication mechanism.&quot;,<br>    config=types.GenerateContentConfig(<br>        cached_content=cache.name,<br>    ),<br>)</pre><pre>usage = response.usage_metadata</pre><pre>print(&quot;Prompt tokens:&quot;,<br>      usage.prompt_token_count)</pre><pre>print(&quot;Cached tokens:&quot;,<br>      usage.cached_content_token_count)</pre><pre>print(&quot;Output tokens:&quot;,<br>      usage.candidates_token_count)</pre><p>A non-zero:</p><pre>cached_content_token_count</pre><p>indicates that cached content was used for that request.</p><p>This is much better than simply assuming:</p><blockquote><em>“I created a cache, therefore caching is working.”</em></blockquote><h3>Inspecting the Cache Itself</h3><p>You generally cannot retrieve the original cached content as a normal document.</p><p>Instead, you can inspect cache metadata.</p><pre>active_cache = client.caches.get(<br>    name=cache.name<br>)</pre><pre>print(&quot;Name:&quot;, active_cache.name)<br>print(&quot;Model:&quot;, active_cache.model)<br>print(&quot;Created:&quot;, active_cache.create_time)<br>print(&quot;Expires:&quot;, active_cache.expire_time)</pre><p>Google explicitly documents retrieving metadata such as the cache name, model, creation time, update time, expiration time, and usage metadata, while the cached content itself is not retrievable for viewing.</p><h3>List Existing Caches</h3><p>You can also inspect the caches associated with your project.</p><pre>for cached in client.caches.list():<br>    print(<br>        f&quot;ID: {cached.name} | &quot;<br>        f&quot;Model: {cached.model} | &quot;<br>        f&quot;Expires: {cached.expire_time}&quot;<br>    )</pre><p>This is useful when managing production applications.</p><p>For example:</p><pre>cachedContents/support-docs<br>cachedContents/product-manual<br>cachedContents/codebase-v3<br>cachedContents/legal-docs</pre><h3>Delete a Cache</h3><p>When you no longer need an explicit cache:</p><pre>client.caches.delete(<br>    name=cache.name<br>)</pre><p>Explicit context caching can involve storage costs based on cached token count and how long the cache is retained, so cache lifecycle management matters.</p><h3>TTL: The Cache Doesn’t Have to Live Forever</h3><p>You can define how long the cache should remain available.</p><p>For example:</p><pre>ttl=&quot;900s&quot;</pre><p>means approximately:</p><pre>15 minutes</pre><p>You could also use a longer duration when your workload benefits from it.</p><p>The right TTL depends on your workload.</p><p>For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/191/1*ncMOtjTFbCkxT_zTW72SgA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/198/1*lofKpBFU7MG9u0LRl6OrQw.png" /></figure><p>The important thing is to balance:</p><blockquote>cache storage cost vs. repeated input processing cost</blockquote><h3>The Most Important Prompt-Design Rule</h3><p>If you’re relying on prefix-based caching, <strong>put stable content first and dynamic content later.</strong></p><p>Bad structure:</p><pre>USER QUESTION + SYSTEM INSTRUCTIONS + DOCUMENTATION + TOOLS</pre><p>The beginning changes every time.</p><p>Better:</p><pre>SYSTEM INSTRUCTIONS + TOOLS + DOCUMENTATION + USER QUESTION</pre><p>Now the common prefix is much more stable.</p><p>Conceptually:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/191/1*HeW-KvyDxYkN39GAcNvJ3A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*FQC4sTOf0yK7C0H-CJbrOA.png" /></figure><p>This pattern is recommended by both Google and OpenAI for improving cache reuse.</p><h3>What Can Break Cache Reuse?</h3><p>A common mistake is constantly changing the supposedly stable portion of the prompt.</p><p>For example:</p><pre>system_prompt = f&quot;&quot;&quot;<br>You are an AI assistant.Follow the company policies.<br>Use the provided documentation.<br>Follow the available tool definitions.<br>&quot;&quot;&quot;</pre><pre>Current time: {datetime.now()}</pre><pre>User ID: {user_id}</pre><pre>Random session ID: {session_id}</pre><pre>Company documentation:<br>{documentation}<br>&quot;&quot;&quot;</pre><p>This makes the beginning of the prompt dynamic.</p><p><strong>A better architecture is:</strong></p><pre>system_prompt = &quot;&quot;&quot;<br>You are an AI assistant.Follow the company policies.<br>Use the provided documentation.<br>Follow the available tool definitions.<br>&quot;&quot;&quot;</pre><pre>dynamic_context = f&quot;&quot;&quot;<br>Current time: {datetime.now()}<br>User ID: {user_id}<br>Session ID: {session_id}<br>&quot;&quot;&quot;</pre><pre>prompt = system_prompt + dynamic_context + user_question</pre><p>The exact caching behavior is provider-specific, but the architectural principle is universal:</p><blockquote><strong><em>Separate stable context from dynamic context.</em></strong></blockquote><h3>Prompt Caching in an AI Agent</h3><p>This becomes even more interesting with agents.</p><p>Imagine:</p><pre>AI Agent<br>│<br>├── System instructions<br>├── Safety rules<br>├── 30 tools<br>├── Company policies<br>├── Product documentation<br>├── User profile<br>│<br>└── Current task</pre><p>The agent might make 10–20 model calls during one workflow.</p><p>Without effective caching:</p><pre>Call 1 → large context<br>Call 2 → large context<br>Call 3 → large context<br>Call 4 → large context<br>...<br>Call 20 → large context</pre><p>With caching:</p><pre>              ┌── Call 1<br>              ├── Call 2<br>Large context ├── Call 3<br>     ↓        ├── Call 4<br>   CACHE      ├── ...<br>              └── Call 20</pre><p>This is where caching becomes a serious production optimization.</p><h3>But Don’t Cache Everything</h3><p>Caching isn’t automatically beneficial.</p><p>Suppose your prompt is:</p><pre>&quot;What&#39;s the weather today?&quot;</pre><p>There isn’t much repeated context.</p><p>Caching probably isn’t the main optimization.</p><p>But this:</p><pre>50,000-token technical documentation + 20 tools + large system prompt + 200-token question</pre><p>is a very different workload.</p><p>A useful rule is:</p><blockquote><strong><em>The more frequently a large context is reused, the more interesting caching becomes.</em></strong></blockquote><h3>Cache Hit Rate Matters</h3><p>One metric I would monitor in production is:</p><pre>Cache Hit Rate = Cached Input Tokens / Total Input Tokens</pre><p>For example:</p><pre>Total input tokens:     10,000,000<br>Cached input tokens:     8,000,000</pre><pre>Cache hit ratio ≈ 80%</pre><p>That tells you much more than simply knowing:</p><blockquote><em>“We enabled caching.”</em></blockquote><p>You should monitor:</p><pre>Cache hit rate<br>Cached tokens<br>Uncached tokens<br>Input cost<br>Cache storage cost<br>Latency<br>Requests per cache<br>Cache lifetime</pre><p>This allows you to determine whether caching is actually improving the system.</p><h3>A Simple Cost Model</h3><p>You can think about caching like this:</p><p>Without caching:</p><pre><br>Total cost ≈ Number of requests × Static input tokens × Normal input price</pre><p>With caching:</p><pre>Total cost ≈ Cache creation/storage cost + Cached input cost + Dynamic input cost + Output cost</pre><p>The exact pricing formula depends on the provider.</p><p>Therefore, don’t assume:</p><blockquote><em>“Caching is always cheaper.”</em></blockquote><p>Instead ask:</p><blockquote><strong><em>Is the cost of maintaining the cache lower than repeatedly processing the same context?</em></strong></blockquote><p>That’s the engineering question.</p><h3>Prompt Caching Is Not a Replacement for Good Architecture</h3><p>Caching doesn’t fix everything.</p><p>If your prompt is unnecessarily huge:</p><pre>100,000 tokens</pre><p>you shouldn’t simply say:</p><blockquote><em>“Let’s cache it.”</em></blockquote><p>You should first ask:</p><ul><li>Do we need all of this context?</li><li>Can we summarize it?</li><li>Can we retrieve only relevant information?</li><li>Can we remove redundant instructions?</li><li>Can we move information into tool descriptions?</li><li>Can we reduce conversation history?</li><li>Can we use a smaller model for some tasks?</li></ul><p>Caching should be one optimization in the architecture — not an excuse for inefficient prompts.</p><h3>A Practical Architecture</h3><p>For a production AI agent, I would think about context like this:</p><pre>                  AI AGENT<br>                     │<br>       ┌─────────────┼──────────────┐<br>       │             │              │<br>       ▼             ▼              ▼<br>   STATIC         SEMI-STATIC     DYNAMIC<br>       │             │              │<br> System prompt    User profile    User query<br> Tool definitions Company policy  Current state<br> Core rules       Documentation   Tool results<br>       │             │              │<br>       └─────────────┼──────────────┘<br>                     ▼<br>                  CONTEXT<br>                     │<br>                     ▼<br>                LLM REQUEST</pre><p>Then optimize each category differently.</p><pre>STATIC<br>→ Cache aggressively</pre><pre>SEMI-STATIC<br>→ Cache when reuse justifies it</pre><pre>DYNAMIC<br>→ Don&#39;t force caching</pre><p>This is a much better way to think about prompt caching than simply:</p><blockquote><em>“Turn caching on.”</em></blockquote><h3>Final Takeaway</h3><p>Prompt caching is not simply a trick for reducing API bills.</p><p>It is a way of designing LLM applications around <strong>reusable context</strong>.</p><p>The key principles are:</p><pre>1. Identify stable context<br>2. Keep stable content together<br>3. Put dynamic information later<br>4. Use implicit caching when appropriate<br>5. Use explicit caching when you need more control<br>6. Monitor cached token usage<br>7. Measure the actual cost/latency impact<br>8. Manage cache TTL and lifecycle<br>9. Don&#39;t cache unnecessarily large or irrelevant context<br>10. Combine caching with RAG and other optimization techniques</pre><p>The most important idea is this:</p><blockquote><strong><em>Good AI engineers don’t only optimize what the model generates. They optimize what the model has to repeatedly read.</em></strong></blockquote><p>And as AI agents become more complex, <strong>context management may become just as important as model selection.</strong></p><h3>References</h3><ul><li><a href="https://ai.google.dev/gemini-api/docs/caching?utm_source=chatgpt.com">Google Gemini — Context Caching</a></li><li><a href="https://ai.google.dev/gemini-api/docs/generate-content/caching?utm_source=chatgpt.com">Google Gemini — Generate Content / Context Caching</a></li><li><a href="https://ai.google.dev/gemini-api/docs/tokens?utm_source=chatgpt.com">Google Gemini — Token Usage</a></li><li><a href="https://developers.openai.com/api/docs/guides/latest-model?utm_source=chatgpt.com">OpenAI — Model Guidance / Prompt Caching</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c953fc17cc85" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Authenticate with Amazon Cognito]]></title>
            <link>https://medium.com/@iAmrAmosh/authenticate-with-amazon-cognito-552fb845da37?source=rss-64b465829d14------2</link>
            <guid isPermaLink="false">https://medium.com/p/552fb845da37</guid>
            <dc:creator><![CDATA[Yasiru Ramosh]]></dc:creator>
            <pubDate>Sat, 22 Aug 2026 07:32:23 GMT</pubDate>
            <atom:updated>2026-08-22T07:32:23.393Z</atom:updated>
            <content:encoded><![CDATA[<p>what is cognito?</p><p><em>AWS Service that offers Authentication and Authorization features<br>Allows you to add user registration, sign in, and access control<br>Scalable and Highly available supporting millions of users<br>Supports standards-based Identity Providers (OAuth 2.0, OIDC, SAM L)</em></p><p>context :</p><blockquote>do everything related user signup and oll other things</blockquote><blockquote>protect API by unauthorized users</blockquote><blockquote>provide temporary access for AWS resources</blockquote><p>Core Concepts<br>User Pools</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*Z9Os5ojtvQ2AaV4ZP1o1pg.png" /></figure><p>Identity Pools</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*Kbb8UQ26YXZ9k8sILOA_6Q.png" /></figure><p>so the userpool hosted UI looks like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*B5zyvJujnvOTYDzkm2B97Q.png" /></figure><p>User Pools<br>• Cognito User Pools at their heart are User Directories<br>• Users can Sign Up/ Sign In either directly in Cognito or via an SSO<br>• Cognito leverages common OAuth 2.0 flows such as Implicit/Auth Flo<br>Triggers allow you to inject hooks into auth stages<br>• Integrate with Cognito via Amplify or AWS SDK</p><p>Identity Pools<br>- Cognito Identity Pools provide short-term AWS access for users<br>• Integrate your Identity Provider with your Identity Pool<br>- Guest access for restrictive authorization<br>- Dynamically select IAM Roles via Token Attributes or IAM Policies</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=552fb845da37" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AI Harness: The Control Layer That Turns LLMs into Production-Ready Systems]]></title>
            <link>https://medium.com/@iAmrAmosh/ai-harness-the-control-layer-that-turns-llms-into-production-ready-systems-55ac81677ccd?source=rss-64b465829d14------2</link>
            <guid isPermaLink="false">https://medium.com/p/55ac81677ccd</guid>
            <category><![CDATA[harness]]></category>
            <category><![CDATA[agent-harness]]></category>
            <category><![CDATA[ai-engineering]]></category>
            <category><![CDATA[ai-harness]]></category>
            <category><![CDATA[production]]></category>
            <dc:creator><![CDATA[Yasiru Ramosh]]></dc:creator>
            <pubDate>Sat, 22 Aug 2026 07:30:03 GMT</pubDate>
            <atom:updated>2026-08-22T07:30:03.486Z</atom:updated>
            <content:encoded><![CDATA[<p>An <strong>LLM harness</strong> is the <strong>software layer that surrounds an LLM to make it perform a task reliably</strong>, rather than simply sending a prompt to an API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*wE_9oOPgrj7CFWfRFEjcXA.png" /></figure><h3>Breaking Down the Analogy</h3><ul><li><strong>The Monster (The Base Model):</strong> A raw foundation model has consumed massive amounts of internet data. It is highly capable, unpredictable, and entirely unaligned. If let loose without controls, it can hallucinate, execute destructive commands, or generate toxic content. It possesses raw “strength” but zero common sense.</li><li><strong>The Handcuffs (Input/Output Guardrails):</strong> This represents the semantic filters and parsers placed around the model. In a real-world pipeline, these handcuffs act as security layers — for instance, mechanisms that scan for, detect, and mask out sensitive personal information before the model can process or leak it. You are restricting what the “hands” can touch.</li><li><strong>The Limited Running Area (Sandboxing &amp; Scoping):</strong> This represents restricted execution environments. When building agentic architectures that can take actions, you never give the LLM root access to your machine. You confine it to a narrow, isolated environment, often running it inside a containerized setup like Docker. Even if the “monster” tries to break something, it only hits the walls of its cage, lacking the permissions to access the broader system or the internet.</li></ul><p>Think:</p><blockquote><strong><em>LLM = brain</em></strong><em><br></em><strong><em>Harness = system controlling, feeding, checking, and coordinating the brain</em></strong></blockquote><h3>Example</h3><p>A simple LLM application:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/235/1*Foxqt2MVAOh8peD2gVCLvg.png" /></figure><p>An LLM harness might look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*CzGLjmVli-fauHsE4FTH6Q.png" /></figure><p>Why call it a “harness”?</p><p>The analogy comes from a <strong>harness used to control a powerful animal</strong>.</p><p>An LLM is powerful but unpredictable. The harness gives your application mechanisms to:</p><ul><li>tell it <strong>what to do</strong></li><li>give it <strong>information</strong></li><li>give it <strong>tools</strong></li><li>restrict <strong>what it can do</strong></li><li>check <strong>what it produced</strong></li><li>recover when something <strong>fails</strong></li><li>observe and measure its behavior</li></ul><h3>AI agent example</h3><p>Imagine you build an AI customer-support agent.</p><p>The LLM itself might simply generate:</p><blockquote><em>“I’ll check your order.”</em></blockquote><p>But your <strong>AI harness</strong> could orchestrate:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/1*luAEphbayP76p8a_cb_VKQ.png" /></figure><p>So the <strong>LLM is the reasoning/generation component</strong>, while the <strong>harness is the system that makes the LLM operate safely and effectively in the application</strong>.</p><h3>This is especially relevant to AI engineering</h3><p>When you’re building <strong>production agents</strong>, the harness can become a major part of the architecture:</p><p><strong>Model + Harness + Tools + Data + Infrastructure = Production AI system</strong></p><p>For example, frameworks such as <strong>LangGraph, OpenAI’s agent tooling, Anthropic’s agent patterns, and similar orchestration systems</strong> can be used to build parts of this kind of harness.</p><p>And this is why I would distinguish:</p><blockquote><strong><em>Prompt engineering:</em></strong><em> “How do I tell the model what to do?”</em></blockquote><p>from</p><blockquote><strong><em>AI engineering:</em></strong><em> “How do I build the entire system around the model, so it reliably does the job?”</em></blockquote><h3>The important distinction</h3><p>The harness <strong>doesn’t fundamentally change the model’s underlying intelligence</strong>.</p><p>Instead, it controls the model’s <strong>operational capabilities</strong>.</p><p>For example, a GPT-like model may be capable of reasoning about databases, but without a database tool:</p><blockquote><em>Model: “I don’t have access to your database.”</em></blockquote><p>With a harness:</p><blockquote><em>Model → </em><em>query_database() → gets data → reasons over it → responds.</em></blockquote><p>You can also restrict it:</p><blockquote><em>❌ Can’t delete data<br> ✅ Can read customer records<br> ✅ Can create support tickets<br> ❌ Can’t access financial records</em></blockquote><p>So you can think of it as:</p><p><strong>Model = brain</strong><br> <strong>Tools = hands</strong><br> <strong>Data/RAG = knowledge/environment</strong><br> <strong>Harness = control system + nervous system</strong></p><blockquote><em>And in serious production AI systems, </em><strong><em>the harness can be just as important as the model itself.</em></strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55ac81677ccd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Production-Grade RAG: What Happens Beyond Vector Search?]]></title>
            <link>https://medium.com/@iAmrAmosh/production-grade-rag-what-happens-beyond-vector-search-3c270296d877?source=rss-64b465829d14------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c270296d877</guid>
            <category><![CDATA[query]]></category>
            <category><![CDATA[what-is-in-production-rag]]></category>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[bm25]]></category>
            <dc:creator><![CDATA[Yasiru Ramosh]]></dc:creator>
            <pubDate>Sun, 16 Aug 2026 21:11:06 GMT</pubDate>
            <atom:updated>2026-08-17T18:25:53.964Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1_BogPqIqJWiXBROiELtEQ.jpeg" /></figure><p>Retrieval-Augmented Generation (RAG) is often explained with a very simple architecture:</p><p><strong>Knowledge Base → Vector Database → LLM → Answer</strong></p><p>And technically, that is a RAG system.</p><p>But when you move from a prototype to a <strong>production-grade RAG system</strong>, things become much more interesting.</p><p>A production RAG pipeline isn’t just about storing documents as embeddings and performing a similarity search.</p><blockquote><strong>A production RAG system is not a single retrieval technique. It is an entire information-processing pipeline.</strong></blockquote><p>The Production RAG Pipeline contains with few layers,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/208/1*_X8qb208lsG39QmycGiXRA.png" /></figure><h3>1. Knowledge Layer</h3><blockquote>this part is responsible for from raw documents(ingestion) to create embeddings and indexing. Ingestion is a core in RAG. If bad Ingestion means a bad RAG.</blockquote><p>in here,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uOpEYjb7aa-fD-QlpEa8vQ.png" /></figure><p><strong>1.1 Data Ingestion<br></strong>Gathering Knowledge what actually needed.</p><p>in here,</p><ul><li>collect documents</li><li>detect changes</li><li>parse them</li><li>extract text</li><li>preserve metadata</li><li>identify document structure</li><li>handle deleted/updated documents</li></ul><p><strong>1.2 Document Parsing<br></strong>Once collect Knowledge, we cannot use them as RAW text because it doesn&#39;t give any meanings when considered about tables and other exact structures, therefore we have to get the exact alignments such as,</p><ul><li>headings</li><li>paragraphs</li><li>tables</li><li>lists</li><li>code</li><li>images</li><li>links</li><li>page numbers</li><li>document hierarchy</li></ul><p>as it is,</p><p><strong>1.3. Cleaning / Normalizing<br></strong>Consider about removal of unnecessary stuff which is hurtful when retrieval happens.</p><ul><li><em>headers repeated on every page</em></li><li><em>footers</em></li><li><em>page numbers</em></li><li><em>navigation menus</em></li><li><em>HTML garbage</em></li><li><em>duplicate text</em></li><li><em>OCR artifacts</em></li></ul><p><strong>1.4. Chunking<br></strong>Then we have to divide the document into retrievable units,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*-Sy5DLbEBQ6vFIMCMMzGQQ.png" /></figure><p>as example</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*n7F9zK8vM3yDN72twCOPfg.png" /></figure><p><strong>1.5. Contextual chunk enrichment<br></strong>This is an advanced but very useful stage.</p><p><strong>Instead of embedding only:</strong></p><pre>&quot;Employees receive 14 days of annual leave.&quot;</pre><p><strong>we can enrich it like:</strong></p><pre>&quot;Annual Leave Policy &gt; Full-time Employees:<br>Employees receive 14 days of annual leave.&quot;</pre><p><strong>So, this helps embeddings understand the chunk’s context.</strong></p><p>Also we can attach other stuff for enrichment such as</p><ul><li><em>document title</em></li><li><em>section title</em></li><li><em>department</em></li><li><em>date</em></li><li><em>author</em></li><li><em>permissions</em></li><li><em>entities</em></li></ul><p><strong>1.6. Embedding Conversion<br></strong>Then we have to convert chunks into Vectors using a model,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/199/1*5FK0kF21DsUF8Xn1MobJVA.png" /></figure><p>Then we store these vectors in vector database like (Pinecorn, pgvector etc)</p><p><strong>1.7. Indexing<br></strong>Sake of ease of search we can use indexing strategies like,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*XCpezn-c152m6n0t4ljhJg.png" /></figure><p>To get all possible meaningful information, therefore we need</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*H5mLHHeACOHNwVfPZ_OgtA.png" /></figure><p><strong>2. Querying</strong></p><blockquote>In here we suffer about how can we retrieve the data from database</blockquote><p><strong>2.1. Querying Understanding</strong></p><p>Before retrieval we have to consider about query like</p><ul><li>What is the intent?</li><li>What entities are present?</li><li>What filters apply?</li><li>Which knowledge source should be searched?</li><li>Does this even require RAG?</li></ul><p>This can be rule-based, ML-based, or LLM-based.</p><p><strong>2.2. Query writing</strong></p><p>The user’s natural-language query isn’t always optimal for search.</p><p>Since model know how to get exact from what user exactly needed LLM can rewrite the query,</p><p><strong>User:</strong></p><p><em>“What was that thing we decided about AWS costs?”</em></p><p><strong>Rewrite:</strong></p><p><em>“AWS cost optimization decision”</em></p><p><strong>Or potentially:</strong></p><p><em>“AWS infrastructure cost optimization decision meeting notes architecture”</em></p><p><strong>The system can generate multiple queries:</strong></p><pre>Q1 = AWS cost optimization decision<br>Q2 = AWS infrastructure cost reduction<br>Q3 = AWS billing architecture discussion</pre><p><strong>Then search each.</strong></p><p><strong>2.3. Query Decomposition</strong></p><p>This is important for complex questions, such as one question but there might be many queries,</p><p><strong>User:</strong></p><p><em>“Compare our AWS and Azure costs in Q1 and explain why AWS was chosen.”</em></p><p>That’s actually several questions:</p><pre>Q1 → AWS costs Q1<br>Q2 → Azure costs Q1<br>Q3 → AWS vs Azure decision<br>Q4 → reason AWS was selected</pre><p><strong>Retrieve separately:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*hEW7zgb3Kjfe65uV3p8XsA.png" /></figure><p><strong>2.4. Access control / security filtering</strong></p><p><strong>Before retrieving sensitive information, determine:</strong></p><blockquote>What is this user allowed to see?</blockquote><p><em>For example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/184/1*oqiWVw-2VgGUBmxLckvjFg.png" /></figure><pre>If:<br>user.department = engineering<br>you may filter:<br>department = engineering<br>OR<br>access_level = public </pre><p>This is <strong><em>critical</em></strong> in enterprise RAG.</p><p><strong>3.1 Hybrid Retrieval</strong></p><p>Now we make the search</p><p>There are two ways of search</p><ol><li><strong>Dense (Semantic):</strong></li></ol><ul><li><em>“How much vacation can I take?”</em></li><li><strong>can retrieve:</strong></li><li><em>“Annual leave entitlement…”</em></li></ul><p><strong>even though the words differ.</strong></p><p><strong>2. Sparse (Keyword)</strong>:</p><ul><li><em>“DataEngineerProd”</em></li><li><strong>BM25</strong> is very good at finding the exact term.</li></ul><p>So, in finally its,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/1*uf_drDFG5ReN5YcNWpvX_w.png" /></figure><p><strong>3.2. Candidate Fusion</strong></p><p>Now you’ve got results from different retrievers.</p><p>You need to combine them.</p><p>One common technique is <strong>Reciprocal Rank Fusion (RRF).</strong></p><p>It <strong>combines multiple retrieval signals before final ranking.</strong></p><p><strong>4.1 Reranking</strong></p><p>Now you’ve got perhaps:</p><pre>50 candidate chunks<br>A reranked examine:<br>Query + candidate document</pre><p>and asks:</p><pre>&quot;How relevant is this document to this specific query?&quot;</pre><p>Then:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/182/1*AXO8OXuRER2V77fBWZP-RA.png" /></figure><p>This is often much better than trusting raw vector similarity.</p><p><strong>4.2. Relevance filtering</strong></p><p>Even after reranking:</p><pre>1. 0.94<br>2. 0.91<br>3. 0.89<br>4. 0.43<br>5. 0.31</pre><p>You probably don’t want <strong>#4 and #5.</strong></p><p>So use:</p><blockquote><strong>minimum relevance threshold </strong>or <strong>dynamic selection</strong>.</blockquote><p>Result:</p><blockquote>Top relevant evidence</blockquote><p><strong>4.3. Context Construction</strong></p><p>You have:</p><pre>Chunk A<br>Chunk B<br>Chunk C<br>Chunk D</pre><p>You need to construct the context that the LLM sees.</p><p><strong>Potential operations:</strong></p><ul><li>deduplicate</li><li>reorder</li><li>expand parent chunks</li><li>preserve document hierarchy</li><li>remove irrelevant content</li><li>fit token budget</li><li>prioritize authoritative sources</li></ul><p>For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*SDLC0y5hd1JkkJkLxk6akw.png" /></figure><p><strong>4.4. Prompt Construction</strong></p><p>Now construct the actual LLM request.</p><p>Conceptually:</p><pre>SYSTEM INSTRUCTIONS:<br><br>You are an enterprise assistant.<br>Answer only using provided evidence.<br>If evidence is insufficient, say so.<br>CONTEXT<br>[Document A]<br>…<br>[Document B]<br>…<br>QUESTION:<br><br>What is our refund policy?</pre><p>Production prompts often also specify:</p><ul><li>citation requirements</li><li>refusal behavior</li><li>formatting</li><li>source prioritization</li><li>confidence behavior</li><li>tool usage</li></ul><p><strong>5.1. LLM Generation</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*kN1hP3DdWRT1zH5k89TWOg.png" /></figure><p>But <strong>this isn’t the end of production RAG….</strong></p><p><strong>6. Validation</strong></p><p><strong>6.1. Grounding and answer validation</strong></p><p><em>In here we check</em></p><blockquote>Did the answer actually come from the retrieved evidence?</blockquote><p><strong>For example:</strong></p><p><strong>Retrieved:</strong></p><p>Refunds are available within 30 days.</p><p><strong>LLM:</strong></p><p>“Customers can request refunds within 60 days.”</p><p>So that is a hallucination</p><p><strong>You can have a validation layer:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/222/1*QmGGNmjuYLtFI2zIr-Q-iA.png" /></figure><p><strong>If it&#39;s a pass then its fine else,</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/286/1*wfBPYJHY8gyF9ls5vm2u7g.png" /></figure><p><strong>7. Setup for Production Level</strong></p><p><strong>7.1 Citation Generation</strong></p><p><strong>For enterprise systems, you often want:</strong></p><blockquote>Refunds are available within 30 days.</blockquote><blockquote>[Source: Customer Refund Policy, Section 4]</blockquote><p><strong>The system should ideally know:</strong></p><p><em>rather than simply putting random citations at the end.</em></p><p><strong>7.2. Evaluation</strong></p><p>This is where your earlier point becomes <strong>very important</strong>.</p><p><strong>Don’t just test:</strong></p><p>“Does the final answer look good?”</p><p>Break evaluation apart.</p><p><strong>Retrieval</strong></p><p>Did we retrieve the correct document?</p><p>Metrics:</p><ul><li><strong>Recall@K — </strong>Of all the relevant documents, how many were successfully retrieved in the top K?</li><li><strong>Precision@K — </strong>Of the top K retrieved documents, how many are actually relevant?</li><li><strong>MRR (Mean Reciprocal Rank) — </strong>How high is the first relevant result ranked, averaged across queries?</li><li><strong>NDCG@K — </strong>How well are all relevant results ranked, giving more importance to highly relevant results appearing near the top?</li><li><strong>Hit Rate@K — </strong>The percentage of queries where at least one relevant document appears in the top K.</li></ul><p><strong>Generation</strong></p><p>Did the LLM correctly use the evidence?</p><p>Evaluate:</p><ul><li>faithfulness</li><li>groundedness</li><li>answer relevance</li><li>citation correctness</li></ul><p><strong>7.3. Evaluation Dataset</strong></p><p>Production teams shouldn’t manually test random questions forever.</p><p><strong>Build a dataset:</strong></p><pre>Question<br>Expected answer<br>Expected document<br>Expected chunk<br>Metadata</pre><p><strong>Example:</strong></p><p><strong>Question:</strong></p><blockquote>“What is the annual leave entitlement?”</blockquote><p><strong>Expected source:</strong></p><blockquote>HR Policy v3.2</blockquote><p><strong>Expected answer:</strong></p><blockquote>14 days</blockquote><p><strong>Then every time you change:</strong></p><ul><li>embedding model</li><li>chunking</li><li>retriever</li><li>reranker</li><li>prompt</li><li>LLM</li></ul><p><strong>you can run regression tests.</strong></p><p>This is <strong>RAG evaluation as CI/CD,</strong> which is a very powerful way to think about it.</p><p><strong>7.4. Observability/Tracing</strong></p><p><strong><em>Every request should ideally produce a trace:</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/88/1*F0NcWYNv_irks_Jd2xL3sg.png" /></figure><p>Track:</p><ul><li>latency</li><li>token usage</li><li>retrieval scores</li><li>reranking scores</li><li>model used</li><li>prompt version</li><li>errors</li><li>cost</li><li>answer quality</li></ul><p><strong><em>Then when something breaks, you can find which stage broke.</em></strong></p><p><strong>7.5. Caching</strong></p><p>Production RAG can become <strong>expensive.</strong></p><p><strong>Therefore, caching is crucial:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/109/1*Z1rTWbuDx75OF3zd7bruYA.png" /></figure><p>depending on whether the underlying knowledge has changed.</p><p><strong>This reduces:</strong></p><ul><li>latency</li><li>GPU/API cost</li><li>database load</li></ul><p><strong>7.6. Cost and Latency management</strong></p><p>You might have:</p><pre>Query rewrite → LLM Retrieval<br>Reranker → expensive model<br>Answer → LLM<br>Validator → another LLM</pre><p>That’s potentially several model calls.</p><p>So production architecture asks:</p><blockquote>Do we really need every stage for every query?</blockquote><p>For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/231/1*Ncm_9lkPmRHwoY4hSD-3lg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/176/1*tsgoHRzQKfHd08hU6xcBwQ.png" /></figure><blockquote>This is A<strong>daptive RAG</strong>.</blockquote><p><strong>7.7. Failure handling</strong></p><p><strong>A production system must know what happens when:</strong></p><ul><li>No documents found</li><li>Retriever timeout</li><li>Vector DB unavailable</li><li>LLM timeout</li><li>Low retrieval confidence</li><li>Conflicting documents</li><li>Stale information</li><li>User lacks permission etc…</li></ul><p><strong>For example:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*KCFXNrgEsN1pa-DooddEKQ.png" /></figure><blockquote><strong>That’s much better than forcing an answer.</strong></blockquote><p><strong>7.8. Knowledge Freshness</strong></p><p>Your RAG knowledge changes.</p><p><strong>Imagine:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/132/1*rPTkesnLMRylldueVRJ1Sw.png" /></figure><p>Your system needs to know which is authoritative.</p><p><strong>You may need:</strong></p><ul><li>document versioning</li><li>timestamps</li><li>source priority</li><li>update detection</li><li>incremental re-indexing</li><li>deletion handling</li><li>stale-document detection</li></ul><p><strong>7.9. Multi Source Retrieval</strong></p><p><strong>Production RAG isn’t necessarily:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/215/1*H7ETx59sBfp1KFioTOStJw.png" /></figure><p><strong>It can be:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*EqK3R0VuXlHaAnSIuNSZKg.png" /></figure><p><strong>For example:</strong></p><blockquote><strong>“What was our Q2 revenue and what did the sales team say about it?”</strong></blockquote><p><strong>You might need:</strong></p><pre>SQL → revenue<br>Vector DB → sales meeting documents</pre><p><strong>Then the LLM synthesizes them.</strong></p><p>That’s closer to <strong>agentic / tool-augmented RAG.</strong></p><p>Finally,,,,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HgyFPMCnguu6jLkpThh44A.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c270296d877" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Connect a Cloudflare Domain with AWS Amplify: A Complete Guide]]></title>
            <link>https://medium.com/@iAmrAmosh/how-to-connect-a-cloudflare-domain-with-aws-amplify-a-complete-guide-57439a16b4d2?source=rss-64b465829d14------2</link>
            <guid isPermaLink="false">https://medium.com/p/57439a16b4d2</guid>
            <dc:creator><![CDATA[Yasiru Ramosh]]></dc:creator>
            <pubDate>Mon, 09 Jun 2025 14:55:41 GMT</pubDate>
            <atom:updated>2025-06-09T14:55:41.785Z</atom:updated>
            <content:encoded><![CDATA[<p>Connecting a Cloudflare-managed domain to an AWS Amplify-hosted application might seem straightforward — until you hit the infamous <strong>ANAME/CNAME roadblock</strong>. This article walks you through the entire process step-by-step and covers the <strong>trickiest part</strong>: how to handle ANAME records with Cloudflare.</p><h3>🛠 Prerequisites</h3><p>Before you begin, make sure you have:</p><ul><li>A domain registered with <strong>Cloudflare</strong></li><li>An <strong>AWS account</strong></li><li>A <strong>deployed application</strong> on AWS Amplify</li></ul><h3>🔗 Step-by-Step: Connecting Your Domain</h3><h3>1. Go to AWS Amplify Console</h3><ul><li>Navigate to your deployed Amplify application.</li><li>In the left panel, go to Hosting -&gt; <strong>“Custom Domain”</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*f89bcpM-yQ3efNMgqNDp3g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fb_PhfobZJeRL1TArI8yWw.png" /></figure><ul><li>Click <strong>“Add domain”</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C6j3c9S8ryb94cYEQoGMWQ.png" /></figure><h3>2. Add Your Custom Domain</h3><ul><li>Enter the domain name you’ve registered with Cloudflare (e.g., example.com).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ppbIOsw0_S6L6V5pSLYHpQ.png" /></figure><ul><li>Enable <strong>Redirection</strong> if needed (e.g., redirecting www to root).</li><li>Choose <strong>Amplify-managed certificate</strong> for automatic SSL.</li><li>Click <strong>“Add domain”</strong>.</li></ul><blockquote><em>Wait for AWS Amplify to generate the SSL certificate. This can take a few minutes.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1lYlXz67ZZd2mSai-qhbXw.png" /></figure><h3>📋 Step 3: Update DNS Settings in Cloudflare</h3><h3>3.1 Get DNS Records from Amplify</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XiZmSnkI9goZIntV-FcHEQ.png" /></figure><ul><li>After domain setup is initiated, click the <strong>“Actions”</strong> button next to your domain in Amplify.</li><li>Click <strong>“View DNS Records”</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*3iMC6_o3AcPd1oD202BiaQ.png" /></figure><blockquote><em>You’ll see several records, including CNAMEs for verification and subdomain, and an </em><strong><em>ANAME</em></strong><em> (or alias) record.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_v8D-d3hCNB207HVOcrWug.png" /></figure><h3>3.2 Add CNAME Records in Cloudflare</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BHQVxwHPuOHTZ-zZl2rPJA.png" /></figure><p>In the <strong>Cloudflare Dashboard</strong>, go to: <em>DNS → Records → “Add record”</em></p><p>Add the following CNAMEs:</p><ul><li><strong>Type:</strong> CNAME<br> <strong>Name:</strong> _amplify-&lt;hash&gt; (or as shown in Amplify)<br> <strong>Content:</strong> Value from Amplify<br> <strong>Proxy Status:</strong> DNS only (gray cloud)</li><li><strong>Type:</strong> CNAME<br> <strong>Name:</strong> www<br> <strong>Content:</strong> Value from Amplify<br> <strong>Proxy Status:</strong> DNS only (gray cloud)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7MRxkXCrx4mroqKcSmIQhw.png" /></figure><h3>⚠️ The Tricky Part: ANAME Isn’t Supported on Cloudflare</h3><p>Cloudflare does <strong>not</strong> support ANAME records directly. Amplify typically gives a record like:</p><pre>ANAME: d2c7bbtgur58ox2.cloudfront.net</pre><p>To work around this:</p><h3>4. Use nslookup to Resolve the ANAME</h3><p>Open a terminal and run:</p><pre>nslookup d2c7bbltgur58x2.cloudfront.net</pre><p>You’ll get a list of <strong>IPv4 addresses</strong>, like:</p><pre>13.33.47.1<br>13.33.47.123<br>13.33.47.52<br>13.33.47.120</pre><blockquote><em>These are the IP addresses behind the CloudFront distribution used by Amplify.</em></blockquote><h3>✅ Final Step: Add A Records in Cloudflare</h3><p>For each of the IPv4 addresses you got, add them as A records in Cloudflare:</p><pre>Type: A<br>Name: @<br>Content: 13.33.47.1<br>Proxy status: DNS only</pre><p>Repeat for each IP:</p><ul><li>13.33.47.1</li><li>13.33.47.123</li><li>13.33.47.52</li><li>13.33.47.120</li></ul><blockquote><em>Make sure </em><strong><em>Proxy status is set to DNS only (gray cloud)</em></strong><em>.</em></blockquote><h3>🧪 Test Your Configuration</h3><p>To verify everything is working:</p><pre>nslookup yourdomain.com</pre><p>Example output:</p><pre>Name: yourdomain.com<br>Addresses: <br>  13.33.47.1<br>  13.33.47.123<br>  13.33.47.52<br>  13.33.47.120</pre><p>If these match the A records you set, you’re good to go! SSL certificates should automatically validate soon after.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VKr10FuBniKTu8TR9PSL6w.png" /></figure><h3>🎉 You’re Done!</h3><p>Once DNS propagation completes and SSL certificates are issued, your domain will be <strong>fully active with AWS Amplify</strong>, even with Cloudflare DNS in the mix.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57439a16b4d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying AI Models Using Ollama on AWS EC2]]></title>
            <link>https://medium.com/@iAmrAmosh/deploying-ai-models-using-ollama-on-aws-ec2-3359a769af7a?source=rss-64b465829d14------2</link>
            <guid isPermaLink="false">https://medium.com/p/3359a769af7a</guid>
            <dc:creator><![CDATA[Yasiru Ramosh]]></dc:creator>
            <pubDate>Tue, 20 May 2025 21:34:53 GMT</pubDate>
            <atom:updated>2025-05-22T07:54:45.070Z</atom:updated>
            <content:encoded><![CDATA[<p>Running open-source LLMs directly on cloud infrastructure like AWS EC2 is becoming easier than ever. In this tutorial, we’ll walk through how to deploy and run a model using <a href="https://ollama.com/">Ollama</a> on an EC2 instance, using the <strong>Gemma3:1b</strong> model as an example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PBJdnBY50akubiKm" /></figure><p>This guide assumes a basic familiarity with AWS and command-line operations.</p><h3>🔧 Step 1: Launch an EC2 Instance</h3><ol><li>Log in to your <strong>AWS Management Console</strong>.</li><li>Navigate to <strong>EC2 &gt; Instances</strong>.</li><li>Click <strong>“Launch Instance”</strong> and configure as follows:</li></ol><ul><li><strong>AMI</strong>: Choose <strong>Ubuntu Server 22.04 LTS</strong> or <strong>Amazon Linux 2023</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ThkH2tgST1ZAvP7NkYaZrg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5GbrW3D-q5WcdEwHTJBPHA.png" /></figure><ul><li><strong>Instance Type</strong>: Use at least a t3.large (4 vCPU, 8 GB RAM)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qmBSeAgk65WVzBv1yQw7hw.png" /></figure><ul><li><strong>Use a key pair </strong>which is need in future access ,make sure to save this in known location to open command prompt easily.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xqRRbPjebYmztup4ulD3Ag.png" /></figure><ul><li>Allow all ssh and others for this moment,after you can change them up as you wish.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vlBZvAMOoxEH0GAMsoAUDw.png" /></figure><ul><li><strong>Storage</strong>: Allocate <strong>at least 20 GB (SSD preferred)</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8bP5snKmAzV67hOWBCtIGQ.png" /></figure><ul><li><strong>Security Group</strong>:</li><li>Allow <strong>SSH (port 22)</strong> from your IP</li><li>Allow <strong>TCP port 11434</strong> for the Ollama API</li><li>Optionally allow <strong>HTTP (80)</strong> and <strong>HTTPS (443)</strong> if needed</li></ul><p>Create or use an existing <strong>Key Pair</strong> for SSH access.</p><p>Launch the instance 🚀</p><h3>🔗 Step 2: Connect to Your EC2 Instance</h3><p>Use SSH to connect to your EC2 instance:</p><pre>ssh -i /path/to/your-key.pem ec2-user@&lt;your-instance-public-ip&gt;   # For Amazon Linux  <br># OR  <br>ssh -i /path/to/your-key.pem ubuntu@&lt;your-instance-public-ip&gt;     # For Ubuntu</pre><h3>📦 Step 3: Install Ollama</h3><h3>For Ubuntu:</h3><pre>sudo apt update &amp;&amp; sudo apt upgrade -y</pre><h3>For Amazon Linux:</h3><pre>sudo yum update -y</pre><p>Then install Ollama:</p><pre>curl -fsSL https://ollama.com/install.sh | sh</pre><h3>🤖 Step 4: Run the Gemma-3:1B Model</h3><p>Start the Ollama service (usually automatic after install, but you can ensure it’s running):</p><pre>ollama serve &amp;</pre><p>Pull the <strong>Gemma-3:1B</strong> model:</p><pre>ollama pull gemma3:1b</pre><h3>🧪 Step 5: Test the Model</h3><p>You can now test the model with a simple prompt:</p><pre>ollama run gemma3:1b &quot;Explain quantum computing in simple terms&quot;</pre><h3>👟 Step 5: Run the Model Locally</h3><p>lets have a look the model works in locally,in instance</p><pre>curl -X POST http://localhost: 11434/api/generate —d&#39;{<br>&quot;model&quot; :&quot;gemma3:1b&quot;<br>&quot;prompt&quot;: &quot;Explain how large language models work&quot;<br><br>}&#39;<br><br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*85IO6nIAdwpzyabN6BkFZA.png" /></figure><h3>🌐 Step 6 (Optional): Enable API Access</h3><p>If you’d like to access the Ollama API remotely:</p><ol><li>Configure the Ollama service:</li></ol><pre>sudo mkdir -p /etc/systemd/system/ollama.service.d/<br>echo &quot;[Service]&quot; | sudo tee /etc/systemd/system/ollama.service.d/override.conf<br>echo &quot;Environment=\&quot;OLLAMA_HOST=0.0.0.0:11434\&quot;&quot; | sudo tee -a /etc/systemd/system/ollama.service.d/override.conf</pre><ol><li>Restart Ollama:</li></ol><pre>sudo systemctl daemon-reload<br>sudo systemctl restart ollama</pre><h3>🔁 Step 7 (Optional): Enable Auto-Start on Boot</h3><pre>sudo systemctl enable ollama</pre><h3>📡 Step 8: Check API Availability</h3><p>Use curl to confirm if the Ollama API is running:</p><pre>curl http://&lt;your-public-ip&gt;:11434/api/version</pre><h3>🧠 Step 9: Run a Generation Request via API</h3><p>Now, you can make requests from any external client:</p><pre>curl -X POST http://&lt;your-public-ip&gt;:11434/api/generate -d &#39;{<br>  &quot;model&quot;: &quot;gemma:1b&quot;,<br>  &quot;prompt&quot;: &quot;Explain what EC2 is in one sentence.&quot;,<br>  &quot;stream&quot;: false<br>}&#39;</pre><h3>🎉 Wrapping Up</h3><p>With just a few simple steps, you now have a powerful LLM like <strong>Gemma 1B</strong> running on your own EC2 instance via <strong>Ollama</strong>. This setup is great for experimentation, prototyping, or even deploying internal AI tools without relying on third-party APIs.</p><p>Want to go further? Try:</p><ul><li>Switching to larger models</li><li>Automating deployments with Terraform</li><li>Exposing Ollama behind an API Gateway or NGINX proxy</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3359a769af7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>