<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vassiliki Dalakiari on Medium]]></title>
        <description><![CDATA[Stories by Vassiliki Dalakiari on Medium]]></description>
        <link>https://medium.com/@vadal_?source=rss-f1558d10c1f5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*HE9SJdQlX-D17sMOd9bX8A.png</url>
            <title>Stories by Vassiliki Dalakiari on Medium</title>
            <link>https://medium.com/@vadal_?source=rss-f1558d10c1f5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 07:21:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vadal_/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Deep AI Learning Part 2: Building Neurons, Layers, and the Training Loop]]></title>
            <link>https://itnext.io/build-neural-network-from-scratch-python-3ed125f758ed?source=rss-f1558d10c1f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ed125f758ed</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Vassiliki Dalakiari]]></dc:creator>
            <pubDate>Fri, 09 Oct 2026 07:50:39 GMT</pubDate>
            <atom:updated>2026-10-09T07:50:39.981Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>How to teach a neural network to learn by building a custom Multi-Layer Perceptron and writing a Gradient Descent training loop using the First-Principles Methodology.</em></h4><figure><img alt="Title card for Deep AI Learning Part 2: Building Neurons, Layers, and the Training Loop." src="https://cdn-images-1.medium.com/max/1024/1*zoGVrvkC9beT1lK4ekyDSA.png" /></figure><p>In <a href="https://itnext.io/deep-ai-learning-part-1-building-an-autograd-engine-ab443deeaf4d">Part 1</a>, we built an Autograd engine and learned about the forward pass, backpropagation, and the math behind them. In this article, our goal is to assemble those gears into a working mathematical machine (a Neural Network) and write the code that actually teaches it to learn.</p><p>Applying my <a href="https://itnext.io/the-first-principles-methodology-a-code-first-approach-to-learning-704653a1032a">First-Principles Methodology</a>, this is the curriculum for today’s build:</p><ul><li><strong>Understand what Neuron, Layer &amp; MLP are:</strong> Using the <strong>Triad Concept Node</strong>, I will break down these terms to deeply understand what they are.</li><li><strong>Build:</strong> Writing the custom Python wrappers (the Neuron, Layer and MLP objects) to record the operations.</li><li><strong>Sandbox:</strong> Using the <a href="https://github.com/vadal/first-principles-methodology-templates/blob/main/templates/Triad_Concept_Node.md">Triad Concept Node</a> to break down the training process.</li><li><strong>Read &amp; Reflect:</strong> Reading parts of a book and use the <a href="https://github.com/vadal/first-principles-methodology-templates/blob/main/templates/Q-E-C-L_Paper_Node.md">Q-E-C-L Node</a> of the methodology to fill in the conceptual holes and expose flaws in my early assumptions.</li></ul><p>Before building the final MLP architecture in code, I am going to break down the four core components: Neuron, Layer, MLP, and Loss Function, using the Triad Concept Node to build a strong conceptual foundation.</p><h3>The Neuron</h3><p>First, I wanted to keep notes on what a neuron is. I used the Triad Concept Node template to understand and document the concept.</p><h4>The Math</h4><p>A single neuron computes a very simple linear equation, followed by a non-linear “squish”. The linear equation is:</p><figure><img alt="Mathematical formula for a single neuron computing the sum of inputs multiplied by weights, plus a bias." src="https://cdn-images-1.medium.com/max/1024/1*C6OskT4-hsBqHUlaIoytMg.png" /></figure><p>Variables:</p><ul><li>xᵢ: The incoming data (inputs).</li><li>wᵢ: The weights (how much we care about each specific input).</li><li>b: The bias (a baseline trigger threshold).</li></ul><p>If we only used that equation, <strong>our entire neural network would mathematically collapse into a single straight line</strong>, no matter how many neurons we stacked. <br>To fix this, we wrap the output in an <strong>Activation Function</strong> (like Tanh), which bends that straight line into a curve, allowing the network to learn complex shapes.</p><h4>The Code</h4><p>To understand a single Neuron conceptually, we can write a simple Python function using standard math without any complex objects yet.</p><pre>import math<br><br>def simple_neuron(inputs, weights, bias):<br>    activation = sum(w * x for w, x in zip(weights, inputs)) + bias <br>    return math.tanh(activation)<br><br># Test: 2 ingredients, 2 weights, 1 bias<br>print(simple_neuron(inputs=[1.0, 0.5], weights=[-0.2, 0.8], bias=0.1))</pre><h4>The Plain English</h4><p>When learning about AI, everyone uses biological metaphors about “human brains” and “synapses.” And I wonder, how many people <strong><em>really</em></strong> know how human brains and synapses work? Human brains are still a mystery even for specialized scientists. Instead, I will use a much simpler metaphor.</p><p>I think of a neuron as a mathematical container. Let’s say we have a pastry <em>“chef ” </em>in a bakery who receives a few raw ingredients to make a cake (the inputs). The chef has a set of dials (the weights) to adjust exactly how much of each ingredient to use: maybe dialing up the sugar and dialing down the salt. They also add a baseline foundation to the bowl no matter what, like a base level of baking powder (the bias).</p><p>They mix all of these dialed-in ingredients together. But before passing it down the line, they pour the mixture into a strict, predefined <em>“baking tin”</em> to give it a specific shape and prevent it from expanding infinitely (the activation function).</p><p>When the system learns, it just sends a message back to this specific chef, telling them exactly which ingredient dials to turn to make a better recipe for the next batch.</p><blockquote><strong>Note: </strong>In this foundational build, I am using tanh to &quot;squish&quot; the numbers. However, in modern deep learning, the industry standard is <strong>ReLU (Rectified Linear Unit)</strong>.</blockquote><blockquote>The math for ReLU is incredibly simple: max(0, x). Back in the bakery, instead of the chef pouring the batter into a strict, squished tin, they simply taste it. If it tastes terrible (a negative number), they throw it in the trash (set it to 0). If it tastes good (a positive number), they pass it down the line exactly as it is.</blockquote><figure><img alt="Side-by-side graphs comparing neural network activation functions: the curved Tanh function and the angled ReLU function." src="https://cdn-images-1.medium.com/max/1024/1*YTJ9gtl78Jjf-BcgvPg21A.png" /><figcaption>Activation Functions</figcaption></figure><h3>Building a Multi-Layer Perceptron (MLP) Architecture</h3><h4>The Math</h4><p>A single neuron is just one equation. A <strong>Layer</strong>, on the other hand, is a collection of n independent neurons running their equations at the same time on the exact same incoming data. Mathematically, it outputs a vector (a list) of results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*99DQ7JRo5yyZJ8nXR03k4Q.png" /></figure><p>An <strong>MLP (Multi-Layer Perceptron)</strong> is the result of these layers stacked sequentially. The math is a chain of functions where the output of Layer 1 becomes the input data x for Layer 2:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F33997XREls12bJAwj6Jag.png" /></figure><h4>The Code</h4><pre>def simple_layer(inputs, layer_weights, layer_biases):<br>    return [simple_neuron(inputs, w, b) for w, b in zip(layer_weights, layer_biases)]<br><br>def simple_mlp(raw_inputs, network_weights, network_biases):<br>    x = raw_inputs<br>    for weights, biases in zip(network_weights, network_biases):<br>        x = simple_layer(x, weights, biases)<br>    return x</pre><h4>The Plain English</h4><p>If a single neuron is one chef mixing ingredients at a table, a <strong>Layer</strong> is a whole row of chefs standing side-by-side.</p><p>Every chef in that first row receives the exact same raw ingredients (the inputs). However, because each chef has their own personal set of dials (weights), they all produce something different. Chef A might dial up the sugar to make a sweet mixture, while Chef B dials up the cocoa for a bitter one.</p><p>An <strong>MLP (Multi-Layer Perceptron)</strong> is multiple rows of these tables lined up on the factory floor.</p><p>The first row takes the raw ingredients, mixes their specific batters, and passes them to the second row. To the chefs in the second row, those pre-mixed batters are now their <em>new</em> ingredients. They mix them together into even more complex combinations and pass them down the line. By the time it reaches the final row (which is usually just one single chef), all those simple batters have been combined into one final, highly complex cake.</p><figure><img alt="Diagram of a Multi-Layer Perceptron neural network architecture featuring 3 input nodes, two hidden layers of 4 nodes each, and 1 output node." src="https://cdn-images-1.medium.com/max/1024/1*7Ri71Uho6yFDxxeIRTQo6w.png" /><figcaption>MLP factory Architecture: [3, 4, 4, 1]</figcaption></figure><h3>The Loss Function</h3><h4>The Math</h4><p>The loss function measures how wrong our network’s final guess is compared to the correct answer. The standard formula I am using for this build is Mean Squared Error (MSE):</p><figure><img alt="Mathematical formula for the Mean Squared Error (MSE) loss function used in neural networks." src="https://cdn-images-1.medium.com/max/1024/1*hhwubN6q1FbJvE97xWemOQ.png" /></figure><p>Variables:</p><ul><li>y_pred: Our network’s final guess.</li><li>y_true: The actual correct answer we wanted.</li></ul><p>We subtract the true answer from our guess to find the difference.</p><p>We square that difference for two reasons: First, it turns any negative numbers into positive numbers so errors in opposite directions don’t accidentally cancel each other out. Second, it exponentially punishes massive errors while being forgiving of tiny ones.</p><h4>The Code</h4><p>Using a list of target answers (ys) and a list of our network&#39;s final predictions (ypred), we just translate the mathematical equation directly into Python.</p><pre>def calculate_mse(predictions, targets):<br>    return sum((p - t)**2 for p, t in zip(predictions, targets))<br><br># Conceptual Test:<br># The recipe wanted sweetness 10. We guessed 4. Error is 6. Squared error is 36.<br>test_loss = calculate_mse(predictions=[4.0], targets=[10.0])<br>print(test_loss) # Outputs: 36.0</pre><h4>The Plain English</h4><p>Back on the factory floor, the fully baked cake has finally reached the end of the assembly line.</p><blockquote>The Loss Function is the Head Chef performing quality control.</blockquote><p>The chef takes a bite of the final cake and compares it to the master recipe. If the recipe called for a sweetness level of 10, but the cake is only a 4, the base error is 6. Squaring that error (6² = 36) acts as a massive alarm bell for the factory. If the cake was a 9, the error is 1, and the squared error is still just 1.</p><p>Squaring the number is the chef’s way of telling the assembly line: “Tiny variations in the mixture are fine, but completely ruined cakes require immediate, drastic changes to your ingredient dials.”</p><p>Once this alarm bell rings, the chef walks backward down the line (backpropagation) to tell every single chef exactly how to adjust their specific dials for the next cake.</p><figure><img alt="A U-shaped parabola graph illustrating how the Mean Squared Error (MSE) function exponentially punishes large prediction errors." src="https://cdn-images-1.medium.com/max/1024/1*ijBQxjaKKTwecCPYQajPqw.png" /><figcaption>Mean Squared Error</figcaption></figure><h3>The Build</h3><p>Now that I have a great understanding of the Neural Network (NN) basics conceptually, I will write the Object-Oriented code using our custom Value engine from Part 1 to reproduce a minimal MLP.</p><p>Let’s start with the <strong>Neuron:</strong></p><pre>import random<br><br>class Neuron:<br>    def __init__(self, nin): # nin = how many inputs in neuron<br>        self.w = [Value(random.uniform(-1, 1)) for _ in range(nin)]<br>        self.b = Value(random.uniform(-1, 1))<br>    <br>      def __call__(self, x):<br>        act = sum((wi*xi for wi,xi in zip(self.w, x)), self.b)<br>        out = act.tanh()<br>        return out<br>    <br>      def parameters(self):<br>        return self.w + [self.b]</pre><ul><li><strong>__init__</strong>: We pass it nin (how many inputs/ingredients it has). We set a random value for the weight of each input and a random bias. Why random? Because we actually don’t know the recipe yet. It’s trial and error.</li><li><strong>__call__</strong>: We implement the linear equation of the neuron and apply the activation function.</li><li><strong>parameters</strong>: We define this method to track the params. We need them because they are the only things we can change to make our network more accurate.</li></ul><p>Now we move to the <strong>Layer</strong>:</p><pre>class Layer:<br>  def __init__(self, nin, nout):<br>    self.neurons = [Neuron(nin) for _ in range(nout)]<br><br>  def __call__(self, x):<br>    outs = [n(x) for n in self.neurons]<br>    return outs[0] if len(outs) == 1 else outs<br><br>  def parameters(self):<br>    return [p for neuron in self.neurons for p in neuron.parameters()]</pre><ul><li><strong>__init__</strong>: We initialize the Layer by creating as many Neurons as the nout input specifies.</li><li><strong>__call__</strong>: We execute each neuron’s function using the exact same input.</li></ul><p>Finally, the <strong>MLP</strong>:</p><pre>class MLP:<br>  def __init__(self, nin, nouts):<br>    sz = [nin] + nouts<br>    self.layers = [Layer(sz[i], sz[i+1]) for i in range(len(nouts))]<br><br>  def __call__(self, x):<br>    for layer in self.layers:<br>      x = layer(x)<br>    return x<br><br>  def parameters(self):<br>    return [p for layer in self.layers for p in layer.parameters()]</pre><h3>Sandbox: Writing a Gradient Descent Training Loop from Scratch</h3><p><strong>The Math</strong></p><p>The training loop is an optimization algorithm called <strong>Gradient Descent</strong>. We calculate the slopes, and then we update every single weight and bias in the network using this core equation:</p><figure><img alt="Mathematical formula for gradient descent parameter update, showing a weight updated by subtracting the learning rate multiplied by the gradient." src="https://cdn-images-1.medium.com/max/1024/1*dI_ZTBbIwA4BEMqY0E6LQA.png" /></figure><ul><li>p: The current parameter (the weight or bias).</li><li>α: The learning rate (a small multiplier that controls how big of a step we take).</li><li>∇p: The gradient (the slope telling us which way increases the error).</li></ul><p>By subtracting the gradient, we step in the <em>opposite</em> direction of the error, walking downhill. We repeat this equation in a loop until the Loss L approaches zero.</p><h4><strong>The Code</strong></h4><p>We turn the factory on using a dummy dataset of raw ingredients (xs) and target sweetness levels (ys). We run the process 20 times.</p><pre>xs = [<br>  [2.0, 3.0, -1.0],<br>  [3.0, -1.0, 0.5],<br>  [0.5, 1.0, 1.0],<br>  [1.0, 1.0, -1.0],<br>]<br>ys = [1.0, -1.0, -1.0, 1.0] # desired targets<br><br># Initialize the factory: 3 inputs, two layers of 4 neurons, 1 output<br>n = MLP(3, [4, 4, 1]) <br><br>for k in range(20):<br>  <br>  ypred = [n(x) for x in xs]<br>  <br>  loss = sum((yout - ygt)**2 for ygt, yout in zip(ys, ypred))<br>  <br>  for p in n.parameters():<br>    p.grad = 0.0<br>    <br>  loss.backward()<br>  <br>  for p in n.parameters():<br>    p.data += -0.05 * p.grad<br>    <br>  print(f&quot;Step {k}: Loss = {loss.data}&quot;)</pre><figure><img alt="Side-by-side charts showing gradient descent optimization: a 2D line graph with data points and a 3D bowl-shaped surface plot representing the loss landscape." src="https://cdn-images-1.medium.com/max/1024/1*KiE61rOO9HNy8Wzz8vrWog.png" /><figcaption>Gradient Descent Visualization</figcaption></figure><h4><strong>The Plain English</strong></h4><p>Because we initialized all our chefs with random weights and biases, the network’s first cakes will be <strong>terrible.</strong> This loop helps us running automated trial and error to perfect the recipe.</p><p>So, what happens in those five steps?</p><ol><li><strong>Forward Pass:</strong> We push the raw ingredients through the factory so the chefs can make their initial, random cakes.</li><li><strong>Calculate Loss:</strong> The Head Chef tastes all four cakes and calculates the error to see how far off they are from the target.</li><li><strong>Zero Grad:</strong> We clear out the old feedback. If we do not reset the feedback to zero before the next batch, we will accidentally add today’s adjustments on top of yesterday’s, ruining the math.</li><li><strong>Backward Pass:</strong> The Head Chef walks backward down the line, telling every single chef exactly how their specific dials contributed to the bad cake.</li><li><strong>Update Weights:</strong> Every chef physically turns their ingredient dials a tiny fraction of a notch (eg -0.05) in the correct direction to make the next cake better.</li></ol><p>We run this shift 20 times until the recipe is perfect.</p><h3>Filling in the Holes: A QECL Reflection</h3><p>I went to the foundational literature and read the <a href="https://aikosh.indiaai.gov.in/static/Deep+Learning+Ian+Goodfellow.pdf">MIT Press <em>Deep Learning</em> textbook</a>. Specifically, I read two parts of the book:</p><ol><li>6.1 Example: Learning XOR (pages: 171–177), and</li><li>6.2.2 Output Units (pages: 181–191)</li></ol><p><strong>1) Question / Core Problem<br></strong>Why do we absolutely need this activation function, and why did we specifically choose Mean Squared Error (MSE) as our loss function instead of something else?</p><p><strong>2) Evidence / Approach<br></strong>Translating that dense jargon through the Feynman method gave me exactly what I needed. The book’s <strong>XOR example</strong> proved that without an activation function, the model is practically useless for complex tasks. Without a non-linear “squish,” no matter how many layers you stack, the math collapses into a single, rigid straight line.</p><p>As for the loss function, the literature confirmed that MSE is ideal for raw numerical output. Because it squares the difference, it naturally makes tiny, acceptable errors shrink away while massively punishing the big errors, all without needing complex filtering.</p><p><strong>3) Conclusion / Critique<br></strong>My aftertaste is that the book uses highly sophisticated, dense mathematical language that feels incredibly overwhelming for the target audience which is students or software engineers who trying to learn ML.</p><p><strong>4) Lesson<br></strong>The biggest takeaway is that the architecture is completely modular, and you must know where to use each specific output unit. I need to know exactly what is the right activation function with the right loss function for the specific problem I am trying to solve.</p><p>For example, I should use a sigmoid function if I need a binary output.</p><h3>What Comes Next</h3><p>Now that our mathematical factory is fully operational, we have a complete, working neural network. We have seen exactly how it runs a forward pass, measures the error, and walks backward down the assembly line to adjust the weights.</p><p>However, our factory has only been mixing raw numbers to guess a single continuous target. In the next part, we graduate from scalar operations to building our first generative AI model.</p><p>Stay tuned!</p><h3>Resources &amp; Further Reading</h3><ul><li><strong>Textbook:</strong> <em>Deep Learning</em> (MIT Press) by Ian Goodfellow, Yoshua Bengio, and Aaron Courville.</li><li>3Blue1Brown’s “<a href="https://www.youtube.com/watch?v=aircAruvnKk">But what is a Neural Network?</a>” video</li><li>3Blue1Brown’s “<a href="https://www.youtube.com/watch?v=IHZwWFHWa-w">Gradient descent, how neural networks learn | Deep Learning Chapter 2</a>” video</li><li><a href="http://neuralnetworksanddeeplearning.com/">Neural Networks and Deep Learning</a> by Michael Nielsen</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ed125f758ed" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/build-neural-network-from-scratch-python-3ed125f758ed">Deep AI Learning Part 2: Building Neurons, Layers, and the Training Loop</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deep AI Learning Part 1: Building an Autograd Engine]]></title>
            <link>https://itnext.io/deep-ai-learning-part-1-building-an-autograd-engine-ab443deeaf4d?source=rss-f1558d10c1f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab443deeaf4d</guid>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <dc:creator><![CDATA[Vassiliki Dalakiari]]></dc:creator>
            <pubDate>Wed, 30 Sep 2026 22:06:12 GMT</pubDate>
            <atom:updated>2026-09-30T22:06:12.721Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to deeply understand neural networks by building a functional autograd engine and manually calculating backpropagation using the First-Principles Methodology.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OR6ZOQfYJqWRUSkWAkyvsQ.png" /></figure><p>In my last article, I outlined my <a href="https://medium.com/@vadal_/the-first-principles-methodology-a-code-first-approach-to-learning-704653a1032a">First-Principles Methodology</a> for tackling complex concepts, which focuses on stripping away the abstractions and building from first principles. Today, we are putting that philosophy to its first real, practical test.</p><p>Everyone talks about <strong>Neural Networks</strong> like they are magic black boxes. You feed data in, something mysterious happens, and a smart answer pops out. But after diving into the first part of my <strong>Deep AI Learning</strong> journey, I realized it is mostly calculus and some very clever code.</p><h3><strong>What is a Neural Network (And How Does It Learn?)</strong></h3><p>A neural network is a massive math equation with millions of adjustable dials (called weights).</p><p>When you first build a network, these dials are set randomly, meaning its first guesses are completely wrong. The network actually “learns” in three simple steps:</p><ol><li><strong>Forward Pass:</strong> It pushes data through the current dial settings to make a prediction (a guess)</li><li><strong>Loss:</strong> It compares its guess to the correct answer to see how wrong it was (the error).</li><li><strong>Backward Pass: </strong>It calculates exactly which dials to turn, and by how much, to make a better guess next time. This process is called the <strong>backpropagation</strong>.</li></ol><p>That third step is the secret to everything. To figure out how to turn millions of dials simultaneously to shrink the error, you have to measure the “slope” of that error. They learn through calculus.</p><p><strong>But doing calculus by hand for millions of math operations is impossible.</strong> We need a system that automatically remembers every math step the network takes during its guess, so it can automatically calculate those slopes later. This is called an <strong>Autograd</strong> (Automatic Gradient) engine.</p><p>So my focus in this part is building this Autograd engine, programming backpropagation, and combining these two to train a Neural Network in plain Python code.</p><p>Applying my First-Principles Methodology, this is the curriculum for today’s build:</p><ul><li><strong>Understand what Autograd is:</strong> Using <strong>Feynman Translation</strong>, I will strip away the jargon to deeply understand what Autograd actually does.</li><li><strong>Build:</strong> Writing the custom Python wrapper (the Value object) to record mathematical operations.</li><li><strong>Sandbox:</strong> Using the <a href="https://github.com/vadal/first-principles-methodology-templates/blob/main/templates/Triad_Concept_Node.md">Triad Concept Node</a> to break down derivatives and manually calculate the slope.</li><li><strong>Build:</strong> Connecting the math and the code to automatically pass error signals backward.</li><li><strong>Read &amp; Reflect: </strong>Watching a foundational calculus video series through the <a href="https://github.com/vadal/first-principles-methodology-templates/blob/main/templates/Q-E-C-L_Paper_Node.md">Q-E-C-L Node</a> of the methodology to fill in the conceptual holes and expose flaws in my early assumptions.</li></ul><p>As a side note on the methodology: writing this article itself serves as my articulation practice. ;)</p><h3>Understand what Autograd is</h3><p>It is important to understand exactly what Autograd is to be able to code it. I will use the Feynman Translation to simplify it:</p><blockquote>Lets say, we have a smart tracking system. As parts move forward through the factory (the forward pass), this system automatically takes notes on exactly which machines touched the toy and how they combined the pieces (e.g., “Machine A added legs, Machine B glued the head”). It builds a map of the assembly line while it runs.</blockquote><blockquote>Because we kept that exact map, when the final toy fails Quality Control at the end of the line, the manager can walk completely backward down the exact same assembly path. They can tell Machine B to use less glue, and Machine B passes the message backward to Machine A to attach the legs looser. This backward flow of instructions is the Chain Rule in action.</blockquote><p>Now I feel that I understand how this process works and why it is so important I can start coding the machine.</p><h3>Building the Autograd Engine</h3><p>To actually build this, I need to figure out how to redefine basic mathematical actions in plain Python so they could remember their history. In standard Python, if you add a = 2 and b = 3, the computer just spits out 5 and instantly forgets how it got there.</p><p>To fix this, I created a custom wrapper (a Value object) around the numbers. This is a look at the core engine and how it handles simple addition:</p><pre>class Value:<br>  def __init__(self, data, _children=(), _op=&quot;&quot;, label=&quot;&quot;):<br>    self.data = data<br>    self.grad = 0.0<br>    self._backward = lambda: None<br>    self._prev = set(_children)<br>    self._op = _op<br>    self.label = label<br><br>  def __add__(self, other):<br>    other = other if isinstance(other, Value) else Value(other)<br>    out = Value(self.data + other.data, (self, other), &quot;+&quot;)<br><br>    def _backward():<br>      self.grad += 1.0 * out.grad<br>      other.grad += 1.0 * out.grad<br>    <br>    out._backward = _backward<br>    return out<br>  <br>  def __radd__(self, other): # other + self<br>        return self + other</pre><p>If you look closely, you can see the factory analogy in action. self.data holds the actual number. self._prev is the tracking system building the map of the assembly line. And the _backward function is the manager passing the instructions in reverse to calculate the gradient (the slope) using the chain rule.</p><p>I won’t paste the entire script here (you can check out <a href="https://github.com/karpathy/micrograd">Andrej Karpathy’s original Micrograd repository</a> for the full source code) but once I understood how this single class worked, the rest was just scaling it up to handle more complex math.</p><h3>Sandbox 1: Unpacking the Math</h3><p>If you look closely at the code snippet above, you will notice a variable called self.grad. That stands for gradient, or derivative. While the code tracks the <em>operations</em>, it is the calculus that actually calculates the numbers stored in that variable.</p><p>According to the Wikipedia:</p><blockquote>In mathematics, the <strong>derivative</strong> is a fundamental tool that quantifies the sensitivity to change of a function’s output with respect to its input.</blockquote><p>Ok. I used the Triad Concept Node template to understand and document what this means and how it is calculated.</p><ol><li><strong>The Math</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/138/0*0S29kYrEL2c70x9y" /></figure><p><em>Variables:</em></p><ul><li>f(x): The current position/value.</li><li>h: A ridiculously tiny step forward.</li></ul><p><strong>2. The code</strong></p><pre>def f(x): return x**2<br><br>x = 3.0<br>h = 0.0001 # Our tiny step (the limit approaching zero)<br><br># The derivative (slope) at x=3<br>derivative = (f(x + h) - f(x)) / h <br>print(derivative) # Outputs roughly 6.0</pre><p><strong>3. The Plain English (Feynman Translation)</strong></p><p>Let’s say I am climbing a mountain in the fog. I can’t see the whole mountain, but I can feel the ground right under my boots. The derivative is the steepness of the ground at the exact spot I am standing.</p><p>To calculate it, I will check my current elevation on my GPS, I’ll take one more step forward (that step is h), and check back my new elevation. How much did my altitude change based on that one tiny step? That difference is the derivative.</p><blockquote>In a neural network, that ‘elevation’ is our error rate. We use the derivative to figure out which direction is downhill so we can take a step toward zero error.</blockquote><p>When I first started brushing up on the math, I hit a frustrating roadblock. I watched a video that talked about ‘derivatives,’ ‘slopes,’ and ‘steepness’ as if they were entirely different things. It felt like I was being asked to learn three separate languages at once.</p><p>My real ‘aha!’ moment came when I realized <strong>they are all just different lenses for the exact same concept</strong>.</p><ul><li>The ‘slope’ is the geometric visual on a graph,</li><li>the ‘steepness’ is the physical feeling on our mountain, and</li><li>the ‘derivative’ is simply the mathematical formula we use to calculate it.</li></ul><p>Once I stripped away the bloated terminology, the math became an accessible tool rather than an abstract hurdle.</p><p>And because I am a visual learner too:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tg7fbcTo1NqLaW4F_65tcQ.png" /><figcaption>An AI generated visualization of the metaphor (I hope you like it)</figcaption></figure><h3>Sandbox 2: Practicing Calculus</h3><p>To familiarize myself with calculating the slope, I practiced with a hypothetical scenario.</p><p><strong>The forward pass</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d3ANATYw95kWsS5LuVh24w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aioUk25lWGXE57iA_-zmGw.png" /></figure><h4><strong>The Math (Manual Limit Proofs)</strong></h4><p>To find the gradient of the loss (L) with respect to every node, we use the limit definition of a derivative to find the local slope, and the Chain Rule to multiply it by the incoming global slope.</p><p><strong>Derivative of L with respect to L (Base Case):</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WLvt7ONLfKtANhcp8mFXlw.png" /></figure><p><strong>Derivative of L with respect to f:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FdY0uOS3VoKxavf_hst3pw.png" /></figure><p><strong>Derivative of L with respect to d:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JmDLKUnQxA0ZQ426kojzLg.png" /></figure><p><strong>Derivative of L with respect to e (Chain Rule applied):</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HeyXKsAwq3N0AJIzeyexbQ.png" /></figure><p><strong>Derivative of L with respect to a (Chain Rule applied twice):</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*liC6HJ62FOq9fqd2Pdp8Kg.png" /></figure><p><strong>Derivative of L with respect to b (Chain Rule applied twice):</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9gz21NlPJB7AF8wz61i9DQ.png" /></figure><h4>Some things I noticed</h4><p>When passing error signals backward through the factory:</p><ul><li><strong>Addition is a Router:</strong> The local derivative is exactly 1. It acts as a megaphone, passing the exact same error signal equally to all machines that fed into it.</li><li><strong>Multiplication is a Swapper:</strong> The local derivative is exactly the other input’s value. Machine A’s error signal is scaled by whatever Machine B produced, and vice versa.</li></ul><h3>Building the backpropagation with code</h3><p>After calculating the slope manually for each node, I felt confident enough to write the code to calculate it at scale.</p><p>To do this, we need to order the nodes so that a parent node only calculates its gradient <em>after</em> all of its children have calculated theirs. In computer science, this is called a topological sort.</p><p>This is how that final piece of the engine looks:</p><pre>class Value:<br>...<br>  def backward(self):<br>    topo = []<br>    visited = set()<br><br>    def build_topo(v):<br>      if v not in visited:<br>        visited.add(v)<br>        for child in v._prev:<br>          build_topo(child)<br>        topo.append(v)<br><br>    build_topo(self)<br><br>    self.grad = 1<br>    for node in reversed(topo):<br>      node._backward()</pre><h3>Filling in the Holes: A QECL Reflection</h3><p>Writing the code is one thing, but to truly understand what the engine is physically doing, I ran <a href="https://www.youtube.com/playlist?list=PLZHQObOWTQDMsr9K-rj53DwVRMYO3t5Yr">3Blue1Brown’s <em>Essence of Calculus</em></a> series through the Q-E-C-L Node of the framework. Visualizing the geometry behind the formulas filled in the conceptual holes the code left behind.</p><p><strong>1) Question / Core Problem<br></strong><em>What specific bottleneck or failure is this trying to solve?</em></p><p>The traditional approach I followed to calculus relies heavily on memorization. This series attempts to explain calculus in a way that allows the student to reproduce any part of it from scratch without just memorizing abstract formulas.</p><p><strong>2) Evidence / Approach<br></strong><em>How do they solve it mathematically and architecturally?</em></p><p>It breaks abstract equations into physical, geometric sums of smaller problems. <br>For example, the standard approach is memorizing that the derivative of x² is 2x. Instead, the videos suggest that you picture a physical square where each side is length x, making its area x². If you increase the sides by a microscopic step, the square grows. The new area added is two thin strips added to the top and the right side. The area of those two expanding strips is exactly 2x.</p><p><strong>3) Conclusion / Critique<br></strong><em>What are the limitations or flaws?</em></p><p>First, the standard textbook phrase “instantaneous rate of change” is technically a paradox. You cannot have change in a frozen instant, as dividing by a zero step throws a mathematical error. That is why our Python code must use a microscopic step (h) to measure the ratio of change instead. <br>Second, geometric visual intuition has a scaling limit. When we build neural networks with millions of parameters, human visualization is impossible. At that point, we must trust the algebraic rules established in these lower dimensions.</p><p><strong>4) Lesson<br></strong><em>What is the core takeaway?</em></p><p>I love the mindset behind this. It simplifies the math down to its roots.</p><p>It also exposed a misunderstanding in my earlier thinking. In my original hiker metaphor, I said the derivative was just the difference in altitude. But the videos made me realize my explanation was oversimplified,<strong> as I left out the division! </strong>The derivative is actually the ratio of that altitude change divided by the tiny step.</p><p>Another big takeaway for me was the Chain Rule, which actually made perfect sense <em>after</em> I wrote the code, as it filled in the holes in my understanding perfectly.</p><h3>What Comes Next</h3><p>Building Micrograd from scratch proved that the “magic” of AI is just a combination of tracked operations and basic calculus.</p><p>Now that I have a working Autograd engine and a solid grasp on backpropagation, the foundation is set. In my next article, I will use this exact engine to build out the architecture of a simple neural network (Neurons and Layers) and write a training loop to watch it actually learn.</p><h3>Resources &amp; Further Reading</h3><ol><li><a href="https://github.com/karpathy/micrograd">Andrej Karpathy’s Micrograd</a>: The full, original source code that inspired this build can be found in the Micrograd GitHub repository.</li><li>The incredible <a href="https://www.youtube.com/watch?v=VMj-3S1tku0">video lecture by Andrej Karpathy</a> that serves as the primary foundation for this part of my learning.</li><li>Derivative Definition: The formal Wikipedia entry for <a href="https://en.wikipedia.org/wiki/Derivative">Derivative</a> referenced in the math sandbox.</li><li><a href="https://medium.com/@vadal_/the-first-principles-methodology-a-code-first-approach-to-learning-704653a1032a">My Previous Article</a>, detailing the First-Principles Methodology used throughout this series.</li><li><a href="https://www.youtube.com/playlist?list=PLZHQObOWTQDMsr9K-rj53DwVRMYO3t5Yr">3Blue1Brown’s <em>Essence of Calculus</em></a> video series. A-M-A-Z-I-N-G!</li><li>3Blue1Brown’s “<a href="https://www.youtube.com/watch?v=Ilg3gGewQ5U">Backpropagation, intuitively | Deep Learning Chapter 3</a>” video</li><li>3Blue1Brown’s “<a href="https://www.youtube.com/watch?v=tIeHLnjs5U8">Backpropagation calculus | Deep Learning Chapter 4</a>” video</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab443deeaf4d" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/deep-ai-learning-part-1-building-an-autograd-engine-ab443deeaf4d">Deep AI Learning Part 1: Building an Autograd Engine</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The First-Principles Methodology: A Code-First Approach to Learning]]></title>
            <link>https://itnext.io/the-first-principles-methodology-a-code-first-approach-to-learning-704653a1032a?source=rss-f1558d10c1f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/704653a1032a</guid>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Vassiliki Dalakiari]]></dc:creator>
            <pubDate>Thu, 24 Sep 2026 11:12:08 GMT</pubDate>
            <atom:updated>2026-09-28T22:51:07.087Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>A framework for engineers who want to master complex systems without getting lost in endless documentation.</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BNGU-XAlrvQnxvPAlkPVqg.png" /></figure><p>I am the kind of person who needs to understand something down to its root to actually consider that I know it. But I am also the kind of person who gets incredibly bored reading pure theory. I prefer to try things first, figure out how they work, and <em>then</em> look at the theory behind them.</p><p>Because of this, I adapted David Kolb’s learning model (which is basically a proven cycle of active experimentation and reflection) to create a methodology for learning deeply technical concepts, like Neural Networks.</p><blockquote>I call it the First-Principles Methodology.</blockquote><h3>The Framework</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8SYgJ5tpm1P8iQ0pT4oF5g.png" /><figcaption>The First-Principles Methodology</figcaption></figure><h4>Pillar 1: Build</h4><p>Because I get bored with theory, I always start by building. For every new concept, I construct the core project entirely from scratch, line by line.</p><ul><li><strong>The Constraint:</strong> No high-level abstractions or “black box” libraries allowed. If I am learning backpropagation, I must build the computational graph and the individual nodes myself.</li><li><strong>The Output:</strong> A working, raw implementation (like building a custom neural network engine) that proves I understand exactly how the system passes data and gradients under the hood.</li></ul><h4>Pillar 2: Sandbox</h4><p>While I’m in the Build Phase, I inevitably run into math concepts I need to sharpen (you see, high school calculus was a loooooot of years back).</p><p>When I hit this wall, I pause the build and start refreshing my math in a “sandbox.” This helps me deeply understand what is actually happening behind a system or a library’s API so I can reproduce it anywhere.</p><p>What do I do here?</p><ul><li><strong>Terms &amp; Concept Understanding:</strong> Figuring out what it is actually about and how I can solve it.</li><li><strong>Boundary Testing:</strong> Pushing the limits of the logic or math to see exactly where and why it breaks.</li><li><strong>Industry Verification:</strong> Comparing my from-scratch build against production-grade tools (like PyTorch) to ensure my output perfectly matches reality.</li></ul><h4>Pillar 3: Literature Read</h4><p>After, and <em>only</em> after, finishing the Build Phase, I move on to the literature.</p><p>During this phase, I read the original papers, courses, or documentation that introduced the concept to fill in the gaps. I do this <em>after</em> building because I don’t like reading long theoretical texts for things I haven’t touched yet. I need a basic understanding first to keep my focus.</p><p>The papers actually make sense in this phase because I just spent days struggling with the exact problems they solve.</p><h4>Pillar 4: Habit</h4><p>This is the most interesting phase. Our brains forget things that consume energy if we don’t use them frequently, so it’s important to keep the saw sharp. The idea here is to lock in what you’ve learned by reproducing the system without help and being able to explain it to others flawlessly.</p><h3>How it works in practice</h3><p>Say I want to understand how video game physics work under the hood.</p><p><strong>I know nothing about it</strong>, so I find a YouTube tutorial: <em>“Code a 2D Physics Engine in Python from Scratch.”</em></p><blockquote>This is a fictional scenario!</blockquote><p><strong>1. Build</strong></p><p>I start watching the video, where the instructor explaining the goal and gives step by step instructions on how to <strong>build</strong> the system. I build in parallel.</p><ul><li><strong>The Action:</strong> I have my IDE open on one screen and the video on the other. When he starts building the gravity loop, I pause the video. I try to write it myself first based on his initial hint. If I get stuck, I watch him write a line, pause, and then I write the line.</li><li><strong>The Constraint:</strong> I don’t cheat here by copy-pasting or downloading his finished GitHub repo. I must physically type and construct the architecture alongside the instructor.</li><li><strong>The Result:</strong> Eventually, the ball hits the floor, and the instructor writes a formula to calculate the bounce angle using Sine, Cosine, and Vector Dot Products. I have absolutely no idea what just happened. I have successfully created cognitive friction.</li></ul><h4>2. The Math Sandbox</h4><p>I am stuck because the code relies on Trigonometry and Vectors, and high school math is rusty.</p><ul><li><strong>The Action:</strong> I pause the video. I step entirely away from the main build and open a blank notebook (my Sandbox). I study the terminology of Vector Dot Products. I write down how it works. I document this in my “Triad Concept Node”:<br> 1. <strong>The Math:</strong> I write down the raw trigonometric formula.<br> 2. <strong>The Code:</strong> I write a tiny, isolated 3-line Python script to calculate just the bounce angle of two numbers.<br> 3. <strong>The Feynman Translation:</strong> I force myself to write a plain-English analogy. <em>(e.g., “A vector dot product is just a flashlight pointing down at a stick. It calculates exactly how much of a shadow the stick casts on the ground.”)</em></li><li><strong>Verification:</strong> Before I go back to the video, I plug my numbers into a standard online physics calculator. If my custom math doesn’t match the actual laws of physics perfectly, I am not allowed to leave the Sandbox.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RXCnxBrmWzdU1obJjzbPnw.png" /><figcaption>The Triad Concept Node for Vector Dot Product</figcaption></figure><p><strong>3. Hunt &amp; Extract (The Literature)</strong></p><p>Now that I have successfully built the gravity loop in parallel and survived the Trigonometry Sandbox, I actually know what a vector is.</p><p><em>Now</em> I go read the literature.</p><p>I pull up formal game-dev documentation or physics articles on “Elastic Collisions.” In this phase, the articles actually make sense because I spent two hours struggling with a digital ball falling endlessly through a digital floor.</p><p>I keep notes on:</p><ul><li><strong>Core Problem:</strong> What mathematical limit was stopping my ball from bouncing correctly?</li><li><strong>Approach:</strong> How do real game engines solve this architecturally?</li><li><strong>Critique:</strong> Under what conditions will this formula break? (e.g., What happens if two balls hit each other at the exact same time?)</li><li><strong>Lesson: </strong>What did I learn during this process that build and sandbox didn’t offer?</li></ul><p><strong>4. Lock in the Mastery (The Habit)</strong></p><p>I have built it, tested the math, and read the theory. Now I have to make sure my brain doesn’t delete it to save energy.</p><ul><li><strong>Action 1:</strong> I close the Python file I spent three hours building alongside the video. I open a brand new, blank file. I rebuild the entire bouncing ball engine from memory to prove it wasn’t a fluke.</li><li><strong>Action 2:</strong> I write a 200-word explanation of vector math to give it to a non-technical friend.</li><li><strong>Action 3:</strong> I open the voice memo app on my phone. I record myself explaining the mechanics out loud for 3 minutes without looking at my notes. Then, I force myself to listen to it. <br>If I stumble or sound confused, I haven’t mastered it yet.</li></ul><h3><strong>The Templates (Open Source)</strong></h3><p>If you want to implement this immediately, I have open-sourced the exact Markdown files I use to track my learning.</p><p>You can grab them for your own Obsidian or Notion workspace <a href="https://github.com/vadal/first-principles-methodology-templates">here</a>.</p><h3>Conclusion</h3><p>This methodology isn’t fast, and it isn’t easy. It is intentionally designed to be uncomfortable. But it guarantees one thing: when you finally look at a complex system and say, “I know how this works,” you will be speaking from the ground truth.</p><p>Next time you want to learn something new, close the book, open a blank file, and start building.</p><blockquote><strong>P.S.</strong> I am releasing this framework under a Creative Commons Attribution license (CC BY 4.0). You are completely free to use it, adapt it, and share it with your own teams or study groups. <br>All I ask is that you give me credit as the original creator and link back to this post.</blockquote><p><strong>How are you planning to use it? <br></strong>Let me know what course or concept you are tackling next in the comments, and once you survive the build, report back with your results!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=704653a1032a" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/the-first-principles-methodology-a-code-first-approach-to-learning-704653a1032a">The First-Principles Methodology: A Code-First Approach to Learning</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Connected Prefect Cloud to GCP Cloud Run Jobs Without a Paid Subscription]]></title>
            <link>https://itnext.io/how-i-connected-prefect-cloud-to-gcp-cloud-run-jobs-without-a-paid-subscription-a448f4cd46f1?source=rss-f1558d10c1f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/a448f4cd46f1</guid>
            <category><![CDATA[prefect-cloud]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[scheduled-tasks]]></category>
            <dc:creator><![CDATA[Vassiliki Dalakiari]]></dc:creator>
            <pubDate>Tue, 18 Aug 2026 20:19:27 GMT</pubDate>
            <atom:updated>2026-08-18T20:19:27.022Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UGx4JakN_JyWmg-66vsB9Q.png" /></figure><p>In this post, I explain how I use Prefect Cloud to monitor <a href="https://www.moviegroovy.gr/">MovieGroovy.gr</a>’s data-ingestion jobs while keeping the scheduling and execution inside Google Cloud.</p><p>Prefect Cloud gives me a dashboard where I can see when each flow ran, inspect its logs, and identify failed jobs. I use the free Prefect Cloud account for this, without using Prefect Serverless compute or running a Prefect worker.</p><blockquote>I made this decision because I did not want to pay €100 per month to monitor a small number of data-ingestion jobs, especially while MovieGroovy is not generating revenue yet.</blockquote><p>The infrastructure is divided between three services:</p><ul><li><strong>Cloud Scheduler</strong> decides when each job should run.</li><li><strong>Cloud Run Jobs</strong> provides the compute and executes the container.</li><li><strong>Prefect Cloud</strong> records the flow run, status, and logs.</li></ul><p>This allows me to use Prefect as the monitoring layer for infrastructure that already runs on GCP.</p><figure><img alt="How Cloud Scheduler, Cloud Run Jobs, Secret Manager, and Prefect Cloud work together." src="https://cdn-images-1.medium.com/max/1024/1*Sh_rnVfDp8sj4ulr3y5Lsw.png" /><figcaption>Scheduled Execution: <em>How Cloud Scheduler, Cloud Run Jobs, Secret Manager, and Prefect Cloud work together.</em></figcaption></figure><h3>Run the Prefect Flow Directly</h3><p>A Prefect worker is useful when Prefect is responsible for scheduling work and submitting it to the execution infrastructure.</p><blockquote>In my setup, Cloud Scheduler already handles the timing, so the Cloud Run container can execute the flow directly.</blockquote><p>I created a small Python entry point that imports and runs my asynchronous Prefect flow:</p><pre>import asyncio<br><br>from jobs.discovery.flow import (<br>    discovery_flow,<br>)<br><br>if __name__ == &quot;__main__&quot;:<br>    asyncio.run(discovery_flow())</pre><p>The imported function is a standard Prefect flow:</p><pre>from prefect import flow<br><br>@flow<br>async def discovery_flow():<br>    # Run the data-ingestion workflow<br>    ...</pre><p>When Cloud Run starts the container, Python runs the flow and exits when the work is complete. There is no process waiting for Prefect to submit work.</p><h3>Connect the Container to Prefect Cloud</h3><p>The container needs two Prefect settings:</p><ul><li>PREFECT_API_URL, which identifies the Prefect Cloud workspace;</li><li>PREFECT_API_KEY, which authenticates the connection.</li></ul><p>The workspace URL follows this format:</p><pre>https://api.prefect.cloud/api/accounts/&lt;ACCOUNT_ID&gt;/workspaces/&lt;WORKSPACE_ID&gt;</pre><blockquote>You can find the account and workspace IDs in your Prefect Cloud workspace URL.</blockquote><p>The API key and the URL are stored in Google Secret Manager and exposed to the container as PREFECT_API_KEY and PREFECT_API_URL.</p><blockquote><strong>With these settings available when the Python process starts, Prefect sends the flow state and logs to the remote workspace.</strong></blockquote><figure><img alt="MovieGroovy’s Cloud Run executions appearing as completed flow runs in Prefect Cloud." src="https://cdn-images-1.medium.com/max/1024/1*nCtCTDs7Jkd2BzMauEcLYA.png" /><figcaption>MovieGroovy’s Cloud Run executions appearing as completed flow runs in Prefect Cloud</figcaption></figure><h3>Deploy the Cloud Run Job</h3><p>The deployment is handled through my cloudbuild.yaml file.</p><figure><img alt="How cloudbuild.yaml builds the container image and deploys the Cloud Run Job." src="https://cdn-images-1.medium.com/max/1024/1*EPXxfm7i_CSYyqxn2oDAlA.png" /><figcaption>Deployment: <em>How </em><em>cloudbuild.yaml builds the container image and deploys the Cloud Run Job.</em></figcaption></figure><p>This is the relevant command:</p><pre>gcloud run jobs deploy discovery \<br>  --image=&quot;$$IMAGE&quot; \<br>  --region=&quot;${_REGION}&quot; \<br>  --command=&quot;python&quot; \<br>  --args=&quot;-m,jobs.prefect_run_discovery&quot; \<br>  --memory=&quot;4Gi&quot; \<br>  --cpu=&quot;2&quot; \<br>  --set-secrets=&quot;PREFECT_API_URL=PREFECT_API_URL:latest,PREFECT_API_KEY=PREFECT_API_KEY:latest&quot;</pre><p>The --command and --args options tell Cloud Run to execute:</p><pre>python -m jobs.prefect_run_discovery</pre><p>The Cloud Run service account needs the roles/secretmanager.secretAccessor role to access the Prefect secrets.</p><h3>Trigger the Job With Cloud Scheduler</h3><p>After deploying the Cloud Run Job, I created a Cloud Scheduler job that calls the Cloud Run Jobs API according to the cron schedule I need.</p><p>The endpoint follows this format:</p><pre>https://&lt;REGION&gt;-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/&lt;PROJECT_ID&gt;/jobs/discovery:run</pre><p>The Scheduler request uses the POST method and authenticates with a Google Cloud service account that has permission to run the job.</p><p>An equivalent command looks like this:</p><pre>gcloud scheduler jobs create http incremental-discovery-schedule \<br>  --location=&quot;${_REGION}&quot; \<br>  --schedule=&quot;0 4 * * *&quot; \<br>  --time-zone=&quot;Europe/Athens&quot; \<br>  --uri=&quot;https://${_REGION}-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${PROJECT_ID}/jobs/discovery:run&quot; \<br>  --http-method=&quot;POST&quot; \<br>  --oauth-service-account-email=&quot;&lt;YOUR_SERVICE_ACCOUNT_EMAIL&gt;&quot;</pre><figure><img alt="The Cloud Scheduler job triggers MovieGroovy’s discovery flow every day at 04:00 Europe/Athens. The latest execution completed successfully." src="https://cdn-images-1.medium.com/max/1024/1*fBk7UERs9KXXA87TT7naqg.png" /><figcaption>The Cloud Scheduler job triggers MovieGroovy’s discovery flow every day at 04:00 Europe/Athens. The latest execution completed successfully.</figcaption></figure><p>The service account used by Cloud Scheduler needs the roles/run.invoker role on the Cloud Run Job.</p><p>From that point, each execution appears in Prefect Cloud as a normal flow run. I can inspect its status and logs from the Prefect dashboard, while Cloud Run remains responsible for the actual execution.</p><h3>Final Thoughts</h3><p>This setup has now been running successfully for MovieGroovy. Each scheduled execution appears in Prefect Cloud with its status, duration, task runs, and logs, which gives me the visibility I need for the product’s current scale.</p><p>A former colleague originally encouraged me to explore Prefect, and that conversation is what led me to try this approach. Thank you, Katerina!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a448f4cd46f1" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/how-i-connected-prefect-cloud-to-gcp-cloud-run-jobs-without-a-paid-subscription-a448f4cd46f1">How I Connected Prefect Cloud to GCP Cloud Run Jobs Without a Paid Subscription</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vendor Lock-In in the Embedding Layer: A Migration Story]]></title>
            <link>https://itnext.io/vendor-lock-in-in-the-embedding-layer-a-migration-story-183ea58e3668?source=rss-f1558d10c1f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/183ea58e3668</guid>
            <category><![CDATA[vector-database]]></category>
            <category><![CDATA[recommender-systems]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Vassiliki Dalakiari]]></dc:creator>
            <pubDate>Fri, 20 Feb 2026 23:12:18 GMT</pubDate>
            <atom:updated>2026-02-20T23:12:18.537Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TXFak-qKG90ZA0HyX38WdQ.png" /></figure><p>In this post, I break down why embeddings can become a hidden source of vendor lock-in in LLM-era products (RAG/semantic search/agent stacks), where embeddings are a foundational layer. I’ll explain the technical reason model swaps can invalidate stored vectors, and the exact migration steps required to recover a broken system.</p><h3>The Moment I Realized I Was Locked In</h3><p>It was late at night, right after coming back from an epic trip to Svalbard, Norway. My body was fighting the flu, and my mind was still replaying the surreal sight from the previous day’s flight: the Northern Lights dancing up in the clouds, right outside my window. I was completely exhausted, and all I wanted was to watch a documentary series</p><p>So I opened the application I built for moments like this: <a href="https://www.moviegroovy.gr/?utm_source=mediumcom&amp;utm_medium=article&amp;utm_campaign=vendorlock"><strong>moviegroovy.gr</strong></a>.</p><blockquote>MovieGroovy is a mood-based movie and TV recommender I built using embeddings and vector search. Instead of browsing by genre, it helps you discover content based on how you feel. Under the hood, it relies heavily on embedding models to represent descriptions, vibes, and user intent in a shared similarity space.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*Xg7Ut0UaRjphcgx1HqXFcA.png" /><figcaption>MovieGroovy in Action</figcaption></figure><p>I selected my mood.<br>I selected the streaming platforms I have access to.<br>And… boom.<br>An error.</p><p>I opened the logs and saw:</p><pre>Error embedding content: 404 models/text-embedding-004 is not found for API <br>version v1beta, or is not supported for embedContent.</pre><p>Google had announced that text-embedding-004 would be discontinued on January 14, 2026. I had seen the notice. I should have acted earlier.</p><blockquote><strong>But my real problem wasn’t that the model was removed. It was that the replacement models were incompatible.</strong></blockquote><p><strong>In reality, that meant that thousands of stored embeddings in my database were now useless.</strong> I couldn’t mix old and new vectors or “gradually” migrate. I had to regenerate everything. My vector space had become obsolete overnight.</p><blockquote>And then I realized that this model wasn’t just an API call. It defined my product’s data layer.</blockquote><h3>Vendor Lock-In Is Not Just Pricing</h3><p>When we say “vendor lock-in,” we usually think about money, which is valid. But in such systems, lock-in often appears <strong>even when pricing is not the trigger</strong>.</p><p>Because the dependency isn’t just operational. It’s representational.</p><p>If your product stores embeddings like mine, you are not just using a third-party service.</p><blockquote>You are committing your data layer to a specific mathematical space created by that model.</blockquote><p>That space defines what <em>similarity</em> means inside your system. And that space is not portable.</p><h3>Why Incompatible Embeddings Break a Working System</h3><p>An embedding model takes text and maps it into a vector space. That vector space has its own geometry, shaped by the model architecture, training data, and objective.</p><p>When you store those vectors in a database like Qdrant, you’re essentially storing points on a map.</p><blockquote>But unfortunately, two different embedding models do <strong>not</strong> produce points on the same map.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x-prg9ZC_uZ4YyjyXWlrUQ.png" /><figcaption>The Geometry Mismatch: Same Words, Different ‘Maps’</figcaption></figure><p>Even if:</p><ul><li>the output dimension is the same,</li><li>the provider is the same,</li><li>the model names look like “minor upgrades.”</li></ul><p>The geometry changes, the distances no longer mean the same thing, the nearest neighbors shift, and finally similarity scores become incomparable.</p><p>So you can’t safely mix old embeddings with new embeddings in the same collection, gradually migrate queries while keeping old vectors, and compare results before/after without re-validating behavior.</p><blockquote>If the embedding model changes, your existing vectors don’t “degrade.” They become <strong>a different coordinate system</strong>.</blockquote><p>That’s why it’s a hidden lock-in: <em>your stored data is coupled to a model’s geometry.</em></p><h3>Why This Can Be a Bad Idea</h3><p>Using a managed embedding API is often the right decision early on, because it’s fast to integrate, it reduces infrastructure work and of course it lets you focus on product.</p><p>The risk appears when embeddings move from “generated on the fly” to “persisted as part of the product.”</p><p>The moment you persist embeddings at scale, you inherit vendor lifecycle risk, as models get deprecated, the new ones are incompatible and output characteristics change.</p><blockquote>At that point, your dependency is no longer “an API call.” It’s your representation layer.</blockquote><p>And representation layers are expensive to change because they touch stored state, retrieval behavior, ranking outcomes, evaluation baselines, and most importantly <strong>user experience</strong>.</p><h3>What I Had to Do (And Why There Was No Shortcut)</h3><p>Once I understood what was happening, the plan was to rebuild the vector space.</p><p>Practically, that meant:</p><ol><li><strong>Re-embed everything with FastEmbed</strong><br>I used the <strong>FastEmbed library</strong> locally to regenerate embeddings for my entire dataset. Since FastEmbed is optimized with ONNX*, I didn&#39;t need a massive GPU cluster; I could transform thousands of rows of text into 768-dimensional vectors directly on my machine with incredible speed.</li></ol><p>This is an example on how you can do it:</p><pre>from fastembed import TextEmbedding<br><br>model = TextEmbedding(&quot;BAAI/bge-base-en-v1.5&quot;)<br>embeddings = list(model.embed([&quot;My Svalbard trip was freezing but epic.&quot;]))</pre><p><strong>2. Create a completely new collection (The Blue/Green Swap)<br></strong>I didn’t overwrite my live database in place. Overwriting a live collection leads to “Frankenstein results”, where a search query might hit a mix of old and new coordinate systems. Instead, I created a brand new collection in <strong>Qdrant</strong>, ingested the fresh FastEmbed vectors, and only pointed my production traffic to the new collection once the migration was 100% complete.</p><p><strong>3. Re-validate retrieval quality<br></strong>With the new collection live, I ran benchmarks to ensure the open-source model’s similarity matching was actually giving users good movie recommendations.</p><blockquote><strong>*The ONNX Advantage:</strong> Most embedding models require PyTorch, which is a massive, gigabyte-heavy framework built for training. Trying to deploy PyTorch in a serverless backend is a nightmare of cold starts and deployment size limits.</blockquote><blockquote>With FastEmbed, the model is converted into the <strong>ONNX format</strong>. ONNX is a highly optimized, lightweight runtime built strictly for inference. It strips out all the training bloat, meaning I could run lighting-fast vector generation directly on my local CPU during the migration, and deploy that exact same lightweight engine to my serverless production environment without breaking a sweat.</blockquote><h3>When Vendor Lock-In Is Fine (And When It Isn’t)</h3><p>I’m not arguing that everyone should self-host embeddings.</p><p>Vendor lock-in is acceptable when:</p><ul><li>embeddings are not persisted,</li><li>your dataset is small,</li><li>re-embedding is cheap,</li><li>retrieval behavior isn’t core to the product,</li><li>you can switch providers without rewriting stored state.</li></ul><h3>Final Reflection</h3><p>Vendor lock-in isn’t always visible in invoices.</p><p>Sometimes it shows up as a 404 in production, and a realization that your stored “meaning map” is tied to a model you don’t control.</p><p>If your product persists embeddings, treat the embedding model as infrastructure. And design as if it will change.</p><p><strong>Because it probably will.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=183ea58e3668" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/vendor-lock-in-in-the-embedding-layer-a-migration-story-183ea58e3668">Vendor Lock-In in the Embedding Layer: A Migration Story</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generative AI Agents Explained: From Tools to Multi-Agent Systems(Beginner-Friendly Guide)]]></title>
            <link>https://itnext.io/generative-ai-agents-explained-from-tools-to-multi-agent-systems-beginner-friendly-guide-e0593ecb2199?source=rss-f1558d10c1f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0593ecb2199</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Vassiliki Dalakiari]]></dc:creator>
            <pubDate>Sun, 11 May 2025 12:32:01 GMT</pubDate>
            <atom:updated>2025-05-12T19:46:44.069Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o7Qq42oy56lb4CRSetK-CQ.png" /></figure><p>Hey there, fellow explorers of the AI world! You’ve probably heard a lot about Generative AI models, those amazing systems that can create text, images, and more. But what if these models could go beyond just generating content? What if they could actually <em>do</em> things in the real world, like book flights, manage your calendar, or answer questions by searching the web in real-time?</p><p>That’s where Generative AI Agents come in. They represent a significant leap forward from standalone models. Think of them as the next evolution, moving from systems that just produce output to systems that can actively work towards goals, much like a skilled assistant uses tools to get a job done.</p><p>This article is a beginner-friendly overview, distilling key concepts from two insightful Google whitepapers: <a href="https://www.kaggle.com/whitepaper-agents"><strong>Agents</strong></a> and <a href="https://www.kaggle.com/whitepaper-agent-companion"><strong>Agents Companion</strong></a>. We’ll break down what agents are, how they work, the tools they use to interact with the world, and even peek into complex real-world applications like <strong>multi-agent systems</strong>.</p><blockquote>By the end, you’ll not only understand how Generative AI agents work; you’ll also see why they’re so critical for next-gen applications, how to avoid common pitfalls, and how to evaluate them effectively.</blockquote><h3>What Are AI Agents?</h3><blockquote>At its heart, a Generative AI agent is an application designed to achieve a specific objective.</blockquote><p><strong>AI agents interact with their environment by observing, reasoning, and acting using tools and APIs.</strong></p><p><strong>Unlike a basic language model</strong> that just gives you a single answer based on its training data, <strong>an agent can reason</strong>, <strong>plan, and execute tasks autonomously</strong>. It can even figure out what it needs to do next to reach its goal without explicit step-by-step instructions from a human. This blend of reasoning, logic, and the ability to tap into external information is what defines an agent.</p><p>Think of a chef. A chef doesn’t just rely on their internal knowledge:</p><ul><li>they use tools (knives, ovens, recipes),</li><li>gather information (customer orders, pantry contents),</li><li>reason about the best way to prepare a dish,</li><li>take action (chop, cook), and</li><li>adjust based on feedback or changing circumstances.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*m-yDtplgSSNHAxY0.jpg" /></figure><p><strong>Agents operate in a similar cyclical fashion.</strong></p><h3>How AI Agents Work: Core Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YjD30QBXsFz7KI02WDwwCA.png" /></figure><p>How does an agent manage this observation, reasoning, and action? It relies on a cognitive architecture, which can be broken down into three fundamental components:</p><ol><li><strong>The Model</strong>: This is the brain of the agent, typically a language model (or potentially multiple models). The model is the central decision-maker, capable of following instruction-based reasoning. It’s not usually trained on the agent’s specific setup, but it can be refined with examples.</li><li><strong>The Tools:</strong> These are the agent’s hands and senses, allowing it to interact with the <em>outside world</em> beyond its training data. Tools bridge the gap between the agent’s internal capabilities and external systems like databases, APIs, or search engines.</li><li><strong>The Orchestration Layer:</strong> This is the manager or the process flow. It’s a cyclical loop that takes in information, performs internal reasoning, and uses that reasoning to decide the agent’s next action or decision. This loop continues until the agent reaches its goal. The orchestration layer is responsible for managing the agent’s memory, state, reasoning, and planning.</li></ol><p>Together, these components allow agents to go far beyond just generating text. They can access real-time data, perform real-world actions, maintain conversation history, and execute complex tasks through multi-step processes.</p><h3>Tools: The Agent’s Keys to the Outside World</h3><blockquote><strong>Without tools, models are limited to the information they were trained on</strong>, which quickly becomes outdated.</blockquote><p>Tools empower agents to connect to dynamic, real-world information and services. The sources highlight three primary types of tools Google models can interact with: <strong>Extensions, Functions and Data Stores.</strong></p><h4>Extensions</h4><p>Think of Extensions as a standardized way to bridge an API and an agent. They teach the agent <em>how</em> to use a specific API endpoint and <em>what</em> arguments it needs, often using examples. The key here is that the Extension is executed on the agent-side. If a user wants to book a flight, the agent, using an Extension configured for a flight API, can make that API call directly.</p><h4>Functions</h4><p>Functions are similar to Extensions in that they connect the agent to external capabilities, but with a significant difference: <strong>the model outputs a Function <em>call</em> and its arguments, but the <em>execution</em> happens on the client-side.</strong> The agent doesn’t directly call the API; it tells the <em>application</em> what API call needs to be made and with what parameters. This gives developers greater control.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Oht1OI5EWDfXvzCgNQcJug.png" /><figcaption><em>Delineating client vs. agent side control for extensions and function calling</em></figcaption></figure><p>Let’s look at a simple example.</p><p><strong>Lets say we have an agent helping a user plan summer vacations. 🏖</strong></p><p>The goal is to get the agent to produce a list of mediterranean islands that we can use in our middleware application to download images, data, etc. for the user’s trip planning<em>.</em></p><p>A user might say something like:</p><blockquote>I’d like to take summer vacations in an island with quiet beaches with my family but I’m not sure where to go.</blockquote><p>In a typical prompt to the model, the output might look like the following:</p><blockquote>Sure, here’s a list of mediterranean islands that you can consider for family summer vacations:</blockquote><blockquote>- Skopelos, Greece<br>- Santorini, Greece<br>- Crete, Greece<br>- Majorca, Spain<br>- Sardinia, Italy<br>- Corsica, France</blockquote><p>While the above output contains the data that we need (island names), the format isn’t ideal for parsing. With <strong>Function Calling</strong>, we can teach a model to format this output in a structured style (like JSON) that’s more convenient for another system to parse.</p><p>Given the same input prompt from the user, an example JSON output from a Function might look like the following:</p><pre>function_call {<br>  name: &quot;display_islands&quot;<br>  args: { &quot;islands&quot;: [<br>    {&quot;name&quot;: &quot;Skopelos&quot;, &quot;country&quot;: &quot;Greece&quot;},<br>    {&quot;name&quot;: &quot;Santorini&quot;, &quot;country&quot;: &quot;Greece&quot;},<br>    {&quot;name&quot;: &quot;Crete&quot;, &quot;country&quot;: &quot;Greece&quot;},<br>    {&quot;name&quot;: &quot;Majorca&quot;, &quot;country&quot;: &quot;Spain&quot;},<br>    {&quot;name&quot;: &quot;Sardinia&quot;, &quot;country&quot;: &quot;Italy&quot;},<br>    {&quot;name&quot;: &quot;Corsica&quot;, &quot;country&quot;: &quot;France&quot;},<br>  ], &quot;preferences&quot;: &quot;quiet beaches&quot;}<br>}</pre><p>This JSON payload is generated by the model but would be sent back to your application (the client-side) to then use these parameters to call a <em>different</em> API (like Google Places) to get more details or images, which are then displayed to the user. <br><strong>This decouples the agent’s decision-making from the actual API execution.</strong></p><p>The following sequence diagram shows the above interaction in step by step detail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z84YPt_OkXC3ipuVxrBqgg.png" /><figcaption><em>Sequence diagram showing the lifecycle of a Function Call</em></figcaption></figure><p>This example shows how the model identifies the user’s intent (“<em>an island with quiet beaches</em>”) and suggests calling the display_islandsfunction with the appropriate parameters. Your application code then receives this structured suggestion and performs the actual work.</p><h4>Data Stores</h4><p>Now, what if you need your agent to access up-to-date documents, websites, or databases that weren’t part of its initial training data?</p><p>Data Stores provide access to this dynamic information. They typically involve converting documents into numerical representations (vector embeddings) stored in a vector database. When a user asks a question, the agent can search this database for relevant information using the user’s query (also embedded). This retrieved information is then given to the agent’s model to help it formulate a grounded, factual response.</p><p>This is the core idea behind <strong>Retrieval Augmented Generation (RAG)</strong>. Data Stores allow agents to extend their knowledge far beyond their static training data, using various formats like PDFs, spreadsheets, or website content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nWfkX-nXb-4N0D1RoUjZCA.png" /><figcaption><em>Sample RAG based application with ReAct reasoning/planning</em></figcaption></figure><p>In summary, these tools are vital for enabling agents to interact with the real world, access fresh data, and perform actions that a standalone language model simply cannot.</p><blockquote><strong><em>Common Pitfall: </em></strong><em>One of the biggest mistakes in agent development is </em><strong><em>underestimating the tool setup</em></strong><em>. Without properly defined schemas or reliable APIs, the agent’s function calling can fail silently or hallucinate capabilities.</em></blockquote><p><em>If you want to learn more about Embeddings and Vector Databases, check the following article:</em></p><p><a href="https://itnext.io/how-machines-understand-meaning-a-guide-to-embeddings-vector-search-ce80356c584f">How machines understand meaning: A guide to Embeddings &amp; Vector Search</a></p><h3>How AI Agents Learn, Reason, and Improve Over Time</h3><p>We touched on the orchestration layer as the “manager.” This layer uses cognitive architectures and reasoning frameworks to guide the agent’s steps. Just like our chef follows a process, an agent needs a structured way to think and act.</p><p>Reasoning frameworks provide this structure. The sources mention several popular ones:</p><ul><li><strong>Chain-of-Thought (CoT): </strong>This involves breaking down a complex problem into intermediate steps, allowing the model to show its “thinking process”.</li><li><strong>Tree-of-Thoughts (ToT): </strong>This expands on CoT by exploring multiple possible “thought chains” or reasoning paths, useful for more strategic tasks.</li><li><strong>ReAct (Reasoning and Acting): </strong>This framework synergizes thinking (“Thought”) and performing actions (“Action”). The agent alternates between internal reasoning (what should I do next?) and taking actions (using a tool).<br>Read more about how ReAct works at the following link.</li></ul><p><a href="https://itnext.io/understanding-prompt-engineering-how-to-talk-to-ai-3186ed68fc85">Understanding Prompt Engineering: How to Talk to AI</a></p><p>These reasoning strategies make the agent’s decision-making process interpretable, auditable, and more robust.</p><blockquote><strong><em>Choosing the right reasoning framework is part of effective agent design</em></strong>.<strong><em> </em></strong><em>For example, </em><strong><em>Tree-of-Thoughts is</em></strong><em> especially useful when the agent needs to explore multiple possible plans before choosing one, but it’s also </em><strong><em>computationally heavier and not always necessary for simple tasks</em></strong><em>.</em></blockquote><h3>Beyond the Single Agent: Multi-Agent Systems</h3><p>While a single agent is powerful, complex tasks often benefit from a team approach. Multi-agent systems involve multiple specialized agents collaborating to achieve complex objectives. Each agent can be an expert in a particular domain, working together like a team of specialists.</p><p>This approach offers significant advantages:</p><ul><li><strong>Enhanced Accuracy: </strong>Agents can cross-check each other.</li><li><strong>Improved Efficiency: </strong>Tasks can be done in parallel.</li><li><strong>Better Handling of Complex Tasks: </strong>Large problems are broken down.</li><li><strong>Increased Scalability:</strong> Add more specialists as needed.</li><li><strong>Improved Fault Tolerance: </strong>If one agent struggles, others can help.</li><li><strong>Reduced Hallucinations and Bias: </strong>Combining perspectives leads to more reliable outputs.</li></ul><p>These agents work together using different design patterns:</p><ul><li><strong>Hierarchical:</strong> A central Orchestrator Agent routes queries to the correct specialized agent.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WlxE_sVOJ7KNT8TE48xs2Q.png" /><figcaption>Hierarchical Pattern: Turn 1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ezNCmKFbDe2Q9ZT8HEusBg.png" /><figcaption>Hierarchical Pattern: Turn 2</figcaption></figure><ul><li><strong>Diamond:</strong> Specialized agents’ responses go through a central agent (like a Rephraser) to refine the output before it reaches the user.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AjuWW247HCWhm6ZQfkaK4w.png" /><figcaption>Diamond Pattern</figcaption></figure><ul><li><strong>Peer-to-Peer: </strong>Agents can hand off tasks directly to each other if they realize a different agent is better suited.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p142e0DJOKsXf06PEj3KZQ.png" /><figcaption>Peer-to-Peer Pattern</figcaption></figure><ul><li><strong>Collaborative: </strong>Multiple agents contribute complementary parts to answer a single query, and a Response Mixer Agent combines them.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HIvXErAPApswfGjLQ0f5eA.png" /><figcaption><em>Collaborative pattern</em></figcaption></figure><ul><li><strong>Adaptive Loop:</strong> An agent iteratively refines its approach through repeated attempts, adjusting queries or actions until satisfactory results are achieved.</li></ul><blockquote><strong><em>Common Pitfall:</em></strong><em> While multi-agent systems offer flexibility, they introduce complexity. </em><strong><em>Poor coordination between agents can result in delays, inconsistent answers, or unnecessary tool use.</em></strong></blockquote><h3>Building and Evaluating Agents</h3><p>Getting agents from a cool idea to a reliable, production-ready application requires discipline. The sources introduce Agent Ops, a practice focusing on efficiently operationalizing agents, building on DevOps and MLOps.</p><p>But what does effective agent evaluation actually look like?</p><h4>Why Evaluation Matters</h4><blockquote><em>Lets say your agent confidently tells a user that Santorini is in Italy. The output looks great: it’s structured, fluent, and fast. </em><strong><em>But it’s completely wrong.</em></strong></blockquote><p><strong>So what failed? The reasoning? The tool? The retrieval step?</strong><br>This is the value of <strong>deep agent evaluation; </strong>not just judging the output, but understanding how the agent got there.</p><p>Evaluation involves:</p><ol><li><strong>Assessing Core Capabilities: </strong>How well does the agent understand instructions or reason?</li><li><strong>Evaluating Trajectory and Tool Use:</strong> Analyzing the sequence of steps and tool calls the agent made. Did it take the expected path? Were the tool calls correct?</li><li><strong>Evaluating the Final Response:</strong> Is the final output correct, relevant, and high-quality? You can use automated tools (“autoraters” or LLMs acting as judges) or human evaluation for this.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x2p48XsDTgPjqTYrlyoSJA.png" /><figcaption>Three layers of agent evaluation, what each reveals, and how failures typically manifest</figcaption></figure><p>Metrics are key, from high-level business goals (like goal completion rate) down to detailed traces of the agent’s internal steps. Human feedback (like simple thumbs up/down or feedback forms) is also invaluable, especially for subjective tasks or calibrating automated evaluations.</p><p>Platforms like <strong>Google’s </strong><a href="https://cloud.google.com/products/agent-builder"><strong>Vertex AI Agent Builder</strong></a><strong> </strong>provide tools and services to help developers build, manage, and evaluate agents, including managed runtimes, evaluation services, and a portfolio of pre-built tools for databases, APIs, and search.</p><blockquote><strong><em>Top Tip: </em></strong><em>The most effective evaluations go beyond final outputs. Use trajectory tracing to find where agents make missteps, and combine autoraters with human feedback to get a complete picture of performance.</em></blockquote><h3>The Future is Agentic</h3><p>Generative AI agents are ready to transform how we interact with technology and automate complex tasks. By using tools, reasoning frameworks, and collaborating in multi-agent systems, they can tackle problems far beyond the reach of standalone models.</p><p>The journey from prototype to production is still evolving, with ongoing research into better evaluation methods, multi-agent coordination, real-world adaptation, and making agent behavior more understandable. Concepts like “contract adhering agents” are being explored to make agent task definitions more precise and reliable.</p><p>Moreover, AI agents are increasingly used in industries like healthcare, automotive, customer service, and finance, with companies leveraging them to automate tasks and improve decision-making.</p><p>This has been a quick tour based on Google’s whitepapers, covering the fundamental building blocks and hinting at the exciting possibilities. If you’re curious to learn more, the sources themselves are packed with deeper insights, diagrams, and technical details.</p><p>This has been a quick tour based on Google’s whitepapers, covering the fundamental building blocks and hinting at the exciting possibilities. If you’re curious to learn more, the sources themselves are packed with deeper insights, diagrams, and technical details.</p><p><strong>The agentic era is just beginning, and it’s one of the most exciting frontiers in AI today.</strong></p><blockquote>Want to go deeper? Search for terms like “Agentic RAG,” “LLM orchestration,” “function calling in GenAI,” and “Vertex AI Agent Builder”; these will surface more real-world examples and toolkits.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0593ecb2199" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/generative-ai-agents-explained-from-tools-to-multi-agent-systems-beginner-friendly-guide-e0593ecb2199">Generative AI Agents Explained: From Tools to Multi-Agent Systems(Beginner-Friendly Guide)</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How machines understand meaning: A guide to Embeddings & Vector Search]]></title>
            <link>https://itnext.io/how-machines-understand-meaning-a-guide-to-embeddings-vector-search-ce80356c584f?source=rss-f1558d10c1f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce80356c584f</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Vassiliki Dalakiari]]></dc:creator>
            <pubDate>Fri, 25 Apr 2025 12:27:37 GMT</pubDate>
            <atom:updated>2025-04-27T08:41:46.936Z</atom:updated>
            <content:encoded><![CDATA[<h4>This article explains how embeddings turn meaning into math and how vector databases help us search through it efficiently.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QcWqPIt4gNgVOcV0bKhwpQ.png" /></figure><p>We are in the data evolution period, where computers (and us, people) deal with all sorts of information: text, images, videos, and more. <strong>To make sense of this diverse data, we need a way to translate it into a language that machines can easily understand and compare. </strong>This is where embeddings come in.</p><h3>What exactly are embeddings?</h3><blockquote>Think of embeddings as a way to translate real-world things into simple lists of numbers.</blockquote><p>These lists are also known as <strong>vectors</strong>. Why do we need to do this? Well, computers are very good at working with numbers. It’s like giving a computer a secret code to understand the meaning of things.</p><blockquote>Lets say that you want to describe a place on Earth. You can use two numbers: its <strong>latitude</strong> and <strong>longitude</strong>. These two numbers act like an “embedding” for that location. If two places have similar latitude and longitude numbers, you know they are close to each other.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BxQRvBE8qJLDT8UZvBpdWA.png" /></figure><p>Embeddings work in a similar way for other types of data. For example, if we take two words that mean almost the same thing, like “happy” and “joyful,” and turn them into embeddings, the lists of numbers will be quite similar. But if we embed words with very different meanings, like “happy” and “banana,” the number lists will be very different.</p><p><strong>So, why are embeddings so important?</strong></p><ul><li>They help computers <strong>understand the meaning</strong> of different types of data.</li><li>They allow us to <strong>compare</strong> how similar different pieces of data are using numbers.</li><li>They provide a <strong>common language</strong> for computers to work with text, images, and more.</li><li>They can make storing and processing large amounts of data more <strong>efficient</strong> by creating smaller representations while keeping the important information. This is like a way to compress data without losing its meaning.</li></ul><h3>Different flavors of embeddings</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BxQTz-EKrKrTvlViJQFrHw.png" /></figure><p>There are different ways to create these number lists depending on the type of data.</p><ul><li><strong>Text Embeddings:</strong> These are for words and blocks of text.<br>- Older techniques like <strong>Word2Vec</strong> learned embeddings for individual words by looking at the words that appear around them.<br>- More advanced methods use <strong>large language models (LLMs)</strong> like <strong>BERT</strong>, that can understand the context of words in a sentence, so the embedding for a word can change depending on where it is used.</li><li><strong>Image and Multimodal Embeddings:</strong> We can also create embeddings for images. <strong>Multimodal embeddings</strong> go a step further by representing both text and images in the same number space. This means you can search for images using text descriptions, for example.</li><li><strong>Structured Data Embeddings:</strong> This is for data that is organized in tables. We can create embeddings for each row in the table, which can be useful for finding unusual patterns or for feeding this data into other machine learning models.</li><li><strong>Graph Embeddings:</strong> If your data is connected like a network (for example, social media connections), graph embeddings can capture information about each item (like a person) and their relationships with others.</li></ul><h3>Finding needles in haystacks: Vector DBs</h3><p>When I was building a system that relied heavily on text embeddings, things got painful fast. Every time the dataset grew, I found myself recalculating embeddings from scratch, over and over.</p><blockquote>It was like rerunning the same marathon every morning.</blockquote><p>That’s when I realized I needed something smarter. I started digging into vector databases, and it clicked: <strong>I didn’t need to rebuild, I just needed to <em>build incrementally</em>.</strong> A vector DB became my go-to tool for storing and querying embeddings without burning compute cycles or my patience.</p><p>That experience helped me understand why vector databases are essential when working with embeddings at scale. Once we have these lists of numbers (embeddings), we often have a huge collection of them. To quickly find the embeddings that are similar to a new query (which is also turned into an embedding), we use special databases called <strong>vector databases</strong>.</p><p>Normal databases search for exact matches of keywords. But vector databases are designed to find embeddings that are <strong>close</strong> to each other in the number space. This allows us to search based on meaning, not just exact words.</p><p>Because we might have millions or even billions of embeddings, we need very fast ways to search. There are some clever <strong>vector search algorithms</strong> that help with this:</p><ul><li><strong>Locality Sensitive Hashing (LSH):</strong> This is like creating buckets so that similar items are likely to fall into the same bucket. Then, you only need to search within those buckets.</li><li><strong>Hierarchical Navigable Small Worlds (HNSW):</strong> This builds a layered network that allows you to quickly “zoom in” on the most similar embeddings. <strong>FAISS</strong> is a popular tool that uses HNSW.</li><li><strong>ScaNN:</strong> This is a method developed by Google that can divide the embeddings into groups and then quickly find the closest ones, balancing speed and accuracy. <strong>Vertex AI Vector Search</strong> uses ScaNN.</li></ul><p>These algorithms make it possible to find similar embeddings very quickly, even when dealing with massive amounts of data.</p><p>Some popular Vector DBs:</p><ul><li><a href="https://www.trychroma.com/">ChromaDB</a></li><li><a href="https://weaviate.io/">Weaviate</a></li><li><a href="https://milvus.io/">Milvus</a></li><li><a href="https://qdrant.tech/">Qdrant</a></li><li><a href="https://www.pinecone.io/">Pinecone</a></li></ul><h3>What can we actually do with this?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G-HYpBy5FQm4aQ7AvzBvoQ.png" /></figure><p>Embeddings and vector databases power many exciting applications:</p><ul><li><strong>Search:</strong> Finding relevant information (documents, images, videos) even if the exact words you searched for are not present. Think about how Google can find pages even if you misspell words.</li><li><strong>Recommendations:</strong> Suggesting things you might like (products, movies, articles) based on what you’ve interacted with before.</li><li><strong>Question Answering with Sources (RAG):</strong> Using embeddings to find relevant information and then using a language model to answer your questions based on that information, while also providing the sources. This helps the answers be more accurate and trustworthy.</li><li><strong>Finding Similar Content:</strong> Checking if two pieces of text or two images are similar in meaning or appearance, even if they are not exactly the same.</li><li><strong>Spotting Unusual Activity (Anomaly Detection):</strong> Identifying data points that are very different from the rest, which could indicate a problem or fraud.</li></ul><h3>Try it yourself!</h3><p>Let’s see what an embedding looks like in real life.<br>Here’s a super quick demo in Python (requires installing google-generativeai and chromadb). We’ll use <strong>Gemini</strong> for generating embeddings and <strong>ChromaDB</strong> for storing and searching.</p><pre>from google import genai<br>from google.genai import types<br>import chromadb<br><br># Authenticate Gemini (requires API key)<br>client = genai.Client(api_key=GOOGLE_API_KEY)<br><br>words = [&quot;happy&quot;, &quot;joyful&quot;, &quot;banana&quot;]<br><br>response = client.models.embed_content(<br>    model=&#39;models/text-embedding-004&#39;,<br>    contents=words,<br>    config=types.EmbedContentConfig(task_type=&#39;semantic_similarity&#39;)<br>)<br>embeddings = [item.values for item in response.embeddings]<br><br># Store embeddings in ChromaDB<br>chroma_client = chromadb.Client()<br>collection = chroma_client.create_collection(&quot;my_embeddings&quot;)<br>for word, emb in zip(words, embeddings):<br>    collection.add(<br>        documents=[word],<br>        embeddings=[emb],<br>        ids=[word]<br>    )<br><br># Let&#39;s search for the most similar word to &#39;happy&#39;<br>query_embedding = client.models.embed_content(<br>    model=&#39;models/text-embedding-004&#39;,<br>    contents=[&quot;happy&quot;],<br>    config=types.EmbedContentConfig(task_type=&#39;semantic_similarity&#39;)<br>)<br>results = collection.query(query_embeddings=[query_embedding.embeddings[0].values], n_results=2)<br>print(&quot;Most similar to &#39;happy&#39;:&quot;, results[&#39;documents&#39;])</pre><p>That’s the result:</p><pre>Most similar to &#39;happy&#39;: [[&#39;happy&#39;, &#39;joyful&#39;]]</pre><p>The code example above show how we can use embeddings to search for similar words in a vector database like Chroma and calculate their similarity scores numerically.</p><p>The following diagram takes those same similarity relationships and translates them into a visual map, letting us see at a glance which words the model considers most alike and which ones stand apart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zYoJAuvcH8eiZzFuzMhFRg.png" /><figcaption><em>MDS (Multidimensional Scaling) plot</em></figcaption></figure><p><em>Notice how “happy” and “joyful” appear close together, reflecting their similar meanings, while “banana” is further away, indicating that it’s unrelated.</em></p><blockquote>In the past, I preferred using LASER (Language-Agnostic SEntence Representations) by Meta, an open-source tool that generates sentence embeddings for over 90 languages right on your machine, with no need for cloud APIs or subscriptions. It uses a BiLSTM (Bidirectional LSTM) architecture, making it fast and effective for multilingual tasks.</blockquote><h3>Limitations and Challenges</h3><p>Embeddings and vector DBs are powerful, but not perfect.</p><p><strong>When Embeddings Fail:</strong></p><ul><li>Sarcasm and irony can be hard for embedding models to capture (e.g., “Great job!” could be negative).</li><li>Out-of-vocabulary words, slang, or new terms may not be well represented.</li><li>Context matters: a single embedding might miss nuances.</li></ul><p><strong>Challenges of Scaling Vector DBs:</strong></p><ul><li>As your database grows to millions of embeddings, searching can get slow without clever algorithms.</li><li>Storing high-dimensional vectors uses memory fast.</li><li>Vector search results are often “approximate,” not always perfect.</li></ul><h3>Key takeaways</h3><p>In short, <strong>embeddings are a way to turn data into meaningful numbers</strong>, and <strong>Vector DBs are specialized databases for quickly finding similar embeddings</strong>. Together, they are powerful tools that help computers understand and work with the huge amounts of diverse data we have today.</p><p>Choosing the right embedding technique and vector database depends on the specific problem you are trying to solve and the type of data you are working with. It’s a complex field, but I hope this explanation gives you a good starting point to understand these important concepts.</p><h3>Glossary</h3><ul><li><strong>Multimodal:</strong> Refers to data involving multiple types (like text and images) represented together.</li><li><strong>RAG (Retrieval-Augmented Generation):</strong> Combines search with language models to answer questions based on retrieved info.</li><li><strong>Approximate Search:</strong> A faster, “good enough” search that doesn’t guarantee finding the perfect match but works well in practice.</li><li><strong>Nearest Neighbor Search: </strong>A technique to quickly find which vectors (embeddings) in a database are most similar to a given query vector.</li><li><strong>Locality Sensitive Hashing (LSH): </strong>An algorithm that groups similar vectors into buckets to speed up nearest neighbor search.</li><li><strong>Hierarchical Navigable Small Worlds (HNSW): </strong>A graph-based algorithm for fast approximate nearest neighbor search in large datasets.</li><li><strong>BERT (Bidirectional Encoder Representations from Transformers): </strong>A popular modern language model used for generating context-aware text embeddings.</li><li><strong>Out-of-Vocabulary (OOV): </strong>Words or tokens not seen by the embedding model during training; may be poorly represented.</li><li><strong>FAISS: </strong>A popular open-source library by Facebook for efficient similarity search and clustering of dense vectors.</li><li><strong>Tokenization:</strong> Breaking text into words or subwords before embedding.</li><li><strong>Context Window:</strong> The span of text a model considers at once for contextual embeddings.</li></ul><p><strong>Here are a few more articles you might enjoy:</strong></p><ul><li><a href="https://itnext.io/understanding-prompt-engineering-how-to-talk-to-ai-3186ed68fc85">Understanding Prompt Engineering: How to Talk to AI</a></li><li><a href="https://itnext.io/how-i-built-a-genai-movie-recommender-that-understands-you-1448af94647e">How I built a GenAI Movie Recommender that understands you</a></li><li><a href="https://itnext.io/feature-engineering-in-xgboost-a-practical-guide-7fbafa7dbdbd">Feature Engineering in XGBoost: A Practical Guide</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce80356c584f" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/how-machines-understand-meaning-a-guide-to-embeddings-vector-search-ce80356c584f">How machines understand meaning: A guide to Embeddings &amp; Vector Search</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I built a GenAI Movie Recommender that understands you]]></title>
            <link>https://itnext.io/how-i-built-a-genai-movie-recommender-that-understands-you-1448af94647e?source=rss-f1558d10c1f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/1448af94647e</guid>
            <category><![CDATA[langgraph]]></category>
            <category><![CDATA[gemini]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <dc:creator><![CDATA[Vassiliki Dalakiari]]></dc:creator>
            <pubDate>Fri, 18 Apr 2025 21:50:12 GMT</pubDate>
            <atom:updated>2025-04-27T08:38:26.355Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*71g2anOZ73lmNGaJ-uJl_A.png" /></figure><p>I joined the Generative AI Intensive Course Capstone Competition by Google and Kaggle because, frankly, it was the perfect excuse to finally build something cool, and stick with it to the end. <br><strong>Let’s be honest, we all have those “I’ll get to it someday” projects. <br></strong>This was my chance to commit.</p><h3>The real challenge: Watch what you feel</h3><p>I was stuck between two ideas:</p><ul><li>An environmental project with social impact</li><li>A movie recommender based on mood and streaming subscriptions</li></ul><p><strong>I really wanted to help the planet…</strong><br>But I also really wanted to stop wasting 40 minutes every time I sat down with friends and family to pick something to watch.</p><p>So yes, I feel slightly guilty that I chose to solve a <strong>deeply personal (and very first-world)</strong> problem instead of something noble. But hey, world peace can wait. Right now, I just want to find something to watch <em>before the food gets cold</em>.</p><p>One movie had already been watched. Another didn’t appeal to everyone. Some weren’t even available on the platforms we had. After <strong>40 minutes of scrolling, rejecting, debating, and compromising</strong>, we finally hit play on something that… no one really liked.</p><p>I thought: <em>Why is this still a problem?</em><br> We live in the age of AI, there must be a better way to pick a movie.</p><h3>The Problem with recommendation engines</h3><p>Most recommendation systems rely on past behavior. If I usually watch true-crime documentaries, they’ll keep suggesting more of the same — like an algorithmic echo chamber. That might work sometimes, but what if I suddenly feel like watching a heartwarming animated film? Or something nostalgic?</p><p>Good luck breaking out of the loop.</p><blockquote>Because, usually we don’t just want to “watch something.”<br><strong>We want something that matches our mood.</strong></blockquote><p>So I decided to build something that <em>does</em> that, a system that asks:</p><p><strong><em>“What’s your mood today?”<br></em></strong><em> And replies with:<br></em><strong><em> “Here’s exactly what you’re looking for.”</em></strong></p><h3>The Idea: A Mood-Based Movie Recommender</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NuwPEHtjPMJc5jWm2Z_MEQ.png" /></figure><p>Using the power of <strong>Generative AI</strong>, I built an intelligent assistant that:</p><ul><li>Understands your <strong>vibe</strong> (thrilling, nostalgic, feel-good, …)</li><li>Filters results based on the <strong>streaming services</strong> you use</li><li>Lets you pick between <strong>movies or TV shows</strong></li><li>Asks follow-up questions to narrow down your preferences</li><li>Explains why each suggestion fits you, using real-world information</li></ul><p>All of this is orchestrated within a stateful LangGraph agent — not just a static recommendation engine.</p><h3>How I built It (Technically Speaking)</h3><p>This project was the perfect opportunity to apply nearly every concept I learned in the Generative AI course — from embeddings and retrieval to function calling and agent design.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6ZL4f0D3QI6fy2BKYVw6_Q.png" /></figure><p>Here’s how it all came together.</p><h4>1. Data Collection (via TMDB API)</h4><p>I started by collecting data using the TMDB API. For each genre and major streaming provider (like Netflix, Disney+, Apple TV, etc.), I retrieved the <strong>50 most-rated movies and TV shows</strong> released in the past 10 years for each genre for each streaming provider.</p><p>Each item included:</p><ul><li>Title</li><li>Overview</li><li>Genre ID</li><li>Streaming platform</li><li>Media type (movie or TV)</li><li>Poster path</li><li>Average user rating</li><li>Release date</li></ul><p>I also handled overlaps: some shows belong to multiple genres or appear on multiple platforms. I ensured deduplication while preserving all metadata.</p><h4>2. Embedding &amp; Vector Storage</h4><p>I used <strong>Gemini’s </strong><strong>text-embedding-004</strong> model to convert every movie/TV show overview into a semantic vector.</p><p>These embeddings were stored in <strong>Chroma</strong>, a persistent vector database, alongside their metadata. This allowed me to later search for titles whose <strong>semantic meaning matches a user’s mood, </strong>not just exact keywords.</p><pre>from chromadb import Documents, EmbeddingFunction, Embeddings<br><br>from google.genai import types<br><br>client = genai.Client(api_key=GOOGLE_API_KEY)<br><br>class GeminiEmbeddingFunction(EmbeddingFunction):<br>  def __call__(self, input: Documents) -&gt; Embeddings:<br>    EMBEDDING_MODEL_ID = &quot;models/text-embedding-004&quot;  <br>    title = &quot;Custom query&quot;<br>    response = client.models.embed_content(<br>        model=EMBEDDING_MODEL_ID,<br>        contents=input,<br>        config=types.EmbedContentConfig(<br>          task_type=&quot;retrieval_document&quot;,<br>          title=title<br>        )<br>    )<br><br>    return [res.values for res in response.embeddings]<br><br>...<br><br>def add_to_chroma_db(documents: list[str], ids: list[str], metadatas: list[dict], db: chromadb.api.Collection):<br>    &quot;&quot;&quot;<br>    Adds documents and metadata to a ChromaDB collection.<br>    <br>    :param documents: A list of movie or TV show descriptions<br>    :type documents: list[str]<br>    :param ids: A list of unique identifiers corresponding to the documents<br>    :type ids: list[str]<br>    :param metadatas: A list of metadata dictionaries<br>    :type metadatas: list[dict]<br>    :param db: The ChromaDB collection to add to<br>    :type db: chromadb.api.Collection<br>    &quot;&quot;&quot;<br>    for meta in metadatas:<br>        if isinstance(meta.get(&quot;platforms&quot;), list):<br>            meta[&quot;platforms&quot;] = &quot;, &quot;.join(meta[&quot;platforms&quot;])<br>            <br>    db.add(<br>        documents=documents,<br>        ids=ids,<br>        metadatas=metadatas,<br>        uris=None<br>    )</pre><h4>3. User Input &amp; Agent Flow</h4><p>Instead of a single prompt, I created a <strong>LangGraph agent</strong> to manage the interaction flow step-by-step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*XrMxANKRFl9reTI3I0O5Ew.png" /></figure><p>The graph walks through these nodes:</p><ul><li>collect_preferences: asks the user for mood, media type, and platforms</li><li>search_movies: queries Chroma using the embedded mood</li><li>filter_platforms: narrows results to match user&#39;s subscriptions</li><li>refine_choices_with_gemini: asks a follow-up question to further narrow suggestions</li><li>respond: generates and displays the final recommendations with summaries</li></ul><p>This approach gave me fine-grained control and memory between steps, unlike a typical chat loop.</p><h4>4. Semantic Search + Filtering</h4><p>When the user enters their mood (e.g. “adventurous”), it’s embedded with the same model and compared against the stored vectors using cosine similarity. This surfaces emotionally relevant content, rather than just keyword-matching.</p><p>After retrieving up to 20 candidates, I filtered them by:</p><ul><li>Media type (movie or TV)</li><li>Available streaming platforms</li></ul><h4>5. Follow-Up queston</h4><p>To help the user refine their results, Gemini generates a follow-up question, tailored to the original mood and top matches. For example:</p><blockquote>“Would you prefer a fast-paced story or something more introspective?”</blockquote><p>Once the user answers, Gemini re-evaluates the list and selects <strong>the best two</strong> based on the refined preference.</p><pre>question_prompt = f&quot;&quot;&quot;<br>    You are a helpful assistant that guides users to narrow down movie or TV show suggestions.<br>    <br>    Given:<br>    - The user&#39;s mood<br>    - Their preferred media type<br>    - Their available streaming platforms<br>    - A list of recommended titles<br>    <br>    Generate a single follow-up question to help refine their choices and reduce the list, based on tone, genre, or story preference.<br>    <br>    Return ONLY the follow-up question, nothing else.<br>    <br>    ---<br>    <br>    Example:<br>    <br>    Mood: playful  <br>    Media type: movie  <br>    Platforms: Netflix, Apple TV  <br>    Recommendations: The Mitchells vs. The Machines, Paddington 2, Luca  <br>    <br>    Follow-up Question: <br>    Do you want something animated, family-friendly, or more sarcastic?<br>    <br>    ---<br>    <br>    Now for the user:<br>    <br>    Mood: {mood}  <br>    Media type: {state[&#39;media_type&#39;]}  <br>    Platforms: {&#39;, &#39;.join(state[&#39;platforms&#39;])}  <br>    Recommendations: {&#39;, &#39;.join(titles_info)}<br>    <br>    Follow-up Question:<br>    &quot;&quot;&quot;<br>    q_response = chat.send_message(question_prompt)</pre><h4>6. Personalized Summaries via Grounded Generation</h4><p>For each final suggestion, I used <strong>Gemini + Google Search Grounding</strong> to generate a personalized summary and return some structured info:</p><ul><li>Why this title fits the user’s mood</li><li>TMDB user score</li><li>Release year</li><li>Top cast members</li><li>Direct link to the TMDB page</li></ul><p>I used <strong>few-shot prompting</strong> to guide Gemini to return valid JSON, with structured fields like:</p><pre>&quot;&quot;&quot;<br>Example 1:<br>Movie title: &quot;The Pursuit of Happyness&quot;<br>Mood: &quot;inspired&quot;<br>TMDB ID: 1402<br>Release date: 2006-02-11<br>Average score: 7.9<br>TMDB URL: https://www.themoviedb.org/movie/1402<br><br>Response:<br>{{<br>  &quot;summary&quot;: &quot;This movie is a perfect match for an inspired mood, showcasing the powerful journey of a man determined to build a better life for his son despite homelessness and hardship. Will Smith delivers a heartfelt performance in this emotionally uplifting story based on true events.&quot;,<br>  &quot;release_year&quot;: 2006,<br>  &quot;rating&quot;: 7.9,<br>  &quot;tmdb_link&quot;: &quot;https://www.themoviedb.org/movie/1402&quot;,<br>  &quot;top_stars&quot;: &quot;Will Smith, Jaden Smith, Thandiwe Newton, Brian Howe, James Karen&quot;<br>}}<br>&quot;&quot;&quot;</pre><p>This made it easy to render summaries in a clean UI.</p><h4>7. Displaying the Final Results</h4><p>The final suggestions are shown in a conversational layout using Markdown and HTML.</p><pre>from IPython.display import display, Markdown, HTML<br><br>def respond(state: AgentState) -&gt; AgentState:<br>    &quot;&quot;&quot;<br>    Displays the recommended items with descriptions and optional Gemini-generated summaries.<br>    <br>    :param state: Agent state with final recommendations<br>    :type state: AgentState<br>    :return: Agent state (unchanged or with display enhancements)<br>    :rtype: AgentState<br>    &quot;&quot;&quot;<br>    results = state[&quot;results&quot;]<br>    if not results:<br>        display(Markdown(&quot;😢 **Sorry, I couldn&#39;t find anything matching your mood on your platforms.**&quot;))<br>        return state<br><br>    display(Markdown(&quot;### That&#39;s what I picked for you:\n&quot;))<br><br>    for movie in results:<br>        title = movie[&#39;title&#39;]<br>        poster_url = f&quot;https://image.tmdb.org/t/p/w500{movie[&#39;poster_path&#39;]}&quot; if movie.get(&quot;poster_path&quot;) else &quot;&quot;<br><br>        # Get Gemini summary<br>        try:<br>            summary_data = summarize_match_with_grounding(movie, state[&quot;mood&quot;])<br>            summary_text = summary_data.get(&#39;summary&#39;)<br>            rating = summary_data.get(&#39;rating&#39;)<br>            release_year = summary_data.get(&#39;release_year&#39;)<br>            url = summary_data.get(&#39;tmdb_link&#39;)<br>            top_stars = summary_data.get(&#39;main_stars&#39;)<br>        except Exception as e:<br>            summary_text = &quot;_Could not generate summary with Gemini._&quot;<br>        <br>        top_stars_html = f&quot;&lt;p&gt;&lt;strong&gt;Top Stars:&lt;/strong&gt;&lt;br&gt;{top_stars}&lt;/p&gt;&quot; if top_stars else &quot;&quot;<br>        <br>        html = f&quot;&quot;&quot;<br>        &lt;div style=&quot;border: 1px solid #ddd; border-radius: 10px; margin-bottom: 20px; padding: 15px;&quot;&gt;<br>            &lt;div style=&quot;display: flex; flex-direction: row; gap: 20px;&quot;&gt;<br>                &lt;div style=&quot;flex: 1;&quot;&gt;<br>                    &lt;img src=&quot;{poster_url}&quot; width=&quot;200&quot; style=&quot;border-radius: 5px;&quot;&gt;<br>                &lt;/div&gt;<br>                &lt;div style=&quot;flex: 3;&quot;&gt;<br>                    &lt;h3 style=&quot;margin-top: 0;&quot;&gt;🎬 {title}&lt;/h3&gt;<br>                    &lt;p&gt;&lt;strong&gt;Rating:&lt;/strong&gt; {rating} | &lt;strong&gt;Released:&lt;/strong&gt; {release_year}&lt;/p&gt;<br>                    &lt;p&gt;&lt;strong&gt;Why I picked it:&lt;/strong&gt;&lt;br&gt;{summary_text}&lt;/p&gt;<br>                    {top_stars_html}<br>                    &lt;p&gt;&lt;a href=&quot;{url}&quot; target=&quot;_blank&quot;&gt;See more&lt;/a&gt;&lt;/p&gt;<br>                &lt;/div&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>        &quot;&quot;&quot;<br>        display(HTML(html))<br><br>    return state</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ighx9HlyVNdNaOpQwvfy_Q.png" /></figure><p>The user gets a clean, chat-like experience where every recommendation comes with a “why”, not just a title.</p><h3>What GenAI Capabilities I used</h3><p>This project allowed me to combine multiple core GenAI capabilities in a single workflow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rV3V9joK3FDsfCztkqkLcQ.png" /></figure><ul><li><strong>Embeddings + Vector Search</strong><br>I generated semantic vector representations using text-embedding-004 from Gemini and stored them in Chroma for similarity-based retrieval.</li><li><strong>Retrieval-Augmented Generation (RAG)</strong><br>Retrieved documents were passed as context into the LLM to generate grounded, context-aware outputs, following the standard index–retrieve–generate architecture.</li><li><strong>Grounding with Google Search</strong><br>I used Gemini’s integrated search tool to dynamically fetch accurate external information (e.g., cast) to enhance model responses and reduce hallucination.</li><li><strong>LangGraph Agents</strong><br>I structured the assistant using LangGraph to model a stateful multi-step conversation, with branching logic and memory between nodes.</li><li><strong>Few-Shot Prompting &amp; Structured Output</strong><br>I used in-context examples to teach Gemini how to generate structured JSON outputs, improving reliability and consistency of function responses.</li></ul><h3>What It looks like</h3><p>This is a full example using this application!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ITWo6yqCk6Ukec7fZWUrwQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SmQL14NxEx58XD9tyJVJdA.png" /></figure><h3>Experiments, findings &amp; what didn’t make the cut</h3><p>This project wasn’t built in a straight line, I experimented with a few approaches that didn’t quite make it into the final version. Here’s what I tried and what I learned:</p><h4>1. Gemini function calling: Powerful, but unpredictable</h4><p>I initially integrated Gemini’s native function calling with LangChain’s ChatGoogleGenerativeAI model. The idea was for the assistant to <em>automatically</em> call the movie recommendation function once it had all the user&#39;s preferences. And while it technically worked, in practice:</p><ul><li>The assistant sometimes skipped inputs or called tools too early (or not at all)</li><li>Couldn’t always reliably return the correct structure.</li><li>Debugging became time-consuming and frustrating</li></ul><p><strong>Lesson learned?</strong> For complex multi-step flows, having <em>explicit control</em> over the state (with LangGraph) beat out the magic of implicit function calls.</p><h4>2. I didn’t evaluate the summaries — yet</h4><p>Another feature I considered (and still might add later) was evaluating the quality of Gemini’s final movie recommendation summaries. While Gemini’s output was often great, I didn’t implement any automated mechanism to check:</p><ul><li>Was the tone right for the mood?</li><li>Did the summary really match the user’s preferences?</li></ul><p>I did evaluate the summaries manually though, and they looked good enough!</p><p>I loved building this assistant and experimenting with Google GenAI tools along the way. There’s still so much to improve and explore, and I’d love to keep pushing it further.</p><p>You can check out the full implementation and try it yourself in my <a href="https://www.kaggle.com/code/vandalos/movie-tv-show-recommender">Kaggle notebook</a>. If you have thoughts or ideas, I’d love to hear them!</p><p><strong>Here are a few more articles you might enjoy:</strong></p><ul><li><a href="https://itnext.io/understanding-prompt-engineering-how-to-talk-to-ai-3186ed68fc85">Understanding Prompt Engineering: How to Talk to AI</a></li><li><a href="https://itnext.io/how-machines-understand-meaning-a-guide-to-embeddings-vector-search-ce80356c584f">How machines understand meaning: A guide to Embeddings &amp; Vector Search</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1448af94647e" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/how-i-built-a-genai-movie-recommender-that-understands-you-1448af94647e">How I built a GenAI Movie Recommender that understands you</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Prompt Engineering: How to Talk to AI]]></title>
            <link>https://itnext.io/understanding-prompt-engineering-how-to-talk-to-ai-3186ed68fc85?source=rss-f1558d10c1f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/3186ed68fc85</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[prompt-engineering]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Vassiliki Dalakiari]]></dc:creator>
            <pubDate>Sun, 13 Apr 2025 17:41:26 GMT</pubDate>
            <atom:updated>2025-04-27T08:40:41.318Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eVRZF3-2fyjgnrveijKEkQ.jpeg" /></figure><p>If you are wondering what Prompt Engineering is, think it like you have a super smart assistant, but this assistant needs very clear instructions to do what you want. That’s kind of like working with a large language model (LLM), the technology behind many AI tools.</p><blockquote><strong>Prompt engineering</strong> is basically the art and science of giving these LLMs the right kind of instructions, or <strong>prompts</strong>, so they can understand what you need and give you accurate and useful results.</blockquote><p><strong>Think of a prompt as the input you give to the LLM, like a question or a request</strong>. Anyone can write a prompt, just like you can ask a friend a question. However, crafting the <em>best</em> prompt, one that really gets the LLM to understand and deliver what you’re looking for, can be a bit more involved. If your prompts aren’t clear, the LLM might give you answers that are vague, wrong, or just don’t make sense. That’s why <strong>prompt engineering is an iterative process,</strong> you might need to try different ways of phrasing your requests to get the best outcome.</p><h3>Different Ways to Ask: Prompting Techniques</h3><p>Lets explore various <strong>prompting techniques</strong> to help you get better results from LLMs. Here are some key ones:</p><ul><li><strong>General/Zero-Shot Prompting:</strong> This is the simplest form, where you just give the LLM a task description without any examples. For example, you could just ask, “Classify this movie review as positive or negative: ‘This film was amazing!’”.</li><li><strong>One-Shot &amp; Few-Shot Prompting:</strong> When zero-shot isn’t enough, you can provide examples in your prompt. A <strong>one-shot prompt</strong> has one example, while a <strong>few-shot prompt</strong> has several. These examples show the LLM the kind of output you’re looking for and help it follow a specific pattern. The number of examples you need depends on how complex the task is.</li></ul><pre>few_shot_prompt = &quot;&quot;&quot;Classify the movie review into valid JSON:<br><br>EXAMPLE:<br>One of the best shows ever made.<br><br>JSON Response:<br>```<br>{<br>&quot;sentiment&quot;: &quot;positive&quot;<br>}<br>```<br><br>EXAMPLE:<br>Poor acting.<br><br>JSON Response:<br>```<br>{<br>&quot;sentiment&quot;: &quot;negative&quot;,<br>}<br>```<br><br>REVIEW:<br>&quot;&quot;&quot;<br><br>review = &quot;This film was amazing!&quot;</pre><ul><li><strong>System, Contextual, and Role Prompting:</strong> These techniques help guide the LLM in different ways:<br>- <strong>System prompting</strong> sets the overall tone and purpose. For instance, you could start with <em>“You are a helpful assistant.”</em><br>- <strong>Contextual prompting</strong> provides specific background information relevant to the current task. For example, <em>“You are writing for a blog about travel experiences.”.</em><br>- <strong>Role prompting</strong> tells the LLM to act as a specific character or expert. You might say, <em>“Act as a code reviewer”</em>.</li><li><strong>Step-Back Prompting:</strong> To tackle complex problems, this technique involves first asking the LLM a general, related question to activate its broader knowledge before asking the specific task.<br>- Step back prompt:</li></ul><pre>What are five key principles that make a blog post about a complex technical <br>topic accessible and engaging for beginners?</pre><p><em>Step Forward Prompt:</em></p><pre>Context: 5 key principles to write a technical topic engaging for beginners:<br>- Use analogies and metaphors<br>- Avoid jargon or explain it simply<br>- Break down concepts step by step<br>- Add visuals or concrete examples<br>- Keep the tone friendly and curious<br><br>Based on the above principles, write a blog post that introduces the concept <br>of quantum computing to a beginner audience.</pre><ul><li><strong>Chain of Thought (CoT) Prompting:</strong> This helps the LLM with reasoning by prompting it to explain its thinking step-by-step. This can significantly improve accuracy for tasks that require logic.</li></ul><pre>When I was 4 years old, my partner was 3 times my age. Now,<br>I am 20 years old. How old is my partner? Let&#39;s think step by step.</pre><ul><li><strong>Self-Consistency:</strong> To get more reliable answers for reasoning tasks, this method involves asking the LLM multiple times using the CoT method often by using a different temperature, and then choosing the most common answer.</li><li><strong>ReAct (Reason &amp; Act):</strong> This powerful technique allows the LLM to not only reason but also to interact with external tools (like search engines or code interpreters) to gather more information and solve tasks.<br><em>See a full example of ReAct using Gemini </em><a href="https://github.com/google-gemini/cookbook/blob/main/examples/Search_Wikipedia_using_ReAct.ipynb"><em>here</em></a><em>.</em></li></ul><pre>model_instructions = &quot;&quot;&quot;<br>Solve a question answering task with interleaving Thought, Action, Observation <br>steps. Thought can reason about the current situation,<br>Observation is understanding relevant information from an Action&#39;s output and <br>Action can be one of three types:<br> (1) &lt;search&gt;entity&lt;/search&gt;, which searches the exact entity on Wikipedia and <br>     returns the first paragraph if it exists. If not, it will return some <br>     similar entities to search and you can try to search the information <br>     from those topics.<br> (2) &lt;lookup&gt;keyword&lt;/lookup&gt;, which returns the next sentence containing <br>     keyword in the current context. This only does exact matches, so keep <br>     your searches short.<br> (3) &lt;finish&gt;answer&lt;/finish&gt;, which returns the answer and finishes the task.<br>&quot;&quot;&quot;<br><br>example = &quot;&quot;&quot;Question<br>What is the capital city of Australia?<br><br>Thought 1<br>This is a simple factual question. I just need to search for the capital city <br>of Australia.<br><br>Action 1<br>&lt;search&gt;Capital of Australia&lt;/search&gt;<br><br>Observation 1<br>Canberra is the capital city of Australia. It is located in the Australian <br>Capital Territory and was selected as a compromise between Sydney and <br>Melbourne.<br><br>Thought 2<br>The observation clearly states that Canberra is the capital.<br><br>Action 2<br>&lt;finish&gt;Canberra&lt;/finish&gt;<br>&quot;&quot;&quot;<br><br>question = &quot;&quot;&quot;Question<br>What is the tallest mountain in Africa?<br>&quot;&quot;&quot;</pre><pre>Thought 1<br>I need to find the tallest mountain in Africa. I can use a search engine to <br>find this information.<br><br>Action 1<br>&lt;search&gt;tallest mountain Africa&lt;/search&gt;<br><br>Observation 1<br>Mount Kilimanjaro, with its three volcanic cones, Kibo, Mawenzi, and Shira, <br>is a dormant volcano in Tanzania. It is the highest mountain in Africa and <br>the highest single free-standing mountain above sea level in the <br>world: 5,895 metres (19,341 ft) above sea level. Kilimanjaro is the fourth <br>most prominent mountain on Earth.<br><br>Thought 2<br>The observation clearly states that Mount Kilimanjaro is the tallest mountain <br>in Africa.<br><br>Action 2<br>&lt;finish&gt;Mount Kilimanjaro&lt;/finish&gt;</pre><ul><li><strong>Automatic Prompt Engineering (APE):</strong> This explores using AI to automatically generate and evaluate different prompts to find the most effective ones.</li></ul><pre>We are training a voice assistant to handle scheduling requests. <br>Generate 10 different ways a user might say: <br>&#39;Schedule a meeting with Dr. Smith on Monday at 10 AM.&#39; <br>The meaning should stay the same, but the wording and phrasing can vary.</pre><ul><li><strong>Code Prompting:</strong> LLMs can also be used to work with code, helping with writing, explaining, translating, debugging, and reviewing code in various programming languages. <strong>Multimodal prompting</strong> is a related but separate area where you use different types of inputs (like text and images) to guide the LLM.</li></ul><pre>Write a Python script that asks the user for the name of a CSV file and a <br>column name. The script should read the CSV file, calculate the average of <br>the values in the specified column, and print the result. <br>Assume the column contains only numeric values.</pre><h3>Best Practices for Writing Great Prompts</h3><p>Lets see a set of <strong>best practices</strong> to help you become a better prompt engineer:</p><ul><li><strong>Provide examples</strong> in your prompts (one-shot or few-shot) whenever possible.</li><li><strong>Keep your prompts simple, clear, and easy to understand</strong>. Avoid complex language and unnecessary information.</li><li><strong>Be specific about the output you want</strong>. The more details you provide, the better the LLM can focus.</li><li><strong>Use instructions more than constraints</strong>. Tell the model what to do rather than what not to do, as positive instructions are often more effective.</li><li><strong>Control the maximum length of the output</strong> using the token limit or by explicitly asking for a certain length in your prompt.</li><li><strong>Use variables in your prompts</strong> to make them reusable and more dynamic.</li><li><strong>Experiment with different input formats and writing styles</strong> to see what works best.</li><li>For <strong>few-shot prompting with classification tasks, mix up the classes</strong> in your examples to <strong>avoid biasing</strong> the model.</li><li><strong>Adapt your prompts when models are updated</strong> to take advantage of new features.</li><li><strong>Experiment with structured output formats</strong> like <strong>JSON</strong> or <strong>XML</strong> for tasks like data extraction to get more consistent and easier-to-parse results.</li><li><strong>Document all your prompt attempts in detail</strong>, including the prompt itself, the model used, the configuration, and the output, to learn and track your progress.</li></ul><h3>Bonus Tip: Configure LLM’s output (in code)</h3><p>If you are using an LLM API, you can also <strong>configure how it generates its output</strong>. Two important aspects of this are:</p><ul><li><strong>Output Length:</strong> Meaning, how long the LLM’s response should be, by setting a limit on the number of <strong>tokens</strong> (which are like pieces of words) it can generate. This may be important, because generating more output uses more computer power and can take longer, so it’s good to be mindful of this. However, using this practice simply means that it just stops when it reaches the limit.</li><li><strong>Sampling Controls:</strong> LLMs don’t just pick one single next word, they predict probabilities for many possible words. <strong>Sampling controls</strong> like <strong>temperature</strong>, <strong>top-K</strong>, and <strong>top-P</strong> let you influence how the LLM chooses which word to use next, which affects how random or focused the output is.<br>- <strong>Temperature</strong> controls randomness. A <strong>low temperature</strong> makes the LLM more likely to pick the most predictable words, leading to more focused and deterministic responses (like when you need a factual answer). A <strong>high temperature</strong> makes it more adventurous, giving more diverse and creative (but sometimes less relevant) results.<br>- <strong>Top-K</strong> and <strong>top-P</strong> are ways to limit the choices of the next word to only the most probable ones. A <strong>lower top-K</strong> or <strong>top-P</strong> makes the output more focused, while a <strong>higher value</strong> allows for more variety.</li></ul><p>Choosing the right combination of these settings depends on what you’re trying to achieve. Sometimes, extreme settings of one control can even override the others.</p><h3>Conclusion</h3><p>In conclusion, prompt engineering is a must learn skill for effectively using large language models. The understanding of different prompting techniques, configuring of theLLM’s output, and following best practices, can help you significantly improve the accuracy and usefulness of the AI’s responses.</p><p>Remember that it’s often an <strong>iterative process</strong> of experimentation and refinement, so don’t be afraid to try different approaches to get the results you need.</p><p>If you want to learn more about the technical aspects of prompt engineering I recommend you to read the <a href="https://www.kaggle.com/whitepaper-prompt-engineering"><strong>Prompt Engineering Whitepaper by Google</strong></a><strong>.</strong></p><p><strong>Here are a few more articles you might enjoy:</strong></p><ul><li><a href="https://itnext.io/how-machines-understand-meaning-a-guide-to-embeddings-vector-search-ce80356c584f">How machines understand meaning: A guide to Embeddings &amp; Vector Search</a></li><li><a href="https://itnext.io/how-i-built-a-genai-movie-recommender-that-understands-you-1448af94647e">How I built a GenAI Movie Recommender that understands you</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3186ed68fc85" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/understanding-prompt-engineering-how-to-talk-to-ai-3186ed68fc85">Understanding Prompt Engineering: How to Talk to AI</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Big O Notation in AI/ML: How It Can Make or Break Your Project]]></title>
            <link>https://itnext.io/big-o-notation-in-ai-ml-how-it-can-make-or-break-your-project-e355f3d2126c?source=rss-f1558d10c1f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e355f3d2126c</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[time-complexity]]></category>
            <dc:creator><![CDATA[Vassiliki Dalakiari]]></dc:creator>
            <pubDate>Thu, 12 Sep 2024 22:09:19 GMT</pubDate>
            <atom:updated>2024-09-12T22:09:19.867Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BM1vyavShulLemdwpmeGaA.png" /></figure><p>As a professional in AI and ML, I’ve seen firsthand how crucial algorithm efficiency is to the success of large-scale projects. Understanding the computational demands of your algorithms can save both time and resources, and one of the best ways to gauge this efficiency is through <strong>Big O notation</strong>.</p><p>At first glance, <strong>Big O</strong> might seem like an abstract concept. However, when applied to everyday AI/ML tasks like <a href="https://medium.com/itnext/feature-engineering-in-xgboost-a-practical-guide-7fbafa7dbdbd">feature engineering</a>, training models, performing inference, and processing data, it becomes an invaluable tool.</p><p>In this article, I’ll explain how I’ve used <strong>Big O</strong> to optimize AI/ML workflows and why it’s super important for any expert in the field.</p><h3>What Is Big O Notation?</h3><blockquote>Shortly, Big O<strong> notation</strong> is a way of describing how the runtime or space requirements of an algorithm increase as the size of the input data grows.</blockquote><p>It provides a high-level understanding of an algorithm’s efficiency, allowing you to predict how it will behave when faced with larger datasets.</p><p><strong>For example, let’s say that you want to sort a list of names in a class. <br></strong>If the class has <strong>10 students</strong>, sorting the names manually takes no time at all. But what if you had <strong>1000 students</strong>? Or <strong>1 million</strong>? <br>The time it takes to sort grows along with the number of names, and this growth can be modeled using Big O notation.</p><p>Common time complexities include:</p><ul><li><strong>O(1)</strong>: Constant time — no matter the size of the input, the time remains the same.</li><li><strong>O(n)</strong>: Linear time — the time grows in direct proportion to the size of the input.</li><li><strong>O(log n)</strong>: Logarithmic time — the time increases, but at a decreasing rate as the input grows.</li><li><strong>O(n²)</strong>: Quadratic time — the time grows rapidly as the input size increases.</li></ul><h3>Application to AI/ML Tasks</h3><p>Let’s move beyond theory and dive into how Big O applies to the kinds of tasks we perform in AI and ML.</p><h4>Training Machine Learning Models</h4><p>When training machine learning models, understanding the time complexity of the algorithms you’re using is key to selecting the right approach. For example:</p><ul><li><a href="https://en.wikipedia.org/wiki/Decision_tree"><strong>Decision Trees</strong></a>: have a time complexity of <strong>O(n * m * log n) </strong>during training, where <strong>n</strong> is the number of samples, <strong>m</strong> is the number of features, and <strong>log n</strong> reflects the depth of the tree. This means that as both the number of training examples and features increase, the training time grows proportionally. This is <strong>relatively efficient</strong> but can slow down with high-dimensional data.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YxyFb-e9B5gZiTfOpZ-kpw.png" /><figcaption>Example of decision tree</figcaption></figure><ul><li><strong>Support Vector Machines (</strong><a href="https://en.wikipedia.org/wiki/Support_vector_machine"><strong>SVMs</strong></a><strong>)</strong> have a training time complexity of <strong>O(n² * m)</strong>. For large datasets, this quadratic growth in time complexity means that SVMs can take significantly longer to train compared to decision trees, especially when there are many data points (n). However, they perform very well on smaller datasets or when high accuracy is essential.</li></ul><figure><img alt="Support Vectors in SVM: Apples vs Oranges Classification" src="https://cdn-images-1.medium.com/max/1024/1*Dv2a-ZFgjs7KGMXdf9-gEQ.png" /><figcaption>Support Vectors in SVM: Apples vs Oranges Classification</figcaption></figure><blockquote>Think of it like cooking. If you’re preparing a meal for 5 people, it’s manageable, but if you had to cook for 500, the time and effort needed would increase exponentially. Some recipes (algorithms) scale better than others.</blockquote><h4>Inference and Prediction</h4><p>Once a model is trained, it’s time to make predictions or inferences. Here, Big O notation helps us understand how quickly we can make those predictions. For instance:</p><ul><li><strong>Linear Regression</strong> has an <strong>O(n)</strong> complexity during inference, meaning the time it takes to make a prediction increases linearly with the number of data points. In everyday terms, imagine scanning a list to find an item. As the list grows, the time it takes grows too, but at a predictable rate.</li><li>In contrast, <strong>Decision Trees</strong> have a time complexity of <strong>O(log n)</strong> during inference. This means that even as your dataset grows, the prediction time doesn’t increase as drastically. <br><em>It’s like searching through a phone book: you can skip whole sections instead of going name by name, making it much faster.</em></li></ul><h4>Data Preprocessing</h4><p>Before you even begin training your model, there’s often a lot of work to be done on the data itself. Tasks like cleaning and sorting data, selecting features, and reducing dimensionality can all be explained through Big O notation.</p><p>For instance, <strong>Sorting Algorithms</strong> are a fundamental part of data preprocessing, especially if you need to order data before feeding it into a model. The best sorting algorithms, like <strong>Merge Sort</strong>, have a time complexity of <strong>O(n log n)</strong>, making them efficient for large datasets.</p><blockquote>Let’s say that you have to organizing a bookshelf. If the books are already somewhat ordered, the task is easier (like a <strong>logarithmic growth</strong>). But if the books are in complete disarray, the task will take far longer, like <strong>linear</strong> or even <strong>quadratic</strong> time complexity.</blockquote><h3>Time Complexity Examples of Search Algorithms</h3><p>To demonstrate the importance of Big O notation in AI/ML tasks, let’s look at two common search algorithms: <strong>Linear Search — O(n)</strong> and <strong>Binary Search — O(log n)</strong>. We’ll use a sorted array with 1 million elements and measure the time taken to find a target value.</p><h4>Linear Search — O(n)</h4><p>Linear Search checks each element one by one until it finds the target.</p><pre>def linear_search(arr, target):<br>    for i in range(len(arr)):<br>        if arr[i] == target:<br>            return i<br>    return -1</pre><ul><li><strong>Time taken</strong>: 0.023035 seconds.</li></ul><h4>Binary Search — O(log n)</h4><p>Binary Search divides the search space in half with each step, making it far more efficient for large datasets.</p><pre>def binary_search(arr, target):<br>    low = 0<br>    high = len(arr) - 1<br>    while low &lt;= high:<br>        mid = (low + high) // 2<br>        if arr[mid] == target:<br>            return mid<br>        elif arr[mid] &lt; target:<br>            low = mid + 1<br>        else:<br>            high = mid - 1<br>    return -1</pre><ul><li><strong>Time taken</strong>: 0.000024 seconds.</li></ul><blockquote>As we see at the example, <strong>Binary Search</strong> is about <strong>960 times faster</strong> than Linear Search for this dataset, highlighting how choosing the right algorithm can significantly impact performance, especially with large datasets.</blockquote><h3>Why Big O Matters in AI/ML</h3><p>Big O notation isn’t just academic or an interviews trap. It has real-world implications for the scalability and efficiency of AI and ML systems. In my experience, it’s especially critical in the following areas:</p><ul><li><strong>Handling Large Datasets</strong>: In modern AI/ML, datasets are often enormous, containing millions of entries. Choosing algorithms with lower time complexities ensures that your systems can handle this data efficiently without having it run forever.</li><li><strong>Optimizing Model Performance</strong>: When you’re working with limited resources, selecting algorithms with lower space complexity can save valuable memory. For instance, understanding that a deep neural network may have an <strong>O(n*m)</strong> complexity can help you make more informed decisions about the model architecture.</li><li><strong>Improving Resource Efficiency</strong>: Computational resources cost money, whether you’re working in a cloud environment or with on-premise hardware. Algorithms with better performance can save you time and, ultimately, cuts down on costs.</li></ul><h3>Conclusion</h3><p>Understanding <strong>Big O</strong> notation and applying it to AI/ML tasks has allowed me to become more efficient and strategic in my projects. By understanding how algorithm efficiency affects training, inference, and data preprocessing, I’ve been able to avoid bottlenecks and build more scalable systems.</p><p>My advice? The next time you’re faced with a choice between two algorithms or preprocessing methods, take a moment to consider their time and space complexities — it might just make all the difference in your project’s success.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e355f3d2126c" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/big-o-notation-in-ai-ml-how-it-can-make-or-break-your-project-e355f3d2126c">Big O Notation in AI/ML: How It Can Make or Break Your Project</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>