RAG In Detail

In my previous post I walked through a RAG example but glossed over the details. In this post I’ll back up and provide the details.

The key steps in RAG are

  • Load the data
  • Split the text into smaller chunks to fit within context limits
  • Create a Document object
  • Embed the document in vectors that represent semantic meaning
  • Store the document—typically in vector stores. These are databases designed to store embeddings and provide fast semantic retrieval
  • Invoke a retriever to query the back end to return the most relevant Document object
  • Create a prompt for the LLM
Continue reading
Posted in AI, Essentials, Python | Tagged , | Leave a comment

RAG – A Quick Example

In the previous blog post, we imported a few Python modules and configured our AI key, using Colab.

In this blog post we’ll use Retrieval-Augmented Generation (RAG) to extend an LLM that we’ll get from OpenAI. I’ll use a number of features from the libraries we imported with only a cursory explanation and will come back to them in upcoming blog posts to examine them in more depth. But I want to get to RAG right away because it is rapidly becoming central to AI and because it is cool.

LLMs are incredibly expensive to create and train, and it isn’t feasible to train them on everything. Besides that, much data is proprietary. It may be that you want an LLM that handles (to use the canonical case) your HR policies. Clearly no commercial LLM knows about those policies, nor should they. And equally clearly, you’re not going to train an LLM from scratch. What you want to do is to combine your own corpus of data (HR policy papers, etc.) with an existing LLM, and that is exactly what RAG is for.

In this simple example, we’re going to take a scene or two from Romeo and Juliet and feed it to gpt-40-mini; one of many LLMs available for use at minimal cost (we’ll get into how cost is computed in an upcoming post).

The first thing we’ll do after configuring the OPEN_API_KEY will be to get a TextLoader to import the text file with the scenes from Romeo and Juliet

Continue reading
Posted in AI | Tagged , , | Leave a comment

Creating Our Python AI Project

As noted in a previous blog post, we’ll be building our project on two platforms: Python and .NET (C#). For Python, we’ll build on Colab. For now, you can use a free account.

The first step is to get an OpenAI key, as described in this previous blog post (scroll to the bottom). Note, these are not free, but we’re talking a few dollars for this entire series of posts.

Continue reading
Posted in AI | Tagged , , | Leave a comment

Mads Torgersen

Mads (Lead Designer of C#) joins me to discuss C# and AI as well as what to expect in C# 15.

Podcast
Video

Posted in Essentials | Leave a comment

Distributed Computing & Docker

Joe Dluzen joins me to discuss, in depth, distributed computing and Docker.

The podcast is here and the video is here.

Posted in Essentials | Leave a comment

Microsoft Agent Framework – Part 0

I’ve been looking at a number of different ways to build Agents. I’ve settled on two and will be documenting what I learn as I go:

  • Building from first principles based on my course on Agentics at Johns Hopkins
  • Building using Microsoft’s new Agent Framework

The advantage of the first is that you understand the underlying mechanisms in more depth; the advantage of the second is that a lot of the plumbing is done for you and you become more productive more quickly.

I will do the .NET work in C#, and probably do all the other work in Python. See my blogpost on why Python.

I will, to a degree, be documenting what I learn as I learn it, without infringing on copyright, of course.

Continue reading
Posted in Essentials | Leave a comment

AI: The Near Term

As promised, I’ll be posting slides and commentary from my recent user-group presentation on AI (Boston Code Camp). One of my first slides talked about the near-term evolution of AI, defined as either 1-2 years or 6 months, depending on who you believe.

I divided the slide into two parts: good news and bad. The good news is the promise of enormously increased productivity, which may well lead to a higher standard of living across the board. Further, as AI progresses, we may see accelerated breakthroughs in many fields, most notably medicine and genetics.

Continue reading
Posted in Essentials | Leave a comment

MCP In Depth

In a special videoCast, Lance McCarthy of Progress Software dives deep into MCP, not only explaining what it is for and how it works, but demonstrating, in code, how it is done.

MCP (Model, Context, Protocol) is an open standard that lets AI models (read copilot, ChatGPT, etc.) connect to external tools. These tools can be databases, code you write, code you connect to, other AIs, etc. etc. It is the universal API for Agents.

Here’s a link to the code.

Posted in Essentials | Leave a comment

Get on the bus, or get run over by it

On March 28 I’m presenting on Fundamentals of AI to the Boston Code Camp. While I will cover what you need to know about the various aspects of using and creating various AI components, the key message is it is time. It is time to start developing and honing your AI skills, or as I say in the title, you will be run over by the AI bus.

After the presentation, I’ll cover a lot of that material here, but to get us started let’s talk about the two ways you’ll care about AI.

  1. Using AI to aid you in your coding
  2. Creating applications that incorporate AI
Continue reading
Posted in AI | Leave a comment

Boston Code Camp

Posted in Essentials | 9 Comments

HyperVideo – GitHub Issues

In examining my HyperVideo project I decided that the Bunny video was a great placeholder, but what I really wanted was my own videos. What better place to start than the videos I have up on YouTube. How am I going to do that?

To get started, I asked CoPilot what it would take. CoPilot generated a plan of action. I took that and opened an issue on GitHub which will document what I have to do.

Continue reading
Posted in Essentials | 1 Comment

copilot-instructions.md

When working with CoPilot in Visual Studio, the single most important thing is context. Context tells CoPilot what it is working on, what it should already know, what language conventions to use, etc., etc. CoPilot wants to help, but its memory is not the best, and like the character in Memento, the trick is to write everything down and remind it all the time… hence context.

The best way to get ahead of this is to create a copilot-instructions.md file in your .github directory (which you may need to create). In this file, you’ll want to put anything that CoPilot should know right from the get-go and for every session.

But how do you know what to put in there?

Continue reading
Posted in Essentials | 7 Comments