The Anatomy of a GenAI System - Part 6

Eric Famanas

~5 min read

With all the Studio Ghilbi-style shenanigans going on, I just had to

At long last, we have finally come to the end of our journey, that is, from the perspective of a GenAI system. There are many, many more things to consider when it comes to infrastructure, network optimisation, traffic management, user experience, testing, cybersecurity... the list goes on and on! As much as I would love to continue on and help you design an entire full-stack, GenAI application, a certain degree is disciplined to keep us on track for the original purpose of this mini-series: to demystify the anatomy of a GenAI system so stakeholders and project managers can ask the right questions and make informed decisions.

A recap from Part 5

In the previous entry in this series, we took a look a look at publicly-available or open-source language learning models (LLMs) that are typically used in more popular GenAI systems. While these models are easily accessible, and can seemingly do a lot of things, they may not necessarily be specialised enough to carry out specific tasks such as reviewing legal documentation or understanding the local context using ubiquitous language.

Instead of directly altering the LLM, which would break best-programming practices of having reusable components and implementations, we instead discussed on how we can apply an additional layer of speciality such as locally downloading the general-purpose LLM and applying a Low-Rank Adaptation (LoRA) to be able to refine the generated output to make it more refined to the user's expectations. Intelligent, thoughtful prompting and LoRA's designed against domain-specific data will yield better results than general-purpose LLM's.

But is there more we can do?

What is RAG?

In this final entry, we will cover retrieval-augmented generation, commonly known as RAG. But first, a diversion.

Why do I always ask ChatGPT first and then provide my own thoughts? Why not just use only ChatGPT-generated content or my own, human-generated content?

When we talk about AI, why not ask the AI what it thinks of itself? When we discuss the benefits of AI to our daily challenges, why not have a proper exchange of ideas instead of relying on a single source of information? I think it's important to have this discourse, because an informed decision means looking at all viewpoints, not just one. Anyway, let's continue....

Per ChatGPT 4o, RAG can be described as:

RAG in the context of AI stands for Retrieval-Augmented Generation. It’s a technique that combines retrieval-based and generation-based models to improve the quality and relevance of responses in tasks like question answering or conversational AI.

Here’s how it works:

1. Retrieval:

First, the model retrieves relevant documents or information from an external source, like a knowledge base, database, or set of documents. This step helps ground the response in factual, up-to-date information.

2. Augmentation:

The retrieved documents are then fed into a language model (like GPT) as context. This way, the model has access to more specific or external knowledge than just what it was trained on.

3. Generation:

Finally, the model generates a response using the retrieved content to ensure it’s more accurate, informed, and relevant.

Looking at ChatGPT's interpretation as RAG, we can liken the exchange to asking the average person to tell me about a particular topic, such as a EULA, but instead of directly expecting a response founded on broad information, we first provide that individual with the necessary documentation and background information to deliver a more precise, appropriate response.

When taking these descriptions into consideration, a RAG-centric GenAI application may end up looking like this:





A simplified architecture of a RAG interaction within a GenAI system

A simplified architecture of a RAG interaction within a GenAI system

"The main benefit of using RAG as part of the GenAI process is that it reduces the risk of assumptions or hallucinations delivered within an LLM's response."

When we take this statement into consideration, the benefits of using RAG techniques are apparent, especially when considering GenAI applications that consume a user enquiry, or a prompt, and are expected to give a response. Just like when searching for answers using a search engine like Google, it is very likely that the user may take the first few outputs and take that as truth. What is even worse about the situation is with AI, however, is that all the source data is obfuscated within its black box- processing, so the user is only given one answer, regardless of its truthfulness. This is why techniques like RAG, and further still regulation, is so important as we innovate and evolve our AI technologies.

RAG vs LoRA? Or why not both?

Often times I read about the dichotomy of RAG vs LoRA, and even ChatGPT was kind enough to produce a table comparing the two techniques:



How ChatGPT 4o compares some GenAI refinement techniques

How ChatGPT 4o compares some GenAI refinement techniques

However, these two techniques are not mutually exclusive, and actually, both can be used within the same process:





An idea of using both LoRA and RAG within the same system

An idea of using both LoRA and RAG within the same system

However, does this really make sense? Considering that you would end up having to account for the negatives, the biggest being development, training, processing and network latency just for an unknown benefit, i.e. how much more accurate would our EULA-analyser system be if we did introduce these techniques side by side, and is it worth the extra cost?

Unfortunately, that is ultimately a business decision, and it needs to be taken carefully on a case by case basis. But ultimately, as a stakeholder, as a project manager, or even someone who is curious about building their own GenAI system, are responsible for even having the most fundamental knowledge to make these kinds of decisions. However, this does not mean there are some quick wins that can be gleaned from knowing what we know now:


  • Network latency can be reduced by having the RAG process run alongside the LoRA model on the user's machine instead of a remote server, so the only thing being transmitted over the wire is the generic prompt call. There are actually full-blown games like InZoi that do this.

  • Development time can be parallelised (and shortened) by breaking down the machine learning development and training tasks using good agile development methods through technology mapping using domain driven design.

  • Understanding time complexity of the different functions involved can help estimate amount and types of IaaS provisioned resources needed to deliver a distributed, efficient application.


So What Is Coming Next?

We are just dipping our toes with this mini-series! In the next story arc of the Coding Carpenter, we finally get back to the original intent of this blog series: Coding for Carpentry! As I mentioned in one of the earlier posts, one of my intentions is to start coding a GPT-type or LLM assistant on creating a woodworking assistant that will advise myself, and hopefully others, along their carpentry journey. I hope to see you all then!

Systems Orchestrator

CTO · Technology leadership