<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Dev J. Shah 🥑</title>
    <description>The latest articles on Forem by Dev J. Shah 🥑 (@busycaesar).</description>
    <link>https://forem.com/busycaesar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1017716%2F0fdaf54f-6428-41fc-86b1-412236c6a8fe.png</url>
      <title>Forem: Dev J. Shah 🥑</title>
      <link>https://forem.com/busycaesar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/busycaesar"/>
    <language>en</language>
    <item>
      <title>Cracking the Databricks Generative AI Engineer Certification</title>
      <dc:creator>Dev J. Shah 🥑</dc:creator>
      <pubDate>Mon, 23 Mar 2026 13:00:00 +0000</pubDate>
      <link>https://forem.com/busycaesar/cracking-the-databricks-generative-ai-engineer-certification-10ga</link>
      <guid>https://forem.com/busycaesar/cracking-the-databricks-generative-ai-engineer-certification-10ga</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;To set expectations, this guide walks you through the introduction of the exam: what it is, the topics covered, and if you are interested, some resources to help you prepare for it.&lt;/p&gt;

&lt;p&gt;The Databricks &lt;strong&gt;Generative AI Engineer Associate&lt;/strong&gt; is a certification offered by Databricks that helps candidates demonstrate their ability to design and build AI-powered solutions using their platform. Here is the link to the Databricks page to learn more about it:&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://www.databricks.com/learn/certification/genai-engineer-associate" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.databricks.com%2Fsites%2Fdefault%2Ffiles%2F2022%2F04%2Fdatabricks-certification-and-badging-og.png" height="auto" class="m-0"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://www.databricks.com/learn/certification/genai-engineer-associate" rel="noopener noreferrer" class="c-link"&gt;
            Databricks Certified Generative AI Engineer Associate | Databricks
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            Become a Databricks Certified Generative AI Engineer Associate! Prove your skills in designing and implementing LLM-enabled solutions using Databricks' cutting-edge tools.
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.databricks.com%2Fen-website-assets%2Ffavicon-32x32.png%3Fv%3Dc9b9916c3b27dc51866c46b79a6e9b88"&gt;
          databricks.com
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Here is my certificate for the creditibility and check my score.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://credentials.databricks.com/4828045b-21ec-4f68-92bd-d9a3f02cc612" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcredentials.databricks.com%2Fassets%2Fimages%2Faccredible_logo.png" height="auto" class="m-0"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://credentials.databricks.com/4828045b-21ec-4f68-92bd-d9a3f02cc612" rel="noopener noreferrer" class="c-link"&gt;
            Accredible • Certificates, Badges and Blockchain
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            Home of digital credentials
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcredentials.databricks.com%2F"&gt;
          credentials.databricks.com
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;





&lt;h2&gt;
  
  
  Topics Covered
&lt;/h2&gt;

&lt;p&gt;This exam covers 6 sections, each focusing on different aspects of building and managing generative AI solutions on Databricks. Below is a brief overview of each section along with its percentage weightage.&lt;/p&gt;

&lt;h3&gt;
  
  
  Design Applications – 14%
&lt;/h3&gt;

&lt;p&gt;As the name suggests, this section focuses on designing various aspects of AI solutions: crafting the right prompt, choosing appropriate models and components, translating business requirements into desired inputs and outputs, and deciding which tools to give the model access to.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data Preparation – 14%
&lt;/h3&gt;

&lt;p&gt;The first step in creating an AI solution is often preparing the data in a way that helps leverage the model to its full potential. This section includes deciding on chunking strategies, filtering unnecessary data, and choosing the appropriate Python package for extracting data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Application Development – 30%
&lt;/h3&gt;

&lt;p&gt;This is the most interesting part. It includes creating tools to extract required data, selecting an orchestration framework like LangChain to create chains of prompt templates and models, crafting prompts by augmenting them with retrieved data, implementing guardrails, reducing hallucinations, and selecting the right models and embedding strategies for your use case.&lt;/p&gt;

&lt;h3&gt;
  
  
  Assembling and Deploying Apps – 22%
&lt;/h3&gt;

&lt;p&gt;Once your application is built, you need to get it out into the world. This section covers deploying model serving endpoints, registering models to Unity Catalog via MLflow, setting up Vector Search indexes, and understanding the end-to-end deployment process for a RAG (Retrieval-Augmented Generation) application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Governance – 8%
&lt;/h3&gt;

&lt;p&gt;This covers how to protect your application and your data. Think guardrails against malicious inputs, data masking, and staying on the right side of legal and licensing requirements.&lt;/p&gt;

&lt;h3&gt;
  
  
  Evaluation and Monitoring – 12%
&lt;/h3&gt;

&lt;p&gt;Building it is one thing; making sure it keeps working well is another. This section tests your ability to evaluate model performance, monitor live deployments, control costs, and understand the difference between the evaluation and monitoring phases of the AI application lifecycle.&lt;/p&gt;




&lt;h2&gt;
  
  
  Exam Overview
&lt;/h2&gt;

&lt;p&gt;The exam consists of 45 scored multiple-choice and multiple-selection questions, though you may encounter a few additional unscored questions. Extra time is factored in to account for these. You will have 90 minutes to complete the exam.&lt;/p&gt;




&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;There are no formal prerequisites required to sit for this exam, which makes it accessible to anyone looking to get started with generative AI on Databricks. That said, Databricks recommends coming in with some solid preparation.&lt;/p&gt;

&lt;p&gt;Beyond the coursework, you will want to have a good working knowledge of current LLMs and their capabilities, prompt engineering, and tools like LangChain and Hugging Face Transformers. On the technical side, comfort with Python and its relevant libraries is important, as is familiarity with APIs used for data preparation and model chaining.&lt;/p&gt;




&lt;h2&gt;
  
  
  Study Plan, Resources, and Practice Exams
&lt;/h2&gt;

&lt;p&gt;I used Databricks Academy's &lt;strong&gt;Generative AI Engineering Pathway&lt;/strong&gt; to prepare for the certification. It consists of 6 courses with a total duration of 10 hours and 35 minutes. I personally took almost a week (including a long weekend) to complete this course. Upon completing each course, you also earn a Databricks badge that you can share. Each course also includes a tutorial walkthrough of the explained topic. Since I have worked on these AI topics before, I did not follow the tutorials hands-on, but depending on your experience level, you may want to. Upon completing the pathway, you will receive a coupon code via email after a few days that you can use to book the exam for free.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
      &lt;div class="c-embed__body flex items-center justify-between"&gt;
        &lt;a href="https://partner-academy.databricks.com/learn/learning-plans/315/generative-ai-engineering-pathway" rel="noopener noreferrer" class="c-link fw-bold flex items-center"&gt;
          &lt;span class="mr-2"&gt;partner-academy.databricks.com&lt;/span&gt;
          

        &lt;/a&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;After completing the pathway, it was time to take some practice exams. Since this is a fairly new certification, there are limited resources available online. After some research, I decided to buy practice questions from &lt;strong&gt;SkillCertPro&lt;/strong&gt;. This package contains around 670 questions across 12 mock exams. There were questions in the actual exam that overlapped with these practice tests, so I highly recommend getting this one. &lt;em&gt;(Not sponsored!)&lt;/em&gt;&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://skillcertpro.com/product/databricks-generative-ai-engineer-associate-practice-questions/" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fskillcertpro.com%2Fwp-content%2Fuploads%2F2025%2F04%2FDatabricks-Generative-AI-Engineer-Associate-Exam-Questions-2025.jpg" height="auto" class="m-0"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://skillcertpro.com/product/databricks-generative-ai-engineer-associate-practice-questions/" rel="noopener noreferrer" class="c-link"&gt;
            Databricks Generative AI Engineer Associate Practice Questions 2026
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            Databricks Generative AI Engineer Associate Exam Questions 2026. Prepare and pass in first attempt. with valid dumps. 100% real exam questions
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fskillcertpro.com%2Fwp-content%2Fuploads%2F2020%2F06%2Fwp-1592240161910-64x64.png"&gt;
          skillcertpro.com
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;After completing 1–2 practice exams, I booked my (as always, in-person) exam for the following week. During that week, I worked through one practice exam per day, reviewed the explanations for wrong answers, and used Claude to dig deeper into concepts I wasn't sure about.&lt;/p&gt;

&lt;p&gt;I also came across a couple of blogs that really helped with preparation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://medium.com/@chandadipendu/databricks-generative-ai-engineer-associate-certification-study-guide-part-1-70cf3c483085" rel="noopener noreferrer"&gt;https://medium.com/@chandadipendu/databricks-generative-ai-engineer-associate-certification-study-guide-part-1-70cf3c483085&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/pulse/preparation-guide-databricks-generative-ai-engineer-associate-mane-0toxf" rel="noopener noreferrer"&gt;https://www.linkedin.com/pulse/preparation-guide-databricks-generative-ai-engineer-associate-mane-0toxf&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Beyond these, depending on your weak domains, Databricks also publishes topic-specific blogs that can help deepen your understanding.&lt;/p&gt;




&lt;h2&gt;
  
  
  My Score
&lt;/h2&gt;

&lt;p&gt;Design Applications: 80%&lt;br&gt;
Data Preparation: 57%&lt;br&gt;
Application Development: 71%&lt;br&gt;
Assembling and Deploying Apps: 100%&lt;br&gt;
Governance: 100%&lt;br&gt;
Evaluation and Monitoring: 80%&lt;/p&gt;




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

&lt;p&gt;To wrap up, most of the exam questions were not just Databricks-specific, but covered real-world Generative AI engineering concepts. So while preparing, make sure you also understand the core concepts of GenAI beyond the Databricks platform. This will help you build transferable skills that go beyond the exam itself.&lt;/p&gt;

&lt;p&gt;Best of luck! Let me know if you have any further questions, and don't forget to let me know once you pass.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>machinelearning</category>
      <category>databricks</category>
      <category>rag</category>
    </item>
    <item>
      <title>Hands-on: Azure AI Search &amp; AI Foundry for RAG</title>
      <dc:creator>Dev J. Shah 🥑</dc:creator>
      <pubDate>Sun, 08 Mar 2026 12:37:13 +0000</pubDate>
      <link>https://forem.com/busycaesar/hands-on-azure-ai-search-ai-foundry-for-rag-3i9g</link>
      <guid>https://forem.com/busycaesar/hands-on-azure-ai-search-ai-foundry-for-rag-3i9g</guid>
      <description>&lt;h2&gt;
  
  
  Index
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;
Azure Resources

&lt;ul&gt;
&lt;li&gt;Azure AI Search&lt;/li&gt;
&lt;li&gt;Azure AI Foundry&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Code&lt;/li&gt;
&lt;li&gt;Do not forget to Clean the Cloud
&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this lab, we will build a full RAG pipeline using Azure. RAG is a technique where, instead of relying solely on a language model's training data, we first retrieve relevant documents from an external knowledge base and then pass them to the model to generate a more accurate and grounded answer.&lt;/p&gt;

&lt;p&gt;To do this, we will use two Azure services: Azure AI Search as the vector database to store and retrieve document embeddings, and Azure AI Foundry to deploy the embedding model and the generation model.&lt;br&gt;
By the end of this lab, you will have a working RAG pipeline running on Azure.&lt;/p&gt;
&lt;h2&gt;
  
  
  Azure Resources
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Azure AI Search
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Azure AI Search&lt;/strong&gt; is a cloud search service that supports full-text search, filters, and vector search. In this lab, we are using it as a vector database. We store document embeddings in it and query them using cosine similarity to find the most relevant documents for a given input.&lt;/p&gt;

&lt;p&gt;To set it up, we need to provision the resource and get two values: &lt;code&gt;VECTOR_SEARCH_ENDPOINT&lt;/code&gt; and &lt;code&gt;VECTOR_SEARCH_KEY&lt;/code&gt;, which will be used as environment variables.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to the &lt;a href="https://portal.azure.com" rel="noopener noreferrer"&gt;Azure Portal&lt;/a&gt; and open &lt;code&gt;AI Search&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2Fe5e9123f-1e41-4280-a43a-ca9818297f69" class="article-body-image-wrapper"&gt;&lt;img width="1168" alt="Screenshot From 2026-03-07 11-48-30" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2Fe5e9123f-1e41-4280-a43a-ca9818297f69" height="902"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click &lt;code&gt;Create&lt;/code&gt; to create a new search service.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F2eb36210-035b-4d0d-98c1-379250b44011" class="article-body-image-wrapper"&gt;&lt;img width="1446" alt="Screenshot From 2026-03-07 11-49-39" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F2eb36210-035b-4d0d-98c1-379250b44011" height="538"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new or use an existing resource group. (Suggest: create a new one so its easy to delete the resources later on.)&lt;/li&gt;
&lt;li&gt;Give a unique name for &lt;code&gt;Service name&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Make sure the &lt;code&gt;Pricing tier&lt;/code&gt; is free, unless you want to experience paid service.&lt;/li&gt;
&lt;li&gt;Finally, click &lt;code&gt;Review + Create&lt;/code&gt; button at the bottom and then click &lt;code&gt;Create&lt;/code&gt; button to create the resource.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F98c24fd8-3266-409e-81f7-129c3bcad103" class="article-body-image-wrapper"&gt;&lt;img width="1352" alt="Screenshot From 2026-03-07 11-53-43" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F98c24fd8-3266-409e-81f7-129c3bcad103" height="932"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Next, do to the resource dashboard and copy the &lt;code&gt;Url&lt;/code&gt; from the &lt;code&gt;Essentials&lt;/code&gt;. This &lt;code&gt;Url&lt;/code&gt; will be used as &lt;code&gt;VECTOR_SEARCH_ENDPOINT&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F181f5efc-c51f-4169-8cac-ec9c6d66decf" class="article-body-image-wrapper"&gt;&lt;img width="1656" alt="Screenshot From 2026-03-07 11-57-59" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F181f5efc-c51f-4169-8cac-ec9c6d66decf" height="932"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To get the &lt;code&gt;VECTOR_SEARCH_KEY&lt;/code&gt; go to the &lt;code&gt;Keys&lt;/code&gt; tab under &lt;code&gt;Settings&lt;/code&gt; section from the left navbar. From this screen, copy the &lt;code&gt;Primary admin key&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F3aed742c-cac6-44cd-8287-c122cc47307b" class="article-body-image-wrapper"&gt;&lt;img width="1656" alt="Screenshot From 2026-03-07 11-59-14" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F3aed742c-cac6-44cd-8287-c122cc47307b" height="932"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Azure AI Foundry
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Azure AI Foundry&lt;/strong&gt; is a platform for deploying and managing AI models on Azure. It lets you deploy base models (like OpenAI models) as endpoints that you can call from your own code. In this lab, we are using it to deploy two models: &lt;code&gt;text-embedding-3-small&lt;/code&gt; to generate embeddings, and a generation model to produce the final answer.&lt;/p&gt;

&lt;p&gt;To set it up, we need to provision the resource and get two values: &lt;code&gt;AZURE_OPEN_API_KEY&lt;/code&gt; and &lt;code&gt;AZURE_OPEN_API_ENDPOINT&lt;/code&gt;, which will be used as environment variables.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to the &lt;a href="http://ai.azure.com/" rel="noopener noreferrer"&gt;Azure AI Foundry&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Click &lt;code&gt;Create new&lt;/code&gt; button to create a new project.&lt;/li&gt;
&lt;li&gt;For the resource type, keep the recommended option and click &lt;code&gt;Next&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F5d7e25ed-17f4-4edc-95ea-d70be24616de" class="article-body-image-wrapper"&gt;&lt;img width="1356" alt="Screenshot From 2026-03-07 12-21-42" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F5d7e25ed-17f4-4edc-95ea-d70be24616de" height="932"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Give it a good name, keep everything else default and click &lt;code&gt;Create&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F58b32bb3-8018-4c6c-87d8-c8670b43a927" class="article-body-image-wrapper"&gt;&lt;img width="1356" alt="Screenshot From 2026-03-07 12-33-28" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F58b32bb3-8018-4c6c-87d8-c8670b43a927" height="932"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Finally, from the project overview page, copy &lt;code&gt;API Key&lt;/code&gt; to use as &lt;code&gt;AZURE_OPEN_API_KEY&lt;/code&gt; and &lt;code&gt;Microsoft Foundry project endpoint&lt;/code&gt; to use as &lt;code&gt;AZURE_OPEN_API_ENDPOINT&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F3940633d-b151-486f-94c8-6c7166306917" class="article-body-image-wrapper"&gt;&lt;img width="1330" alt="Screenshot From 2026-03-07 12-37-15" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F3940633d-b151-486f-94c8-6c7166306917" height="932"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Now from the left navbar, click &lt;code&gt;Models + endpoints&lt;/code&gt; under &lt;code&gt;My assets&lt;/code&gt; section.&lt;/li&gt;
&lt;li&gt;Click &lt;code&gt;Deploy base model&lt;/code&gt;. Now we will deploy an embedding model and a generation model.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F09317a2b-d7f0-47d7-83a9-67c8634a8fda" class="article-body-image-wrapper"&gt;&lt;img width="1566" alt="Screenshot From 2026-03-07 12-41-27" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F09317a2b-d7f0-47d7-83a9-67c8634a8fda" height="932"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Search for &lt;code&gt;text-embedding-3-small&lt;/code&gt; and click &lt;code&gt;Confirm&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F0f378759-24a6-4c89-9533-8d88bad6fe68" class="article-body-image-wrapper"&gt;&lt;img width="1207" alt="Screenshot From 2026-03-07 12-43-59" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F0f378759-24a6-4c89-9533-8d88bad6fe68" height="932"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Change the &lt;code&gt;Deployment type&lt;/code&gt; to &lt;code&gt;Standard&lt;/code&gt; and click &lt;code&gt;Deploy&lt;/code&gt; to deploy the model.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2Faf6bba7b-7095-40cb-8d02-58ec6653d393" class="article-body-image-wrapper"&gt;&lt;img width="1207" alt="Screenshot From 2026-03-07 12-45-04" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2Faf6bba7b-7095-40cb-8d02-58ec6653d393" height="932"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Open &lt;a href="https://github.com/busycaesar/Embeddings_And_Cosine_Similarity/blob/Master/AgentCon%20-%20Toronto/main.ipynb" rel="noopener noreferrer"&gt;this notebook&lt;/a&gt; in Google Colab.&lt;/li&gt;
&lt;li&gt;Add the following environment variables by clicking on this key button, and grant them notebook access

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;AZURE_OPEN_API_ENDPOINT&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;AZURE_OPEN_API_KEY&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;VECTOR_SEARCH_ENDPOINT&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;VECTOR_SEARCH_KEY&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F7a0aa861-37bc-406e-accd-73ca673d6938" class="article-body-image-wrapper"&gt;&lt;img width="465" alt="Screenshot From 2026-03-07 13-01-29" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F7a0aa861-37bc-406e-accd-73ca673d6938" height="929"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Finally, you can run the commands in the notebook.&lt;/li&gt;
&lt;/ol&gt;


&lt;h2&gt;
  
  
  Clean the Cloud
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;On &lt;a href="https://portal.azure.com" rel="noopener noreferrer"&gt;Azure Portal&lt;/a&gt; go to &lt;code&gt;All Resources&lt;/code&gt; and delete all the resources we created for this lab.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F914b5ee6-6083-422d-86d4-b9878a90496e" class="article-body-image-wrapper"&gt;&lt;img width="684" alt="Screenshot From 2026-03-07 13-05-17" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fuser-attachments%2Fassets%2F914b5ee6-6083-422d-86d4-b9878a90496e" height="929"&gt;&lt;/a&gt;&lt;/p&gt;


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

&lt;p&gt;In this lab, we set up a full RAG pipeline on Azure using Azure AI Search as the vector database and Azure AI Foundry to deploy the embedding and generation models. Thanks for reading! If you want to understand the math behind how the retrieval step works, check out my other blog on the Math behind Embeddings and Cosine Similarity.&lt;/p&gt;


&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/busycaesar/embeddings-cosine-similarity-4541" class="crayons-story__hidden-navigation-link"&gt;Exploring RAG: Math behind Embeddings &amp;amp; Cosine Similarity&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/busycaesar" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1017716%2F0fdaf54f-6428-41fc-86b1-412236c6a8fe.png" alt="busycaesar profile" class="crayons-avatar__image" width="800" height="436"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/busycaesar" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Dev J. Shah 🥑
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Dev J. Shah 🥑
                
              
              &lt;div id="story-author-preview-content-2724552" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/busycaesar" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1017716%2F0fdaf54f-6428-41fc-86b1-412236c6a8fe.png" class="crayons-avatar__image" alt="" width="800" height="436"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Dev J. Shah 🥑&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/busycaesar/embeddings-cosine-similarity-4541" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jul 29 '25&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/busycaesar/embeddings-cosine-similarity-4541" id="article-link-2724552"&gt;
          Exploring RAG: Math behind Embeddings &amp;amp; Cosine Similarity
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/vectordatabase"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;vectordatabase&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/rag"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;rag&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/ai"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;ai&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/busycaesar/embeddings-cosine-similarity-4541" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;2&lt;span class="hidden s:inline"&gt; reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/busycaesar/embeddings-cosine-similarity-4541#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              Comments


              &lt;span class="hidden s:inline"&gt;Add Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            10 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


&lt;p&gt;If you want to learn more about AI Engineering and related terminologies, I highly recommended getting the book &lt;a href="https://amzn.to/4kcD2n8" rel="noopener noreferrer"&gt;“AI Engineering” by Chip Huyen&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>azure</category>
      <category>rag</category>
      <category>ai</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>5 AI Agent Design Patterns Every Developer Needs to Know</title>
      <dc:creator>Dev J. Shah 🥑</dc:creator>
      <pubDate>Sun, 01 Mar 2026 21:01:28 +0000</pubDate>
      <link>https://forem.com/busycaesar/5-ai-agent-design-patterns-every-developer-needs-to-know-1n5l</link>
      <guid>https://forem.com/busycaesar/5-ai-agent-design-patterns-every-developer-needs-to-know-1n5l</guid>
      <description>&lt;h2&gt;
  
  
  What is an AI Agent?
&lt;/h2&gt;

&lt;p&gt;To explain this concept, I will use a very simple analogy. Humans have two core powers which they use to build things. These powers are Brain (to think, decide and plan) and Body Parts (to verify, execute, and get feedback). Similarly, an AI agent is a digital version of a human which has an LLM (as Brain) and Tools (as Body Parts) to build things.&lt;/p&gt;

&lt;p&gt;In other words, an AI agent is a software program which does not work on predefined steps. It gets the request, uses the LLM to understand it and plan the steps to be taken to fulfill it. Further, it uses tools, which is a fancy word for a function, to complete those steps as and when needed. Hence, essentially, the agent is as good as the reasoning capability of the LLM and the tools it has access to.&lt;/p&gt;




&lt;h2&gt;
  
  
  Single Agent
&lt;/h2&gt;

&lt;p&gt;As the name suggests, this is an application where only a single AI agent is used to get the work done.&lt;/p&gt;




&lt;h2&gt;
  
  
  Multi-Agent
&lt;/h2&gt;

&lt;p&gt;When an application uses multiple AI agents, it is considered a multi-agent design pattern. Moreover, within the multi-agent design pattern, there are further sub-types.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sequential
&lt;/h3&gt;

&lt;p&gt;For a kind of workflow where the agents have to work in coordination with each other, in the sense that the input of one agent depends on the output of the other, a sequential pattern can be used.&lt;/p&gt;

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

&lt;p&gt;For instance, in a resume screening system:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Agent 1: Extract text from resume (PDF → structured data)&lt;/li&gt;
&lt;li&gt;Agent 2: Identify skills &amp;amp; experience&lt;/li&gt;
&lt;li&gt;Agent 3: Match against job description&lt;/li&gt;
&lt;li&gt;Agent 4: Score candidate&lt;/li&gt;
&lt;li&gt;Agent 5: Generate recruiter summary&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All the tasks to be performed by AI cannot be done simultaneously. Hence, agents need to be arranged in series with each other.&lt;/p&gt;

&lt;h3&gt;
  
  
  Parallel
&lt;/h3&gt;

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

&lt;p&gt;On the other hand, when the workflows can run independently, that is, when the agents can start working simultaneously, the pattern is called the Parallel AI Agent Pattern.&lt;br&gt;
For example, in a research agent tool:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Agent 1: Searches web articles&lt;/li&gt;
&lt;li&gt;Agent 2: Searches academic papers&lt;/li&gt;
&lt;li&gt;Agent 3: Searches internal company docs&lt;/li&gt;
&lt;li&gt;Agent 4: Searches forums (e.g., dev discussions)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Loop
&lt;/h3&gt;

&lt;p&gt;In a loop pattern of AI agents, a loop agent iteratively runs a sequence of AI agents until a specific condition is met. For instance, in a content evaluation agent:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Agent 1: Generates the content&lt;/li&gt;
&lt;li&gt;Agent 2: Evaluates the grammar&lt;/li&gt;
&lt;li&gt;Agent 3: Checks if the content is coherent&lt;/li&gt;
&lt;li&gt;Agent 4: Checks if the content addresses all the requirements&lt;/li&gt;
&lt;/ul&gt;

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

&lt;h3&gt;
  
  
  Other Patterns
&lt;/h3&gt;

&lt;p&gt;Other than these major patterns, there are, and can be, several more patterns to design an efficient AI system. For instance:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Review and Critique Pattern&lt;/strong&gt;: It has one agent which generates the content and another which criticizes it. Until either the generated response is satisfactory or the maximum number of iterations has been reached, it keeps looping.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Iterative Refinement Pattern&lt;/strong&gt;: In this pattern, there can be three agents: one which generates the response, another which evaluates the quality, and if it is not up to the mark, a third agent which enhances the prompt, by adding more instructions, and sends it back to the first agent.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Coordinator Pattern&lt;/strong&gt;: As the name suggests, it has one coordinator or master agent which plans the steps to be taken to resolve the query and assigns each step to a specialized agent based on the task to be completed.&lt;br&gt;
and more.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




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

&lt;p&gt;The introduction of AI Agents started a whole new discipline in the industry of software engineering. In the near future, more software developers will work on creating agents and specialized tools, building multi-agent systems, and more. Not to forget, the invention of the &lt;a href="https://dev.to/busycaesar/mcp-model-context-protocol-4o1l"&gt;Model Context Protocol (MCP)&lt;/a&gt; has made this easier than before.&lt;/p&gt;

&lt;p&gt;If you want to get into the world of AI engineering, I highly recommend getting the book, &lt;a href="https://amzn.to/4kcD2n8" rel="noopener noreferrer"&gt;“AI Engineering” by Chip Huyen&lt;/a&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Citation
&lt;/h2&gt;

&lt;p&gt;This blog is inspired from Google documentation in Cloud Architecture Center: &lt;a href="https://docs.cloud.google.com/architecture/choose-design-pattern-agentic-ai-system" rel="noopener noreferrer"&gt;"Choose a design pattern for your agentic AI system"&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>agents</category>
      <category>rag</category>
      <category>design</category>
    </item>
    <item>
      <title>Chunking for context: 6 Strategies Every AI Engineer Should Know</title>
      <dc:creator>Dev J. Shah 🥑</dc:creator>
      <pubDate>Sun, 22 Feb 2026 22:22:05 +0000</pubDate>
      <link>https://forem.com/busycaesar/chunking-for-context-6-strategies-every-ai-engineer-should-know-40aa</link>
      <guid>https://forem.com/busycaesar/chunking-for-context-6-strategies-every-ai-engineer-should-know-40aa</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;The very purpose of chunking is to split the data into chunks, convert each chunk into embeddings, and store it in a vector database to be able to use it to provide context to the LLM.&lt;/p&gt;

&lt;p&gt;This data can be split using multiple strategies. The ultimate goal is to make sure that whenever the relevant chunk/s are being fetched, it provides enough context to the LLM to make sure that the query of the user is properly addressed. The following are some of the strategies that can be used to split the data.&lt;/p&gt;




&lt;h2&gt;
  
  
  Fixed Size
&lt;/h2&gt;

&lt;p&gt;The most famous method of chunking is fixed-size. The data can be split into a fixed size, that is, the text can be split into a fixed number of characters. For instance, if the data contains 5000 characters and the chunk size is 250 characters, then the data gets divided into 20 chunks.&lt;/p&gt;

&lt;p&gt;For this strategy, one important parameter used is overlapping. Developers often choose to overlap the characters to make sure that the context is maintained in each chunk. In simple words, if the overlap is of 20 characters, this means that the last 20 characters of a chunk will become the first 20 characters of the next chunk. This helps persist the context.&lt;/p&gt;




&lt;h2&gt;
  
  
  Recursive
&lt;/h2&gt;

&lt;p&gt;Recursive chunking splits text by using the largest meaningful structure first, and only falls back to smaller ones if the chunk is still too large. This needs to be explained with the help of an example.&lt;/p&gt;

&lt;p&gt;Assuming the following data is to be split.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Recursive chunking splits text step by step while preserving meaning.

In retrieval-augmented generation systems, documents often exceed the context window of large language models. If text is split blindly into fixed sizes, important ideas may be broken across chunks, and retrieval quality suffers.

Recursive chunking solves this by attempting to keep larger semantic units intact first, such as paragraphs. Only when a paragraph exceeds the size limit does the system split it further into sentences or smaller units.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Considering the required size of each chunk is 20 tokens (~ 20 words).&lt;/p&gt;

&lt;p&gt;Following is the order in which recursive chunking divides the text.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Whole document&lt;/li&gt;
&lt;li&gt;Paragraph &lt;code&gt;\n\n&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Sentence &lt;code&gt;.&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Token&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Following this order, the splitter first checks if the whole document can fit into a single chunk. However, it exceeds the limit of 20 tokens. Hence, it would divide the content into separate paragraphs.&lt;/p&gt;

&lt;p&gt;P1: 10 tokens&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Recursive chunking splits text step by step while preserving meaning.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;P2: 33 tokens&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;In retrieval-augmented generation systems, documents often exceed the context window of large language models. If text is split blindly into fixed sizes, important ideas may be broken across chunks, and retrieval quality suffers.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;P3: 35 tokens&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Recursive chunking solves this by attempting to keep larger semantic units intact first, such as paragraphs. Only when a paragraph exceeds the size limit does the system split it further into sentences or smaller units.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Since P1 fits within the limit of 20 tokens, P1 becomes the first chunk. P2 and P3 exceed the limit and will be further divided into sentences.&lt;/p&gt;

&lt;p&gt;P2, S1: 17 tokens&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;In retrieval-augmented generation systems, documents often exceed the context window of large language models.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;P2, S2: 19 tokens&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;If text is split blindly into fixed sizes, important ideas may be broken across chunks, and retrieval quality suffers.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;P3, S1: 17 tokens&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Recursive chunking solves this by attempting to keep larger semantic units intact first, such as paragraphs.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;P3, S2: 18 tokens&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Only when a paragraph exceeds the size limit does the system split it further into sentences or smaller units.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;All of these fit within separate chunks. Hence, the final list of chunks will be P1, P2;S1, P2;S2, P3;S1, P3;S2.&lt;/p&gt;


&lt;h2&gt;
  
  
  Document-Based
&lt;/h2&gt;

&lt;p&gt;Document-based chunking splits text along natural document boundaries like sections, subsections, and paragraphs, which is similar to recursive chunking. However, the key difference is that when a section exceeds the token limit, document-based chunking identifies semantically meaningful split points (like topic shifts) rather than mechanically splitting at arbitrary separators. This ensures each chunk contains coherent, self-contained information.&lt;/p&gt;

&lt;p&gt;For instance, the following data,&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Analysis Framework&lt;/span&gt;
We employed a mixed-methods approach combining quantitative regression analysis with qualitative thematic coding. The quantitative component used multiple linear regression to identify predictors of user satisfaction, controlling for demographic variables including age, gender, and geographic location. Model selection involved comparing AIC values across nested models. The qualitative component involved coding open-ended responses using an inductive approach to identify emergent themes. Two independent coders achieved an inter-rater reliability of κ=0.85.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;will split as follows&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Analysis Framework - Quantitative&lt;/span&gt;
We employed a mixed-methods approach combining quantitative regression analysis with qualitative thematic coding. The quantitative component used multiple linear regression to identify predictors of user satisfaction, controlling for demographic variables including age, gender, and geographic location. Model selection involved comparing AIC values across nested models.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Analysis Framework - Qualitative&lt;/span&gt;
The qualitative component involved coding open-ended responses using an inductive approach to identify emergent themes. Two independent coders achieved an inter-rater reliability of κ=0.85.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Hierarchical
&lt;/h2&gt;

&lt;p&gt;In this type of chunking strategy, the data is first divided into small semantic units, that is, either sentences or small paragraphs, to form separate chunks. This can be considered a level 3 division (the most granular level). Further, level 3 chunks are grouped together based on similarity, which forms level 2 chunks, and lastly, based on the main topic, level 2 chunks are grouped to become level 1 chunks. This bottom-up aggregation is what makes hierarchical chunking unique.&lt;/p&gt;

&lt;p&gt;In this strategy, the action happens during the retrieval. The user query is used to find the most relevant level 3 chunk. Upon a successful match, the level 2 or level 1 chunk is retrieved.&lt;/p&gt;


&lt;h2&gt;
  
  
  Semantic
&lt;/h2&gt;

&lt;p&gt;In Semantic Chunking, content is divided based on the actual meaning and topic of the text.&lt;/p&gt;

&lt;p&gt;Imagine the algorithm reading through your document sentence by sentence. It starts building a "chunk" and asks itself: "Is this next sentence still talking about the same thing?" As long as the next sentence is semantically related to the previous one, it is added to the current chunk.&lt;/p&gt;

&lt;p&gt;As soon as the topic shifts or if the chunk reaches a maximum token limit, the current chunk is closed, and a new one begins. This ensures that a single idea stays together, making it much easier for an AI to retrieve the right context later.&lt;/p&gt;

&lt;p&gt;The model identifies topic shifts by calculating the mathematical distance between sentences using embeddings and cosine similarity. Check out the following blog to know more about it.&lt;/p&gt;


&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/busycaesar/embeddings-cosine-similarity-4541" class="crayons-story__hidden-navigation-link"&gt;Exploring RAG: Math behind Embeddings &amp;amp; Cosine Similarity&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/busycaesar" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1017716%2F0fdaf54f-6428-41fc-86b1-412236c6a8fe.png" alt="busycaesar profile" class="crayons-avatar__image" width="800" height="436"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/busycaesar" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Dev J. Shah 🥑
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Dev J. Shah 🥑
                
              
              &lt;div id="story-author-preview-content-2724552" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/busycaesar" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1017716%2F0fdaf54f-6428-41fc-86b1-412236c6a8fe.png" class="crayons-avatar__image" alt="" width="800" height="436"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Dev J. Shah 🥑&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/busycaesar/embeddings-cosine-similarity-4541" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jul 29 '25&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/busycaesar/embeddings-cosine-similarity-4541" id="article-link-2724552"&gt;
          Exploring RAG: Math behind Embeddings &amp;amp; Cosine Similarity
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/vectordatabase"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;vectordatabase&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/rag"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;rag&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/ai"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;ai&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/busycaesar/embeddings-cosine-similarity-4541" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;2&lt;span class="hidden s:inline"&gt; reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/busycaesar/embeddings-cosine-similarity-4541#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              Comments


              &lt;span class="hidden s:inline"&gt;Add Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            10 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;/div&gt;
&lt;br&gt;





&lt;h2&gt;
  
  
  LLM Based
&lt;/h2&gt;

&lt;p&gt;In LLM-based chunking, the model acts as an intelligent editor, choosing precisely where to place dividers.&lt;/p&gt;

&lt;p&gt;Key Considerations for Breaking Content:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Semantic Drift:&lt;/strong&gt; It detects subtle transitions in subject matter, asking: "Are we still talking about the same core concept?"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Conceptual Integrity:&lt;/strong&gt; It ensures an idea is fully explained before cutting.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logical Grouping:&lt;/strong&gt; It groups related ideas even if they use different wording or span across multiple paragraphs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Structural Intelligence:&lt;/strong&gt; It respects the flow of headings and sections but prioritizes the actual narrative flow over rigid formatting.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Relational Awareness:&lt;/strong&gt; The LLM excels at identifying functional pairs, such as:

&lt;ul&gt;
&lt;li&gt;Cause ↔ Effect&lt;/li&gt;
&lt;li&gt;Definition ↔ Example&lt;/li&gt;
&lt;li&gt;Problem ↔ Solution&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  Key Considerations for Chunking
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Context Window Limits:&lt;/strong&gt; Every embedding model has a maximum token limit (e.g., 512, 8192 tokens). If a text chunk exceeds this limit, the model will simply truncate the text, ignoring any content beyond the limit. This results in incomplete vector representations and lost data. Therefore, your maximum chunk size must always be safely below the embedding model's context window limit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Granularity vs. Context:&lt;/strong&gt; A larger context window allows for bigger chunks, capturing more context but potentially diluting specific details. Smaller windows force smaller chunks, which are more precise but may lack surrounding context. The choice of chunk size is a direct trade-off that must align with the capabilities of the specific embedding model you intend to use downstream.&lt;/p&gt;




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

&lt;p&gt;Choosing the right chunking strategy depends on the nature of your data, the embedding model you use, and the kind of queries your system needs to handle. Each strategy covered above comes with its own trade-offs between simplicity, semantic accuracy, and computational cost.&lt;/p&gt;

&lt;p&gt;If you want to learn more about AI Engineering and related terminologies, I highly recommended getting the book &lt;a href="https://amzn.to/4kcD2n8" rel="noopener noreferrer"&gt;“AI Engineering” by Chip Huyen&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>rag</category>
    </item>
    <item>
      <title>Model Adaptation: Prompt-Based Techniques vs Fine-Tuning</title>
      <dc:creator>Dev J. Shah 🥑</dc:creator>
      <pubDate>Sat, 31 Jan 2026 17:43:24 +0000</pubDate>
      <link>https://forem.com/busycaesar/model-adaptation-prompt-based-techniques-vs-fine-tuning-3131</link>
      <guid>https://forem.com/busycaesar/model-adaptation-prompt-based-techniques-vs-fine-tuning-3131</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Firstly, it is important to understand why we need to adapt a model and what adapting a model actually means.&lt;/p&gt;

&lt;p&gt;Here, a model refers to a foundation model, which is trained on a very large amount of general-purpose data. These models are capable of handling a wide variety of tasks, but they are not optimized for any specific use case by default.&lt;/p&gt;

&lt;p&gt;Adapting a model means customizing a foundation model for a specific use case so that we can leverage its capabilities more effectively and fulfill a defined purpose.&lt;/p&gt;

&lt;p&gt;Let us assume a use case where we need to build a customer support chatbot backed by an LLM. For this, we would start by selecting a foundation model and then customizing it so that it can directly interact with customers, resolve their issues, or take appropriate actions.&lt;/p&gt;

&lt;p&gt;To achieve this, there are two main approaches. These approaches are not alternatives, but instead serve different use cases, depending on the requirements.&lt;/p&gt;




&lt;h2&gt;
  
  
  Prompt-Based Techniques
&lt;/h2&gt;

&lt;p&gt;The first technique used to adapt a model is prompt-based adaptation. In this approach, there is a middle layer between the user’s query and the LLM.&lt;/p&gt;

&lt;p&gt;When a user submits a question, this middle layer adds:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Additional context&lt;/li&gt;
&lt;li&gt;Instructions&lt;/li&gt;
&lt;li&gt;Constraints or rules&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;along with the original user query. This combined prompt is then sent to the LLM. Based on these instructions and context, the model generates a response that is more aligned with the expected behavior.&lt;/p&gt;

&lt;p&gt;There are multiple prompt-based techniques, including but not limited to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Zero-shot Prompting&lt;/li&gt;
&lt;li&gt;Few-shot Prompting&lt;/li&gt;
&lt;li&gt;Role Prompting&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/busycaesar/series/29180"&gt;Retrieval-Augmented Generation (RAG)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Tool or Function Calling&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Limitations of Prompt-Based Techniques
&lt;/h3&gt;

&lt;p&gt;One major limitation of prompt-based techniques is inconsistency. This approach does not reliably enforce behavior, which means the output can vary even when similar instructions are provided. As a result, the response is not always guaranteed to follow the expected structure or tone.&lt;/p&gt;

&lt;p&gt;Another limitation is the reduction of the available context window. Since instructions and additional context need to be sent with every request, they consume a good part of the model’s context window.&lt;/p&gt;




&lt;h2&gt;
  
  
  Fine-Tuning
&lt;/h2&gt;

&lt;p&gt;Another strategy to adapt a model is fine-tuning. This approach requires more technical knowledge and high-quality data compared to prompt-based methods.&lt;/p&gt;

&lt;p&gt;In fine-tuning, the weights of the foundation model are updated so that the model learns to behave in a specific way by default. Instead of guiding the model through instructions at runtime, we change how the model responds internally.&lt;/p&gt;

&lt;p&gt;Prompt-based techniques can be compared to giving instructions to a smart generalist, whereas fine-tuning is like sending that generalist back to school to become a specialist. Instead of reminding them what to do every time, their training changes how they think and respond by default.&lt;/p&gt;

&lt;p&gt;Some common fine-tuning methods include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Supervised Fine-Tuning (SFT)&lt;/li&gt;
&lt;li&gt;Reinforcement Learning from Human Feedback (RLHF)&lt;/li&gt;
&lt;li&gt;Instruction Fine-Tuning&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With fine-tuning, the model becomes highly reliable. It consistently follows a fixed tone, response structure, and style. Additionally, it can learn company-specific jargon, terminology, and phrasing, making it more suitable for long-term and stable use cases.&lt;/p&gt;




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

&lt;p&gt;In general, prompt-based techniques make more sense when the instructions given to the model change frequently. For example, product FAQs or dynamic content that evolves over time can be efficiently handled using prompt-based methods.&lt;/p&gt;

&lt;p&gt;On the other hand, fine-tuning is more suitable for behaviors that remain consistent over long periods. This includes company policies, tone of communication, customer interaction rules, and compliance requirements.&lt;/p&gt;

&lt;p&gt;In practice, a hybrid approach often works best. Parameters that are expected to remain stable for a long time can be used to fine-tune the foundation model. At the same time, variables that evolve more frequently can be provided dynamically through prompts at inference time.&lt;/p&gt;

&lt;p&gt;This further reinforces the idea that prompt-based adaptation and fine-tuning are not alternatives, but complementary techniques, each with specific and well-defined use cases.&lt;/p&gt;




&lt;h2&gt;
  
  
  Citation
&lt;/h2&gt;

&lt;p&gt;This blog is inspired by the book &lt;a href="https://amzn.to/4kcD2n8" rel="noopener noreferrer"&gt;“AI Engineering” by Chip Huyen&lt;/a&gt;. If you want to go beyond high-level concepts and understand how real-world AI systems are designed, adapted, evaluated, and deployed, this book is an excellent resource. It covers model adaptation, system design, data considerations, production AI workflows, etc., making it valuable for developers building practical AI applications.&lt;/p&gt;

</description>
      <category>llm</category>
      <category>promptengineering</category>
      <category>ai</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Why Am I a SWE?</title>
      <dc:creator>Dev J. Shah 🥑</dc:creator>
      <pubDate>Thu, 16 Oct 2025 13:44:48 +0000</pubDate>
      <link>https://forem.com/busycaesar/why-am-i-a-swe-1246</link>
      <guid>https://forem.com/busycaesar/why-am-i-a-swe-1246</guid>
      <description>&lt;p&gt;I am not a Software Engineer just because I studied Computer Science; I am one because of the journey that led me here, which includes a mix of wrong turns, realizations, courage, and a quiet but persistent voice that never stopped telling me where I truly belonged.&lt;/p&gt;

&lt;p&gt;When I look back, I sometimes wonder how different my life would have been if I hadn’t switched my profession. Considering the captivating pace of today’s tech innovations, I can’t even imagine how bad I would feel if I had stayed where I was.&lt;/p&gt;

&lt;p&gt;I wasn’t always a Software Engineer. In fact, I studied Electrical Engineering. To be honest, I didn’t have a passion for it. I chose it mostly out of fear. Back then, people would tell me that computers were constantly evolving and that if I studied computer science, I would have to keep learning something new almost every single day. As a sixteen-year-old, that sounded intimidating. So, I ended up choosing Electrical Engineering instead. But as my studies went on, something kept tugging at me.&lt;/p&gt;

&lt;p&gt;During my diploma, we had a couple of computer-related courses as part of the electrical curriculum. Around the last year, I found out that one of my friends had started his Bachelor’s in CS. That news haunted me; not in a bad way, but in a way that made me question my own path. The thought that I wasn’t doing computer programming kept bothering me. Deep down, something was constantly telling me that I should be in computers.&lt;/p&gt;

&lt;p&gt;Eventually, I gathered the courage to tell my dad that I wanted to switch to computer programming. Fortunately, he supported my decision, and that conversation changed the entire trajectory of my career.&lt;/p&gt;

&lt;p&gt;Looking back even further, the signs were always there. I think my real connection with computers began in 7th or 8th grade, when I was first introduced to HTML. Later, in 10th grade, I was reintroduced to HTML and also learned C programming in school. I was really good at it. During computer lectures at my tuition classes in 10th grade, I would always be the first one to complete the assigned tasks and then immediately crave something more challenging. I still remember that during our final examinations, the topper of the batch copied from my C program. That moment still makes me smile.&lt;/p&gt;

&lt;p&gt;I also remember building a &lt;a href="https://github.com/busycaesar/Photo_Book" rel="noopener noreferrer"&gt;Facebook-like website&lt;/a&gt; using raw HTML and inline CSS back in 2017, a time when learning programming through online tutorials wasn’t as common as it is today. Most of my learning came from pure curiosity and trial and error.&lt;/p&gt;

&lt;p&gt;In hindsight, studying Electrical Engineering wasn’t a waste at all. It taught me logic, discipline, and a way of thinking that still helps me today, not just professionally, but in life. Yet, it was programming that gave me purpose, creativity, and the thrill of building something from nothing.&lt;/p&gt;

&lt;p&gt;So, why am I a software engineer?&lt;/p&gt;

&lt;p&gt;Because, at every step, even when I didn’t realize it, my heart was already wired for it.&lt;/p&gt;

</description>
      <category>career</category>
      <category>devjournal</category>
      <category>motivation</category>
    </item>
    <item>
      <title>How Retrieval Algorithms Shape Better LLM Responses?</title>
      <dc:creator>Dev J. Shah 🥑</dc:creator>
      <pubDate>Tue, 26 Aug 2025 00:34:43 +0000</pubDate>
      <link>https://forem.com/busycaesar/how-retrieval-algorithms-shape-better-llm-responses-5beo</link>
      <guid>https://forem.com/busycaesar/how-retrieval-algorithms-shape-better-llm-responses-5beo</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In the era of LLMs, specifically in &lt;strong&gt;Retrieval-Augmented Generation (RAG)&lt;/strong&gt;, retrieval algorithms play one of the most important roles. The better the retrieval results, the better the context provided to the LLM, and the better the responses it generates.&lt;/p&gt;

&lt;p&gt;The method of retrieving information is also the backbone of search engines. However, this blog only talks about retrieval specifically for providing context to LLMs.&lt;/p&gt;

&lt;p&gt;The way it works is by ranking documents based on their relevance to the given query. Retrieval algorithms can be classified based on how the &lt;strong&gt;relevance score&lt;/strong&gt; is computed. A relevance score is a numerical measure that indicates how well a piece of information matches a given query.&lt;/p&gt;

&lt;p&gt;The two common retrieval methods are: &lt;strong&gt;Term-based Retrieval&lt;/strong&gt; and &lt;strong&gt;Embedding-based Retrieval&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Term-based Retrieval
&lt;/h2&gt;

&lt;p&gt;As the name suggests, Term-based Retrieval uses the &lt;strong&gt;keywords&lt;/strong&gt; from the query to find the most relevant documents. However, this approach can have issues.&lt;/p&gt;

&lt;p&gt;Many documents may contain the same keyword. Not every document can fit in the LLM’s &lt;strong&gt;context window&lt;/strong&gt;. As a result, the document with the actual useful context might not get included. A simple approach is to include the document that contains the keyword the highest number of times. The number of times a term appears in the document is called &lt;strong&gt;Term Frequency (TF)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A query may contain multiple keywords, out of which some are more important than others. The importance of each keyword is inversely proportional to the number of documents in which it appears. The more documents a keyword appears in, the less important it becomes. This metric is called &lt;strong&gt;Inverse Document Frequency (IDF)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Mathematically, IDF = (Total number of documents) ÷ (Number of documents containing the keyword). A higher IDF value indicates greater importance of the keyword.&lt;/p&gt;

&lt;p&gt;The well-known algorithm that combines these two metrics, &lt;strong&gt;Term Frequency (TF)&lt;/strong&gt; and &lt;strong&gt;Inverse Document Frequency (IDF),&lt;/strong&gt; is &lt;strong&gt;TF-IDF&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Embedding-based Retrieval
&lt;/h2&gt;

&lt;p&gt;Term-based Retrieval is focused on keywords rather than meaning, which can result in irrelevant documents being retrieved. On the other hand, &lt;strong&gt;Embedding-based Retrieval&lt;/strong&gt; ranks documents based on how closely they align with the query in terms of &lt;strong&gt;semantic meaning&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;With Embedding-based Retrieval, indexing involves an additional step: converting documents into &lt;strong&gt;embeddings&lt;/strong&gt;. Embeddings are &lt;strong&gt;high-dimensional vectors&lt;/strong&gt; that preserve important properties of the original data. These embeddings are then stored in a specialized database called a &lt;strong&gt;Vector Database&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To learn more about embeddings, I recommend checking out my &lt;a href="https://dev.to/busycaesar/embeddings-cosine-similarity-4541"&gt;other blog&lt;/a&gt;, which explains how text is converted into embeddings and how retrieval is performed using &lt;strong&gt;cosine similarity&lt;/strong&gt;, one of the most common embedding-based retrieval techniques.&lt;/p&gt;




&lt;h2&gt;
  
  
  Comparing Term-based and Embedding-based Retrieval
&lt;/h2&gt;

&lt;p&gt;Term-based Retrieval is generally faster than Embedding-based Retrieval during both storing (indexing) and fetching (querying). However, Embedding-based Retrieval can significantly improve retrieval quality over time.&lt;/p&gt;

&lt;p&gt;Two metrics often used in RAG to evaluate the quality of a retriever are:&lt;/p&gt;

&lt;p&gt;

&lt;/p&gt;
&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;ContextPrecision=Relevant retrieved documentsAll retrieved documents
Context Precision = \frac{Relevant\ retrieved\ documents}{All\ retrieved\ documents}
&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;C&lt;/span&gt;&lt;span class="mord mathnormal"&gt;o&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mord mathnormal"&gt;t&lt;/span&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mord mathnormal"&gt;tP&lt;/span&gt;&lt;span class="mord mathnormal"&gt;rec&lt;/span&gt;&lt;span class="mord mathnormal"&gt;i&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;i&lt;/span&gt;&lt;span class="mord mathnormal"&gt;o&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mopen nulldelimiter"&gt;&lt;/span&gt;&lt;span class="mfrac"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;A&lt;/span&gt;&lt;span class="mord mathnormal"&gt;ll&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mord mathnormal"&gt;re&lt;/span&gt;&lt;span class="mord mathnormal"&gt;t&lt;/span&gt;&lt;span class="mord mathnormal"&gt;r&lt;/span&gt;&lt;span class="mord mathnormal"&gt;i&lt;/span&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="mord mathnormal"&gt;v&lt;/span&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="mord mathnormal"&gt;d&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mord mathnormal"&gt;d&lt;/span&gt;&lt;span class="mord mathnormal"&gt;oc&lt;/span&gt;&lt;span class="mord mathnormal"&gt;u&lt;/span&gt;&lt;span class="mord mathnormal"&gt;m&lt;/span&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mord mathnormal"&gt;t&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="frac-line"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;R&lt;/span&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="mord mathnormal"&gt;l&lt;/span&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="mord mathnormal"&gt;v&lt;/span&gt;&lt;span class="mord mathnormal"&gt;an&lt;/span&gt;&lt;span class="mord mathnormal"&gt;t&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mord mathnormal"&gt;re&lt;/span&gt;&lt;span class="mord mathnormal"&gt;t&lt;/span&gt;&lt;span class="mord mathnormal"&gt;r&lt;/span&gt;&lt;span class="mord mathnormal"&gt;i&lt;/span&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="mord mathnormal"&gt;v&lt;/span&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="mord mathnormal"&gt;d&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mord mathnormal"&gt;d&lt;/span&gt;&lt;span class="mord mathnormal"&gt;oc&lt;/span&gt;&lt;span class="mord mathnormal"&gt;u&lt;/span&gt;&lt;span class="mord mathnormal"&gt;m&lt;/span&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mord mathnormal"&gt;t&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose nulldelimiter"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;br&gt;

&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;ContextRecall=Relevant retrieved documentsAll relevant documents
Context Recall = \frac{Relevant\ retrieved\ documents}{All\ relevant\ documents}
&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;C&lt;/span&gt;&lt;span class="mord mathnormal"&gt;o&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mord mathnormal"&gt;t&lt;/span&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mord mathnormal"&gt;tR&lt;/span&gt;&lt;span class="mord mathnormal"&gt;ec&lt;/span&gt;&lt;span class="mord mathnormal"&gt;a&lt;/span&gt;&lt;span class="mord mathnormal"&gt;ll&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mopen nulldelimiter"&gt;&lt;/span&gt;&lt;span class="mfrac"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;A&lt;/span&gt;&lt;span class="mord mathnormal"&gt;ll&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mord mathnormal"&gt;re&lt;/span&gt;&lt;span class="mord mathnormal"&gt;l&lt;/span&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="mord mathnormal"&gt;v&lt;/span&gt;&lt;span class="mord mathnormal"&gt;an&lt;/span&gt;&lt;span class="mord mathnormal"&gt;t&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mord mathnormal"&gt;d&lt;/span&gt;&lt;span class="mord mathnormal"&gt;oc&lt;/span&gt;&lt;span class="mord mathnormal"&gt;u&lt;/span&gt;&lt;span class="mord mathnormal"&gt;m&lt;/span&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mord mathnormal"&gt;t&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="frac-line"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;R&lt;/span&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="mord mathnormal"&gt;l&lt;/span&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="mord mathnormal"&gt;v&lt;/span&gt;&lt;span class="mord mathnormal"&gt;an&lt;/span&gt;&lt;span class="mord mathnormal"&gt;t&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mord mathnormal"&gt;re&lt;/span&gt;&lt;span class="mord mathnormal"&gt;t&lt;/span&gt;&lt;span class="mord mathnormal"&gt;r&lt;/span&gt;&lt;span class="mord mathnormal"&gt;i&lt;/span&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="mord mathnormal"&gt;v&lt;/span&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="mord mathnormal"&gt;d&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mord mathnormal"&gt;d&lt;/span&gt;&lt;span class="mord mathnormal"&gt;oc&lt;/span&gt;&lt;span class="mord mathnormal"&gt;u&lt;/span&gt;&lt;span class="mord mathnormal"&gt;m&lt;/span&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mord mathnormal"&gt;t&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose nulldelimiter"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;Another consideration is cost. Generating embeddings requires compute resources and often involves API costs. In addition, depending on the vector database, both &lt;strong&gt;vector storage&lt;/strong&gt; and &lt;strong&gt;vector search queries&lt;/strong&gt; can also be expensive.&lt;/p&gt;




&lt;h2&gt;
  
  
  Combining Retrieval Methods
&lt;/h2&gt;

&lt;p&gt;Combining both retrieval algorithms is called &lt;strong&gt;Hybrid Search&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;There are two common approaches:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Sequential Combination&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;First, use Term-based Retrieval to fetch all documents containing the keyword.&lt;/li&gt;
&lt;li&gt;Then, use Embedding-based Retrieval to re-rank those documents based on semantic meaning.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parallel Combination&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Both retrieval methods run in parallel.&lt;/li&gt;
&lt;li&gt;Each produces a ranking of documents by relevance.&lt;/li&gt;
&lt;li&gt;The results are then merged or compared to generate a final ranking.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hybrid Search allows leveraging the strengths of both approaches: the speed of keyword search and the semantic depth of embeddings.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Citation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This blog is inspired by the &lt;em&gt;“Retrieval Algorithms”&lt;/em&gt; topic in the book &lt;a href="https://amzn.to/4kcD2n8" rel="noopener noreferrer"&gt;&lt;em&gt;“AI Engineer”&lt;/em&gt; by &lt;strong&gt;Chip Huyen&lt;/strong&gt;&lt;/a&gt;. This is a brief introduction to the topic. To learn more in detail, I recommend referring to the book.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>rag</category>
    </item>
    <item>
      <title>AI-900 Guide: From Prep to Pass</title>
      <dc:creator>Dev J. Shah 🥑</dc:creator>
      <pubDate>Mon, 04 Aug 2025 21:07:00 +0000</pubDate>
      <link>https://forem.com/busycaesar/ai-900-guide-from-prep-to-pass-23kg</link>
      <guid>https://forem.com/busycaesar/ai-900-guide-from-prep-to-pass-23kg</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Whatsup everyone? This blog is about Microsoft’s certificate “Azure AI Fundamentals”, which is also referred to as AI 900, which is the certificate code. This is a fundamental certificate that helps the candidate demonstrate understanding and knowledge related to Machine Learning and AI, and all the Microsoft Azure’s services and tools about the topic. The following is the link to Microsoft Learn’s page to know the most updated information about it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/credentials/certifications/azure-ai-fundamentals" rel="noopener noreferrer"&gt;Microsoft Certified: Azure AI Fundamentals - Certifications&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Topics that it covers
&lt;/h2&gt;

&lt;p&gt;The certificate covers the following topics:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Artificial Intelligence workloads and considerations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Includes a brief introduction to Computer Vision workloads, Natural Language Processing Workloads, Document Processing Workloads, and GenAI Workloads. Further, it discusses about principles of responsible AI.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fundamental principles of Machine Learning on Azure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This section talks about various types of Machine Learning, such as Regression, Classification, Clustering, Deep Learning, and Transformer Architecture. Later on, it also teaches how to use Azure tools and services to create ML models.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Computer Vision workloads on Azure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Computer Vision modules introduce various Computer Vision solutions like Image Classification, Object Detection, Optical Character Recognition, and Facial Detection and Analysis. Again, moving forward, it demonstrates how to leverage Azure to implement these services.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Natural Language Processing (NLP) workloads on Azure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this section, various features of Natural Language Processing are introduced, such as Key Phrase Extraction, Entity Recognition, Sentiment Analysis, Language Modeling, Speech Recognition and Synthesis, and Translation. Additionally, walks through the documentation that helps the user set up all these services using Azure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Generative AI workloads on Azure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As the name suggests, this section introduces Generative AI workloads on Azure, including its features, scenarios, and considerations, and all the tools provided by Azure in this vertical.&lt;/p&gt;




&lt;h2&gt;
  
  
  How did I prepare for it?
&lt;/h2&gt;

&lt;p&gt;To prepare for the exam, I followed all the modules described in Microsoft Learn.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/training/paths/introduction-to-ai-on-azure" rel="noopener noreferrer"&gt;Introduction to AI in Azure - Training&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I went through all the units in each module, read, and tried understanding all the topics while making sure to get some hands-on experience, as included in the above-mentioned learning path, which gave me more exposure to all the services and tools discussed in the units. Meanwhile, I also wrote &lt;a href="https://ai900.shahtech.info/" rel="noopener noreferrer"&gt;notes&lt;/a&gt; that try to explain all the topics in simpler terms.&lt;/p&gt;

&lt;p&gt;Alternatively, you can buy any Udemy course or follow a FreeCodeCamp video, as per your capacity. Nonetheless, I feel the material provided by Microsoft Learn is good enough.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: There are a couple of places in my notes where I added a detailed explanation of the topic, which might be out of scope for the certification. I researched the content for my understanding and later decided to keep it in my notes so it's easy for me to understand it while I revise, and might also help others.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I would also recommend that you go through all the units in the modules while also making your own notes to help you revise them.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Recommendation:&lt;/strong&gt; As a suggestion, try understanding all the topics fundamentally, even if it's not required to pass the exam. The reason behind doing this is that once you understand it from the foundation, it will be stored in your memory, and you will not have to revise it again and again.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  How did I revise?
&lt;/h2&gt;

&lt;p&gt;Once you are done with all the units in all the modules, I would suggest that you go ahead and book the test. After booking, you will have a fixed amount of time to revise everything. Following is how I used to revise for the exam, after booking the test.&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1946916929626591351-9" src="https://platform.twitter.com/embed/Tweet.html?id=1946916929626591351"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1946916929626591351-9');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1946916929626591351&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;Microsoft Learn provides the practice tests that you can take to simulate the exam environment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/credentials/certifications/azure-ai-fundamentals/?practice-assessment-type=certification#certification-practice-for-the-exam" rel="noopener noreferrer"&gt;Microsoft Certified: Azure AI Fundamentals - Certifications&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The best thing about these practice tests is that at the end of each test, along with the score, it gives you the list of modules in which you performed poorly and need to revise. This feature helped me evaluate the modules where I was lacking, so I could focus specifically on those, not everything. I would give one practice test daily and revisit my notes according to the list of modules provided.&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1947614569763115522-754" src="https://platform.twitter.com/embed/Tweet.html?id=1947614569763115522"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1947614569763115522-754');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1947614569763115522&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;Before 1-2 days of the exam, I would suggest that you go through some external websites that provide sample exam questions, such as &lt;a href="https://tutorialsdojo.com/ai-900-microsoft-azure-ai-fundamentals-sample-exam-questions/" rel="noopener noreferrer"&gt;Tutorial Dojo&lt;/a&gt;, &lt;a href="https://app.exampro.co/student/journey/AI-900" rel="noopener noreferrer"&gt;Exam Pro&lt;/a&gt;, etc. Try solving these sample questions. This helps you get fully prepared for your test.&lt;/p&gt;




&lt;h2&gt;
  
  
  How did I appear for the exam?
&lt;/h2&gt;

&lt;p&gt;Talking about booking the exam, it costs USD 99. To get a discount, I would recommend that you go to &lt;a href="https://events.microsoft.com/en-us/mvtd" rel="noopener noreferrer"&gt;Microsoft Virtual Training Days&lt;/a&gt;, browse for AI 900, and enroll for the training day as per your convenience. Once you complete these virtual training day sessions, you will automatically get a 50% discount on the exam fees.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: This discount percentage or availability might vary in the future as decided by Microsoft.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1950860676370477154-855" src="https://platform.twitter.com/embed/Tweet.html?id=1950860676370477154"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1950860676370477154-855');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1950860676370477154&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;As for the exam mode, you can take the exam from home or go to a testing center. I preferred going to a testing center rather than clearing everything off my desk and background. Also, since this was my first certification exam, it made more sense to take it at a testing center.&lt;/p&gt;




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

&lt;p&gt;To conclude the blog, the material not only talks about services and tools offered by Azure, but also teaches lots of fundamental concepts related to AI and ML. Hence, this can be a stepping stone, especially if you want to transition into AI and ML. This certificate may help you establish your credibility, which in turn can help you get that opportunity that you have been looking for. &lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1950914135526371814-90" src="https://platform.twitter.com/embed/Tweet.html?id=1950914135526371814"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1950914135526371814-90');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1950914135526371814&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;Also, I hope you understand that this is a fundamental-level certificate, so you still need to do a lot of work and learning. Thus, have a next step ready for yourself after this. Best of Luck!!&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Disclaimer:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Please note that the content and structure of this certification may change in the future. Microsoft Learn can update the modules, add or remove topics, or change how the exam is evaluated. The information shared in this blog is based on what was available at the time I prepared for the exam.&lt;/p&gt;

</description>
      <category>azure</category>
      <category>ai</category>
      <category>machinelearning</category>
      <category>certification</category>
    </item>
    <item>
      <title>Career Reflection: No More Survival Jobs</title>
      <dc:creator>Dev J. Shah 🥑</dc:creator>
      <pubDate>Mon, 04 Aug 2025 12:00:00 +0000</pubDate>
      <link>https://forem.com/busycaesar/dont-read-this-blog-eg3</link>
      <guid>https://forem.com/busycaesar/dont-read-this-blog-eg3</guid>
      <description>&lt;h2&gt;
  
  
  Disclaimer
&lt;/h2&gt;

&lt;p&gt;The following blog was written on 1st October 2024.&lt;/p&gt;




&lt;p&gt;With a miserable heart, I am writing this blog today. I might not even post it anytime. However, I guess expressing my feelings through writing might help me calm down. &lt;/p&gt;

&lt;p&gt;Hello, I am Dev. I recently graduated from Seneca with an Advanced Diploma in Computer Programming and Analysis. Besides having a diploma, I also have 8 months of co-op experience, 3-4 months of volunteering experience, 2 months of freelancing experience, and currently, this is the 10th month working as a Research Assistant. These are all the experiences working on a Software Development project, apart from doing all the survival jobs. &lt;/p&gt;

&lt;p&gt;I started applying for jobs in Feb/March. However, I have not got anything. I don't mean to have an ego, but I believe not everyone graduates with the length as well as the variety of experience that I have. I could have just avoided the volunteering or freelancing work if I wanted to. There was no significant financial benefit involved based on the work and hours that I kept. But I still chose to work because I genuinely wanted to. With all these experiences, I believe that I have good enough skills to start working as a Developer. This is the last month of my contract, and after that, I don't know what I'm going to do. How am I planning to earn money? &lt;/p&gt;

&lt;p&gt;Frankly, I have almost nothing in my account at the moment. Not that I have not saved while I was earning, but I have also paid 50% of my tuition fees by myself, which sums up to almost CAD 25,000. Additionally, I have been living on my own for almost 3 years now, and I have never ever asked my family for any financial help apart from some food which they send me, and that too only if anyone is coming from India to Canada. &lt;/p&gt;

&lt;p&gt;Coming back to the topic, this blog is not to get any kind of sympathy. If I get nothing, the only option I have is to go back to working survival jobs, and since I am being honest in this blog, I literally hate it. No offence to anyone working at survival jobs, because of course someone has to do it. But I think if I have to do survival jobs, that would be a waste of my skills and a human resource. I love Tim Hortons, but I don't want to work there to serve others coffee. I am not made for that thing. And again, I know that I don't want to do survival jobs because I have done survival jobs for 2 years and 8 months, to be specific, including working at Tim Hortons for 10 months. It would be a curse on me if I had to go back and do survival jobs. &lt;/p&gt;

&lt;p&gt;My duty is to develop software, and as I can call it, my dharma is to develop software for now and not serve food. I want to believe in the famous Bhagwat Geeta quote, &lt;code&gt;धर्मो रक्षति रक्षितः&lt;/code&gt;, which means if you protect your dharma, your dharma will protect you. &lt;/p&gt;

&lt;p&gt;Moving forward, I also got rejections for a few entry-level positions. I took it personally and got offended that these companies think I am not good enough for their entry-level jobs. Again, not being egoistic, but I bet not most of the graduates have experience as I do. I do not know what to do!&lt;/p&gt;

&lt;p&gt;I shall have no self-respect if I push myself to do a survival job. I understand that men should adapt as per the situation and not everyone gets what they want, but I want my self-respect. &lt;/p&gt;

&lt;p&gt;I shall protect my career, and my career shall protect me. I did write some harsh things. I am feeling a bit relieved but still miserable. A bit less than when I started writing this. Thanks for reading this.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/fUcVUNViUG4"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Exploring RAG: Math behind Embeddings &amp; Cosine Similarity</title>
      <dc:creator>Dev J. Shah 🥑</dc:creator>
      <pubDate>Tue, 29 Jul 2025 12:00:00 +0000</pubDate>
      <link>https://forem.com/busycaesar/embeddings-cosine-similarity-4541</link>
      <guid>https://forem.com/busycaesar/embeddings-cosine-similarity-4541</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This blog will discuss two main components of Retrieval Augmented Generation: the ingestion of data into a vector database and the retrieval of a relevant chunk of data using cosine similarity.&lt;/p&gt;




&lt;h2&gt;
  
  
  Brief About RAG
&lt;/h2&gt;

&lt;p&gt;Before going further, as a prerequisite, here is a brief explanation of Retrieval Augmented Generation for those who are not familiar with this concept. Please feel free to skip to the next sections if you already know RAG.&lt;/p&gt;

&lt;p&gt;This technique was designed to provide context to the LLM when it comes to generating responses to domain-specific questions. LLMs were trained on a vast amount of general data available on the internet. Hence, when a user asks a domain-specific question, for example, related to medical, legal, etc., a usual tendency of LLMs is to hallucinate. To resolve these issues, RAG was introduced.&lt;/p&gt;

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

&lt;p&gt;The way the RAG technique works is that, first, the domain-specific data is split into various chunks. For example, if the data is in the form of multiple paragraphs, that data is split into each paragraph.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; There are various methods of data splitting, such as by the number of characters, paragraphs, etc.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once the data is split into chunks, each chunk is not converted into an array of numbers. The reason for converting text into numbers is that computers can only understand numbers and not words. Further, this array of numbers, along with their associated data chunk, is stored in a vector database.&lt;/p&gt;

&lt;p&gt;Now, when a user asks a domain-specific question to LLM, the text of this question is also converted into an array of numbers using the same method that was used to convert the data. Further, this array of numbers (of the question’s text) is passed to the vector database. The vector database now uses something known as cosine similarity to search for the most relevant chunk/s of data that can help answer the user’s question and returns these chunk/s. At this point in time, we have the user’s question and the most relevant chunk/s of data (that can answer the user’s question) from the vector database. Subsequently, we can pass the user’s question to the LLM along with the chunk/s of data, as context, which ensures that the LLM’s response is grounded in the actual stored data, making the answer more accurate, up-to-date, and trustworthy. If you want to know more about RAG, please check out &lt;a href="https://dev.to/busycaesar/series/29180"&gt;RAG Explained&lt;/a&gt; series.&lt;/p&gt;

&lt;p&gt;As you would have noticed, RAG has two core functionalities: Converting text into an array of numbers and retrieving the relevant chunk/s of data using cosine similarity. In the next sections, we are going to learn how these are done and have a good overall understanding.&lt;/p&gt;




&lt;h2&gt;
  
  
  Text into Numbers
&lt;/h2&gt;

&lt;p&gt;First, we will discuss how the text is converted into an array of numbers. But instead of directly discussing the actual technique used, let me also discuss the alternatives. This will help you give more perspective on why we use what we use.&lt;/p&gt;

&lt;p&gt;When someone mentions converting text into numbers, the first method that comes to mind is to create a big vocabulary table that stores all the words along with an index. Now, we can refer to this table and easily convert sentences/paragraphs into an array of numbers.&lt;/p&gt;

&lt;p&gt;Consider the example of the following vocabulary table, alphabetically ordered.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Index&lt;/th&gt;
&lt;th&gt;Word&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;best&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;client&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;for&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;high-quality&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;i&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;is&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;know&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;provide&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;service&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;software&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;11&lt;/td&gt;
&lt;td&gt;the&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;think&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;td&gt;tribalscale&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;…&lt;/td&gt;
&lt;td&gt;…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;100,000&lt;/td&gt;
&lt;td&gt;zod&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Using the above table to convert the following sentence: “I think TribalScale provides the best services.”. The array of numbers will become [5, 12, 13, 8, 11, 1, 9].&lt;/p&gt;

&lt;p&gt;Taking one more example of the following sentence: “TribalScale is known for providing high-quality service.”. The array of numbers for this sentence becomes [13, 6, 7, 3, 8, 4, 9].&lt;/p&gt;

&lt;p&gt;Great. This sounds like a straightforward approach. However, considering our use case, there are a couple of issues with this method. To start with, unless the vocabulary table is there, these numbers are random. Moreover, we required something that can help us find the relation between two chunks, to be able to search for the most relevant chunk of data. Nonetheless, when we keep the array of numbers for both the above sentences together without the text,&lt;/p&gt;

&lt;p&gt;Sentence 1: [5, 12, 13, 8, 11, 1, 9]&lt;br&gt;
Sentence 2: [13, 6, 7, 3, 8, 4, 9]&lt;/p&gt;

&lt;p&gt;It's hard to tell if both of these sentences are related to each other. Plus, with the number of words increasing in the vocabulary table, we might have indices in millions. Hence, this would not be an ideal approach, looking at the compute required and the cost associated with that compute.&lt;/p&gt;

&lt;p&gt;Therefore, this calls for another approach. Another approach should help identify if two sentences are related to each other. This is when we should talk about ‘Word Embeddings’.&lt;/p&gt;

&lt;p&gt;“Word Embeddings” is a technique that allows converting text into an array of numbers while also capturing the relationship between all chunks. In this method, instead of using a vocabulary table, we have a list of parameters or, in simple words, flags. For example, the following list.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Parameters/Flags&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Is Company?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Is Opinion?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Is Positive?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Is a service?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Is location?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;…&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Now, based on the sentence, we will answer each flag, anywhere between 0 and 1, including decimals. If the answer is yes, we use 1; if the answer is no, we use 0, and if the answer is anywhere in between, we use a decimal value in the range. Considering both the above sentences, along with a new sentence.&lt;/p&gt;

&lt;p&gt;Sentence 1: “I think TribalScale provides the best services.”&lt;br&gt;
Sentence 2: “TribalScale is known for providing high-quality service.”&lt;br&gt;
Sentence 3: “I live in Toronto”&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Parameters/Flags&lt;/th&gt;
&lt;th&gt;Sentence 1&lt;/th&gt;
&lt;th&gt;Sentence 2&lt;/th&gt;
&lt;th&gt;Sentence 3&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Is Company?&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0.1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Is Opinion?&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0.8&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Is Positive?&lt;/td&gt;
&lt;td&gt;0.9&lt;/td&gt;
&lt;td&gt;0.7&lt;/td&gt;
&lt;td&gt;0.1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Is a service?&lt;/td&gt;
&lt;td&gt;0.9&lt;/td&gt;
&lt;td&gt;0.9&lt;/td&gt;
&lt;td&gt;0.2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Is location?&lt;/td&gt;
&lt;td&gt;0.1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Is city?&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;…&lt;/td&gt;
&lt;td&gt;…&lt;/td&gt;
&lt;td&gt;…&lt;/td&gt;
&lt;td&gt;…&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The values are approx and used for explanation.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This array of numbers is called embedding. Thus, the embeddings for all three sentences become,&lt;/p&gt;

&lt;p&gt;Sentence 1: [   1,      1,   0.9,   0.9,   0.1,   0, …]&lt;br&gt;
Sentence 2: [   1,    0.8,   0.7,   0.9,     0,   0, …]&lt;br&gt;
Sentence 3: [ 0.1,      0,   0.1,   0.2,     1,   1, …]&lt;/p&gt;

&lt;p&gt;This time, when you see the embeddings for all the sentences together, it is evident that for each index, the values of the index of sentence 1 and sentence 2 are very similar or near to each other; nonetheless, the same for sentence 3 is far. This indicates that sentences 1 and 2 are more similar to each other than sentence 3.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In real life, there are hundreds and thousands of such parameters/flags, which increase the accuracy of embeddings.&lt;/li&gt;
&lt;li&gt;The model comes up with these parameters by itself when it is being trained on a huge amount of text.&lt;/li&gt;
&lt;li&gt;For simplicity, we took the range of 0 to 1 to answer the parameters/flags, but it can vary based on the model used for generating the embeddings. It can be from -1 to 1, -3 to 3, but the fundamental purpose remains the same.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;To revise what we saw so far. We first had data (paragraphs), which we split into chunks (each paragraph), then generated embeddings for each chunk, and lastly stored these embeddings along with the text into a vector database.&lt;/p&gt;


&lt;h2&gt;
  
  
  Cosine Similarity to search for relevant chunk/s
&lt;/h2&gt;

&lt;p&gt;Moving towards the next section, since we now have all the data stored in the vector database, it is time to see how does vector database searches for the more relevant data based on the user's question. To understand this, we need to plot some graphs.&lt;/p&gt;

&lt;p&gt;Getting back the embeddings of all the sentences,&lt;/p&gt;

&lt;p&gt;Sentence 1: [   1,      1,   0.9,   0.9,    0.1,   0, …]&lt;br&gt;
Sentence 2: [   1,    0.8,   0.7,   0.9,      0,   0, …]&lt;br&gt;
Sentence 3: [ 0.1,      0,   0.1,   0.2,      1,   1, …]&lt;/p&gt;

&lt;p&gt;Each index in these embeddings represents a coordinate in the graph. So {1, 1, 0.1} (first index value of three sentences) becomes the x-axis, {1, 0.8, 0} becomes the y-axis, and so on. These current embeddings have 6 coordinates. Since it is easy for us to see and observe a 3D graph, for explanation purposes, we will only consider the first three indices of each sentence. Hence, the following.&lt;/p&gt;

&lt;p&gt;Sentence 1: [   1,      1,   0.9]&lt;br&gt;
Sentence 2: [   1,    0.8,   0.7]&lt;br&gt;
Sentence 3: [ 0.1,      0,   0.1]&lt;/p&gt;

&lt;p&gt;Upon plotting these values on a graph, we get,&lt;/p&gt;

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

&lt;p&gt;The graph clearly states that sentences 1 and 2 are going in the same direction, while sentence 3 is going in another direction. &lt;/p&gt;

&lt;p&gt;Now, let's take a sample user’s question, “Which company provides the best services?”. To find the relevant chunk of data to answer this question, we need to use the same strategy to convert this text into embeddings.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Parameters/Flags&lt;/th&gt;
&lt;th&gt;User’s Question&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Is Company?&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Is Opinion?&lt;/td&gt;
&lt;td&gt;0.8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Is Positive?&lt;/td&gt;
&lt;td&gt;0.8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Is a service?&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Is location?&lt;/td&gt;
&lt;td&gt;0.1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Is city?&lt;/td&gt;
&lt;td&gt;0.1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;…&lt;/td&gt;
&lt;td&gt;…&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The embeddings for the user’s question become [1, 0.8, 0.8, 1, 0.1, 0.1, …], and to plot it on a graph, consider the first three embeddings [1, 0.8, 0.8]. Upon plotting this user’s question on the same graph as above, we get,&lt;/p&gt;

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

&lt;p&gt;Here, you can see that the line for the user’s prompt and that of sentences 1 and 2 are going in the same direction, whereas that of sentence 3 is in a different direction. Visually, it's evident that since the line of the user’s prompt is going in the same direction as sentences 1 and 2; hence, they are the most relevant chunk/s of data to answer the user’s question. But we need numbers to prove this. This is where cosine similarity comes in.&lt;/p&gt;

&lt;p&gt;Before going into calculations, let me first explain the reason for using cosine similarity. In simple words, cosine similarity means to find the value of cos θ, where θ is the angle between two lines. The value of cos θ can be anywhere between -1 to 1. If the value of cos θ is&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1; it indicates that both lines are perfectly aligned with each other; hence, the angle between them is 0.&lt;/li&gt;
&lt;li&gt;0; it indicates that both lines are perpendicular to each other.&lt;/li&gt;
&lt;li&gt;-1; it indicates that both lines are in different directions, having a 180-degree angle with each other.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With this analogy, if we find the angle between the line of the user’s question and all three sentences and calculate the value cos θ of those angles, we can get the number of how aligned the lines of each sentence are with the line of the user’s question. This is the reason for using cosine similarity.&lt;/p&gt;

&lt;p&gt;The following are the calculated angles between the line of the user’s question and the line of each sentence.&lt;/p&gt;

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

&lt;p&gt;If we calculate the cos θ of all these three angles, we get,&lt;/p&gt;

&lt;p&gt;Angle between the user’s prompt and sentence 1: 5.38°&lt;br&gt;
cos 5.38°: 0.9955&lt;/p&gt;

&lt;p&gt;Angle between the user’s prompt and sentence 2: 3.33°&lt;br&gt;
cos 3.33°: 0.9983&lt;/p&gt;

&lt;p&gt;Angle between the user’s prompt and sentence 3: 32.55°&lt;br&gt;
cos 32.55°: 0.8429&lt;/p&gt;

&lt;p&gt;Since the values of cos θ for sentences 1 and 2 are very close to 1, it indicates that they are more relevant to the user’s question.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The value of cos θ between sentence 3 and the user’s question is also close to 1 because, for calculations, we only used the first 3 parameters/flags to plot the graph. But in real life, all the hundreds and thousands of parameters/flags are considered, which increases the accuracy of these calculations.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Alright, before going further, let me do a quick recap of what we learnt so far.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;First, we converted the text into numbers, then we plotted a line on the graph using those numbers.&lt;/li&gt;
&lt;li&gt;Second, we converted the text of the user’s question into numbers and plotted those numbers on a graph.&lt;/li&gt;
&lt;li&gt;Lastly, we calculated the angle between the data’s line and the user’s question’s line and used that angle to calculate the value of cos θ, which specifies how aligned each data chunk is to the user’s question.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Perfect. Now, the issue is, for all the questions that the user asks, we cannot go ahead and plot all these lines on a graph, calculate the angle, and cos θ to find which is the most relevant chunk of data based on the user’s question. Therefore, we need a formula that can help us calculate the value of cos θ directly using the embeddings of the sentences. For this purpose, we use the formula of the dot product.&lt;/p&gt;

&lt;p&gt;

&lt;/p&gt;
&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;A⃗ . B⃗ =∥A∥ × ∥B∥ × cos θcos θ=A⃗ . B⃗∥A∥ × ∥B∥cos θ=∑i=1nAi×Bi∑i=1nAi2×∑i=1nBi2
\vec{A}\space.\space\vec{B}\space= \Vert A \Vert\space\times\space\Vert B \Vert\space\times\space cos\space\theta
\newline
cos\space\theta = \frac{\vec{A}\space.\space\vec{B}}{\Vert A \Vert\space\times\space\Vert B \Vert}
\newline
cos\space\theta = \frac{\sum\limits_{i=1}^{n}A_{i}\times B_{i}}{\sqrt{\sum\limits_{i=1}^{n}A_{i}^{2}}\times\sqrt{\sum\limits_{i=1}^{n}B_{i}^{2}}}
&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord accent"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;A&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="accent-body"&gt;&lt;span class="overlay"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mord"&gt;.&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mord accent"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;B&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="accent-body"&gt;&lt;span class="overlay"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;∥&lt;/span&gt;&lt;span class="mord mathnormal"&gt;A&lt;/span&gt;&lt;span class="mord"&gt;∥&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;×&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;∥&lt;/span&gt;&lt;span class="mord mathnormal"&gt;B&lt;/span&gt;&lt;span class="mord"&gt;∥&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;×&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;cos&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mord mathnormal"&gt;θ&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace newline"&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;cos&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mord mathnormal"&gt;θ&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mopen nulldelimiter"&gt;&lt;/span&gt;&lt;span class="mfrac"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord"&gt;∥&lt;/span&gt;&lt;span class="mord mathnormal"&gt;A&lt;/span&gt;&lt;span class="mord"&gt;∥&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;×&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;∥&lt;/span&gt;&lt;span class="mord mathnormal"&gt;B&lt;/span&gt;&lt;span class="mord"&gt;∥&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="frac-line"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord accent"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;A&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="accent-body"&gt;&lt;span class="overlay"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mord"&gt;.&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mord accent"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;B&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="accent-body"&gt;&lt;span class="overlay"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose nulldelimiter"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace newline"&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;cos&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mord mathnormal"&gt;θ&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mopen nulldelimiter"&gt;&lt;/span&gt;&lt;span class="mfrac"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord sqrt"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span class="svg-align"&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mop op-limits"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;i&lt;/span&gt;&lt;span class="mrel mtight"&gt;=&lt;/span&gt;&lt;span class="mord mtight"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="mop op-symbol small-op"&gt;∑&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;n&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;A&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="hide-tail"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;×&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord sqrt"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span class="svg-align"&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mop op-limits"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;i&lt;/span&gt;&lt;span class="mrel mtight"&gt;=&lt;/span&gt;&lt;span class="mord mtight"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="mop op-symbol small-op"&gt;∑&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;n&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;B&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="hide-tail"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="frac-line"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mop op-limits"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;i&lt;/span&gt;&lt;span class="mrel mtight"&gt;=&lt;/span&gt;&lt;span class="mord mtight"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="mop op-symbol small-op"&gt;∑&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;n&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;A&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;×&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;B&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose nulldelimiter"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;Applying this formula for sentence 2 and the user’s question,&lt;/p&gt;

&lt;p&gt;Sentence 2:        [   1,   0.8,   0.7]&lt;br&gt;
User’s Question: [   1,   0.8,   0.8]&lt;/p&gt;


&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;cos θ=(1×1)+(0.8×0.8)+(0.7×0.8)12+0.82+0.72×12+0.82+0.82cos θ=2.22.13×2.28cos θ=2.21.459×1.509cos θ=0.9995
cos\space\theta = \frac{(1\times1) + (0.8\times0.8)+(0.7\times0.8)}{\sqrt{1^2 + 0.8^2 + 0.7^2}\times\sqrt{1^2 + 0.8^2 + 0.8^2}}
\newline
cos\space\theta = \frac{2.2}{\sqrt{2.13}\times\sqrt{2.28}}
\newline
cos\space\theta = \frac{2.2}{1.459\times1.509}
\newline
cos\space\theta = 0.9995
&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;cos&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mord mathnormal"&gt;θ&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mopen nulldelimiter"&gt;&lt;/span&gt;&lt;span class="mfrac"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord sqrt"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span class="svg-align"&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord"&gt;&lt;span class="mord"&gt;1&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;+&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;0.&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord"&gt;8&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;+&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;0.&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord"&gt;7&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="hide-tail"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;×&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord sqrt"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span class="svg-align"&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord"&gt;&lt;span class="mord"&gt;1&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;+&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;0.&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord"&gt;8&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;+&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;0.&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord"&gt;8&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="hide-tail"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="frac-line"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;1&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;×&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;1&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;+&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;0.8&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;×&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;0.8&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;+&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;0.7&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;×&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;0.8&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose nulldelimiter"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace newline"&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;cos&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mord mathnormal"&gt;θ&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mopen nulldelimiter"&gt;&lt;/span&gt;&lt;span class="mfrac"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord sqrt"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span class="svg-align"&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord"&gt;2.13&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="hide-tail"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;×&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord sqrt"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span class="svg-align"&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord"&gt;2.28&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="hide-tail"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="frac-line"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord"&gt;2.2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose nulldelimiter"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace newline"&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;cos&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mord mathnormal"&gt;θ&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mopen nulldelimiter"&gt;&lt;/span&gt;&lt;span class="mfrac"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord"&gt;1.459&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;×&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;1.509&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="frac-line"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord"&gt;2.2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose nulldelimiter"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace newline"&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;cos&lt;/span&gt;&lt;span class="mspace"&gt; &lt;/span&gt;&lt;span class="mord mathnormal"&gt;θ&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;0.9995&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;The value of cos θ for sentence 2 and the user’s question’s embeddings, which was obtained from calculations, is very close to what we found via plotting lines from the graph. Using this formula, we can get the value of cos θ directly from this formula by directly using the embeddings.&lt;/p&gt;




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

&lt;p&gt;Ah, alright, guys. The main purpose of this blog was to understand how these two core functionalities work in Vector Database. The good news is that we don't need to do all these calculations to build a RAG-powered application. There are existing frameworks, such as LangChain, that can do all these things, and all you need to do is call the appropriate function as required.&lt;/p&gt;

&lt;p&gt;In case you want to try a RAG-powered application, &lt;a href="https://github.com/busycaesar/Embeddings_Cosine_Similarity/blob/Master/rag_documentation.md" rel="noopener noreferrer"&gt;here&lt;/a&gt; is the documentation.&lt;/p&gt;

</description>
      <category>vectordatabase</category>
      <category>rag</category>
      <category>ai</category>
    </item>
    <item>
      <title>Linear Regression Model using Math!</title>
      <dc:creator>Dev J. Shah 🥑</dc:creator>
      <pubDate>Sat, 31 May 2025 14:00:00 +0000</pubDate>
      <link>https://forem.com/busycaesar/regression-model-405j</link>
      <guid>https://forem.com/busycaesar/regression-model-405j</guid>
      <description>&lt;p&gt;If you are not familiar with basic Machine Learning terms like Features, Label, Training, Inferencing, please check out the following blog as a prerequisite.&lt;/p&gt;


&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/busycaesar/introduction-to-machine-learning-a22" class="crayons-story__hidden-navigation-link"&gt;Machine Learning 101&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/busycaesar" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1017716%2F0fdaf54f-6428-41fc-86b1-412236c6a8fe.png" alt="busycaesar profile" class="crayons-avatar__image" width="800" height="436"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/busycaesar" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Dev J. Shah 🥑
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Dev J. Shah 🥑
                
              
              &lt;div id="story-author-preview-content-2512412" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/busycaesar" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1017716%2F0fdaf54f-6428-41fc-86b1-412236c6a8fe.png" class="crayons-avatar__image" alt="" width="800" height="436"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Dev J. Shah 🥑&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/busycaesar/introduction-to-machine-learning-a22" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;May 21 '25&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/busycaesar/introduction-to-machine-learning-a22" id="article-link-2512412"&gt;
          Machine Learning 101
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/machinelearning"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;machinelearning&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/ai"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;ai&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/busycaesar/introduction-to-machine-learning-a22" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;3&lt;span class="hidden s:inline"&gt; reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/busycaesar/introduction-to-machine-learning-a22#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              Comments


              &lt;span class="hidden s:inline"&gt;Add Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            2 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;





&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Regression Models Supervised Machine Learning models that are trained to predict the label values based on the training data. In this blog, we will discuss Linear Regression.&lt;/p&gt;




&lt;h2&gt;
  
  
  Linear Regression
&lt;/h2&gt;

&lt;p&gt;Let me first set up the context. Throughout the blog, we will consider a practical example to understand the concept. Considering that we have an existing data of an ice cream shop. The data has 2 columns, one is the average temperature of each day and the second one has the number of ice cream sold.&lt;/p&gt;

&lt;p&gt;We are creating an algorithm using this existing data. The algorithm can further be used to predict the number of ice creams that can be sold given the average temperature.&lt;/p&gt;

&lt;p&gt;For this use case, we will try using linear regression. Hence, consider the algorithm to be the following,&lt;/p&gt;

&lt;p&gt;

&lt;/p&gt;
&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;y=β0+β1x+ε
y = \beta_0 + \beta_1x + \varepsilon
&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;y&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;β&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;+&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;β&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;+&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;ε&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;In this algorithm, 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;yy&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 is the label (number of ice creams), 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;xx&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 is the feature (average temperature), including 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;β0\beta_0&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;β&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 and 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;β1\beta_1&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;β&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 as parameters.&lt;/p&gt;

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

&lt;p&gt;Lets understand how this algorithm is derived.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;As the value of 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;xx&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 (features) increases the value of 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;yy&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 (prediction) will increase/decrease because we are considering a linear regression.&lt;/li&gt;
&lt;li&gt;Hence, 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;yy&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 is either directly or inversely proportional to 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;xx&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
.&lt;/li&gt;
&lt;li&gt;In our case, the value of number of ice creams will increase with the increase in temperature.&lt;/li&gt;
&lt;li&gt;Therefore, 
&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;y∝xy\propto x&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;y&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;∝&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;Therefore, 
&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;y=β1.xy = \beta_1 . x&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;y&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;β&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mord"&gt;.&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;

where 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;β1\beta_1&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;β&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 = constant of proportionality. Also called the slope of the line describing the relationship between 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;yy&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 and 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;xx&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
.&lt;/li&gt;
&lt;li&gt;Further, consider a point at which the value of 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;yy&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 starts. In our case, we can call it the base value or the number of ice creams that are sold regardless of the temperature. This value can also be 0. Lets represent this value by 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;β0\beta_0&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;β&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
. It is the y-intercept of the line.&lt;/li&gt;
&lt;li&gt;Now the equation becomes 
&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;y=β0+β1x+εy = \beta_0 + \beta_1x + \varepsilon&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;y&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;β&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;+&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;β&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;+&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;ε&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;

where 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;ε\varepsilon&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;ε&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 = The error or the difference between the predicted label and the actual label of the feature.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Training
&lt;/h2&gt;

&lt;p&gt;Following are the steps taken place while training a linear regression model.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;The available data, that is, both features and labels are randomly splited into multiple groups.&lt;/li&gt;
&lt;li&gt;This creates various groups of data which can be used to train the model.&lt;/li&gt;
&lt;li&gt;One group is hold back, which can be further use to validate the trained model.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 2
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Take one dataset from the multiple groups that we created in the previous step.&lt;/li&gt;
&lt;li&gt;Use a regression algorithm such as linear regression to fit the training data into a model. In other words, create a formula, based on the known data, by assuming the values of 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;β0\beta_0&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;β&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 and 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;β1\beta_1&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;β&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 such that it predicts the right label for given feature.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 3
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Use the group of data that we held, to validate the model by letting it predict the labels for the features.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 4
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Compare the known actual labels in the group of data, with the labels that model predicted.&lt;/li&gt;
&lt;li&gt;Then aggregate the differences between the predicted and actual label, to calculate a metric that indicates how accurately the model predicted for the validation data.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After each train, validate and evaluate iteration. You can repeat the process with different algorithms and parameters, until an acceptable evaluation metric is achieved.&lt;/p&gt;

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




&lt;h2&gt;
  
  
  Regression evaluation metrics
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Based on the predicted and actual values, you can calculate some common metrics that are used to evaluate a regression model.&lt;/li&gt;
&lt;li&gt;For understanding each metrics, consider the following observations for the ice cream sales.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Temperature&lt;br&gt;(
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;X\mathcal{X}&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathcal"&gt;X&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
)&lt;/th&gt;
&lt;th&gt;Actual sales&lt;br&gt;(
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;Y\mathcal{Y}&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathcal"&gt;Y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
)&lt;/th&gt;
&lt;th&gt;Predicted sales&lt;br&gt;(
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;Y^\hat{\mathcal{Y}}&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord accent"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord mathcal"&gt;Y&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="accent-body"&gt;&lt;span class="mord"&gt;^&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
)&lt;/th&gt;
&lt;th&gt;Absolute Difference&lt;br&gt;(
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;∣Y^−Y∣\lvert\hat{\mathcal{Y}} - \mathcal{Y}\lvert&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mopen"&gt;∣&lt;/span&gt;&lt;span class="mord accent"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord mathcal"&gt;Y&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="accent-body"&gt;&lt;span class="mord"&gt;^&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;−&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathcal"&gt;Y&lt;/span&gt;&lt;span class="mopen"&gt;∣&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;52&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;67&lt;/td&gt;
&lt;td&gt;14&lt;/td&gt;
&lt;td&gt;17&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;70&lt;/td&gt;
&lt;td&gt;23&lt;/td&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;73&lt;/td&gt;
&lt;td&gt;22&lt;/td&gt;
&lt;td&gt;23&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;78&lt;/td&gt;
&lt;td&gt;26&lt;/td&gt;
&lt;td&gt;28&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;83&lt;/td&gt;
&lt;td&gt;36&lt;/td&gt;
&lt;td&gt;33&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Mean Absolute Error (MAE)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The value of MAE is the average of all the absolute differences. Hence, the name &lt;strong&gt;Mean Absolute Error&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;In the ice cream example, the mean (average) of the absolute errors (2, 3, 3, 1, 2, and 3) is 2.33.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Mean Squared Error (MSE)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The Mean Absolute Error takes into account, all the discrepancies between the predicted and actual labels equally. However, it is more desirable to have a model that consistently makes small errors vs a model that makes fewer but large errors.&lt;/li&gt;
&lt;li&gt;One way of getting that metrics that amplifies the large errors is by squaring the individual errors and calculating the mean of the squared values. This metric is known as Mean Squared Error.&lt;/li&gt;
&lt;li&gt;In our ice cream example, the mean of the squared absolute values (which are 4, 9, 9, 1, 4, and 9) is 6.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Root Mean Squared Error (RMSE)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The Mean Squared Error helps take the magnitude of errors into account, but because it squares the error values, the resulting metric no longer represents the quantity measured by the label.&lt;/li&gt;
&lt;li&gt;To get the error in terms of the unit of label, we need to calculate the square root of MSE. It produces a metric called Root Mean Squared Error.&lt;/li&gt;
&lt;li&gt;In this case 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;6\sqrt{6}&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord sqrt"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span class="svg-align"&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord"&gt;6&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="hide-tail"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
, which is 2.45 (ice creams).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Coefficient of determination (
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;R2R^2&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;R&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;All the metrics so far, compare the discrepancy between the predicted and the actual value in order to evaluate the model. However, in reality, there is some natural random variance in the daily data that model takes into account.&lt;/li&gt;
&lt;li&gt;To find the natural variation existing in each data, we need to have a reference point. This reference point can be the average of all the data. Using this reference point, we can calculate the variation that exist in the data.&lt;/li&gt;
&lt;li&gt;In this case, the average of the actual sales is 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;≈20.167\approx20.167&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;≈&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;20.167&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
. Now the absolute variation in each data can be calculated as 20.167, 6.167, 3.167, 2.167, 6.167 and 16.167.&lt;/li&gt;
&lt;li&gt;Now we will find the RMS value of these data due to the same reasons as mentioned in Mean Square Error description. The RMS value of the data is 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;≈11.25\approx11.25&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;≈&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;11.25&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
. This is the variation that already exists in the data.&lt;/li&gt;
&lt;li&gt;Now, we need to find the variation in the predicted data and the actual data. For this one we do not need a reference value because we already have 2 entities.&lt;/li&gt;
&lt;li&gt;The absolute variation in the data predicted by the model is 2, 3, 3, 1, 2, 3. The RMS value of this variation is 2.45.&lt;/li&gt;
&lt;li&gt;Now, the actual (or ideal) variation in the data is 11.25 and the total variation by the model is 2.45. If we remove the total variation by the model from the actual variation in the data, we get 11.25 - 2.45 = 8.8. This is the proportion of the variation from the actual variation that we can get from the model.&lt;/li&gt;
&lt;li&gt;Hence, to calculate how well the model explains the data, we divide the variation the model is able to capture (which is 11.25−2.45=8.8) by the total variation in the data (which is 11.25). The value that we get, indicates how accurate the model is.  This value is call the coefficient of determination, which ranges between 0 to 1.&lt;/li&gt;
&lt;li&gt;1 indicates that the model is efficiently able to get the variation that already exists in the data; while 0 indicates that the model is inefficient and it is only able to guess the mean.&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;All the metrics explained above are used to evaluate a regression model. A data scientist uses an iterative approach to repeatedly train and evaluate a model, varying:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Feature Selection and Preparation&lt;/strong&gt;: Choosing which features to include in the model, and calculations applied to them to help ensure a better fit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Algorithm selection&lt;/strong&gt;: There are many regression algorithms&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Algorithm parameters&lt;/strong&gt;: In case of linear regression algorithm, the parameters were 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;β0,β1\beta_0, \beta_1&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;β&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mpunct"&gt;,&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;β&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 etc. However, in general parameters means the coefficients that represents the relationship between the features and the predicted value of labels.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Final Words
&lt;/h2&gt;

&lt;p&gt;Thank you for reading the blog. I understand that these concepts are hard to understand, especially with limited math and statistics knowledge. Hence, if you have any questions or thoughts, feel free to discuss them in the comments or try to contact me via any of my &lt;a href="https://bento.me/busycaesar" rel="noopener noreferrer"&gt;social profiles&lt;/a&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Citation
&lt;/h2&gt;

&lt;p&gt;This blog post is inspired by a &lt;a href="https://learn.microsoft.com/en-us/training/modules/fundamentals-machine-learning/4-regression" rel="noopener noreferrer"&gt;Microsoft Learn course's module&lt;/a&gt;. While the foundational concepts are based on the course material, I have expanded on them with additional explanations, examples, and insights to better simplify and contextualize the information for readers.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Machine Learning 101</title>
      <dc:creator>Dev J. Shah 🥑</dc:creator>
      <pubDate>Wed, 21 May 2025 22:08:43 +0000</pubDate>
      <link>https://forem.com/busycaesar/introduction-to-machine-learning-a22</link>
      <guid>https://forem.com/busycaesar/introduction-to-machine-learning-a22</guid>
      <description>&lt;p&gt;In very simple terms, Machine Learning is the process of using existing data to create a mathematical function.&lt;/p&gt;




&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;For example, we have an ice cream shop's data that includes the average temperature of the past 30 days, along with the number of ice creams sold on each day. We can analyze this data (average temperature and number of ice creams sold) and can create a mathematical function that fits with the existing data.&lt;/p&gt;

&lt;p&gt;Further, this function can take the average temperature as input and return the prediction of the number of ice creams that can be sold on that day.&lt;/p&gt;




&lt;h2&gt;
  
  
  Terminologies
&lt;/h2&gt;

&lt;p&gt;From the existing data, the data that we use as the condition, in our case, the average temperature, is called a &lt;strong&gt;Feature&lt;/strong&gt;. The main data that we are targeting to predict, in our case, the number of ice creams sold, is called the &lt;strong&gt;Label&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In mathematical terms, the features are referred using 

&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;xx&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
. Hence, the features can be represented as [
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;x1,x2,x3,...,xnx_1, x_2, x_3, ..., x_n&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mpunct"&gt;,&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mpunct"&gt;,&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mpunct"&gt;,&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;...&lt;/span&gt;&lt;span class="mpunct"&gt;,&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;n&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
]; whereas the label is referred to as 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;yy&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
.&lt;/p&gt;

&lt;p&gt;The process of defining the function using the existing data is called &lt;strong&gt;Training&lt;/strong&gt;. This is the step where the model (a general term used for the mathematical function we create) learns the relationship between features and labels.&lt;/p&gt;

&lt;p&gt;Further, the process of using the defined function to get the predicted value is called &lt;strong&gt;Inferencing&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In mathematical terms, the function is referred to as 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;f(x)f(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;f&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
. Moreover, the predicted value by the function is referred to as 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;y^=f(x)\hat{y} = f(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord accent"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;y&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="accent-body"&gt;&lt;span class="mord"&gt;^&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;f&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/p&gt;




&lt;p&gt;There are multiple types of Machine Learning; but at the core, Machine Learning can be classified into two types:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Supervised Machine Learning&lt;/li&gt;
&lt;li&gt;Unsupervised Machine Learning&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Supervised Machine Learning
&lt;/h2&gt;

&lt;p&gt;Supervised Machine Learning is a type of Machine Learning algorithm in which the training data includes both the feature values and the known label values. This type of algorithm is used to train models by determining a relationship between the features and labels in past observations. This helps the model predict unknown labels for new inputs where the feature values are known.&lt;/p&gt;




&lt;h2&gt;
  
  
  Unsupervised Machine Learning
&lt;/h2&gt;

&lt;p&gt;Unsupervised Machine Learning is a type of algorithm in which the training data only includes the feature values, but no known labels. It determines the relationships and patterns between the features of the observations in the training data.&lt;/p&gt;




&lt;h2&gt;
  
  
  Citation
&lt;/h2&gt;

&lt;p&gt;This blog post is inspired by a &lt;a href="https://learn.microsoft.com/en-us/training/modules/fundamentals-machine-learning/2-what-is-machine-learning" rel="noopener noreferrer"&gt;Microsoft Learn course's module&lt;/a&gt;. While the foundational concepts are based on the course material, I have expanded on them with additional explanations, examples, and insights to better simplify and contextualize the information for readers.&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
