The Anatomy of a GenAI System - Part 5
Eric Famanas
~6 min read

A recap from Part 4
In part 4, we started on our journey in applying an actual use case to the theories behind designing a GenAI system, specifically around a use case wherein the user would like to query the contents of a EULA to gain insights and direction. To help recap, I am reposting the use case diagram that was shared:

A high-level use case diagram for a chatbot with an AI backend
During this discussion, we covered in greater detail the first two steps of the ETL (extract, transform, and load) pipeline and what specifically are involved in those steps to create a robust, and legally compliant, GenAI system to deliver to customers. Despite the process being summarised into a neat acronym, the data ingestion pipeline is incredibly complex with many things to consider. Hopefully this discussion continues to empower decision makers and project managers on what to look for when either making the decision to create a GenAI product or seeking vendors to fill their operational gaps.
Continuing on with the mini-series, we have finally reached the loading step of the ETL pipeline and are making the final designs to the system that will accept user input and produce a result. However, it's not as simple as slapping on an interface to our data lake and just dump everything into an LLM. Part 5 and Part 6 of this mini-series will cover some important load and generation refinement concepts around GenAI systems.
The elephant in the room: why do we need all this data?
In the previous articles, there was a lot of discussion around data ingestion and storage, with the main theme around collecting user data, generating rulesets and fine-tuning high-level GPT's or internally creating single-purpose LLM's within the system. But why? Can't we just pass the text straight through to something like DeepSeek and get a result out of it without all this extra architecture?
This is where the "silver bullet myth of AI" finally gets put to rest:
"Current AI systems are not general AI systems; they cannot be assigned generic tasks and produce results within user expectations. They are still single-purpose processes that need to be fine tuned for optimum results".
There is a misconception that we can plug anything into an LLM and get a result; there are even numerous posts around social media and even actual articles that "software engineers will be replaced by AI within the next six months." There is no empirical evidence to support these statements, and in reality, further refinement is necessary to get an LLM to perform well against a targeted use case. And as we have emphasised over and over again, we need data to make these adjustments.
We have justified the collection of this data, and now that we have all this data, where do we go next? Where in the application's architecture should this fine-tuning function sit?
A Function Called LoRA
The subheading is a play on words from the film "A Fish Called Wanda", but that's where the analogy ends. Instead, we are going to talk about one solution called LoRA, or low-rank adaption techniques.

Your spelling in illustrations never ceases to amaze me, ChatGPT 4o.
To go with this lovely image, I have asked ChatGPT to define what LoRA is with respect to... well... itself!
LoRA is a parameter-efficient fine-tuning technique that allows you to adapt large pre-trained models to new tasks without updating the entire model’s parameters. Instead, it introduces small, trainable matrices into the model, which capture task-specific adjustments. The main idea is based on low-rank decomposition, which reduces the number of parameters needed during training while maintaining performance.
Why is LoRA used?
Efficiency: Fine-tuning large models is expensive (millions to billions of parameters). LoRA allows fine-tuning by training a much smaller set of parameters.
Speed & Memory Savings: Since only small matrices are updated, memory and computational overhead is significantly lower.
Preservation of Base Model: The original model remains untouched, so you can easily switch between tasks or revert to the base model without retraining.
How does LoRA work?
Original Model: Let’s say the model has large weight matrices (e.g., W) in its layers.
Low-Rank Adaptation: Instead of updating W, LoRA adds two smaller matrices A and B such that: W{\prime} = W + A \times B, where A and B are of lower rank (small size), and only they are trained.
Fine-Tuning: You train A and B on your specific dataset, leaving W frozen.
Where is LoRA applied?
Natural Language Processing (NLP): Adapting large language models like GPT, BERT for specific tasks (e.g., sentiment analysis, translation).
Computer Vision: Fine-tuning vision transformers.
Multimodal Models: Such as image + text models.
Thank you very much for the commentary, ChatGPT!
After reviewing the brief description, hopefully it is obvious that our GenAI application, the ingestion and processing of user queries to interpret content contained within EULA's, could benefit from taking advantage of a LoRA technique given that its primary functions revolve around natural language processing (NLP).
So when we consider taking advantage of our own data and applying LoRA functions to refine the output generated by one or more LLM's, what would that look like on the system architecture side? To help us move along, here are some diagrams from a blog on DagsHub:

Fine-tuning workflow:

Regular vs LoRA-based tuning:
Okay, I threw some diagrams in here that may not be easily understood within the context of discussion, but it will make sense with the next couple of diagrams based on our use case:

The use case diagram from before, but with the tuner explicitly annotated
Going into further, technical detail, and taking inspiration from an article on AWS, which draws from AI Engineering: Building Applications with Foundation Models (lesson code available on Github), we can use the use case diagram from above and imagine how a LoRA implementation may look within our system.

LoRA Training Phase
In the above diagram, we are sourcing 80% of the data we collected from the data ingestion pipeline and providing that to the neural network that will eventually output the LoRA. The ML should be using the actual EULA documentation we will be reviewing and training itself from the interpretation data provided by domain experts and user feedback. After it is deemed the model is sufficiently trained, it is then tested against the remaining 20% of the data to determine its success score. Why? Because of something I heard once:
"We should never trust AI to give a binary answer and expect 100% accuracy. The answers an AI system gives should be accompanied with a level of confidence that is eventually given to a human to make a final decision."
Taking the statement into consideration, there are two evaluators involved in this process: the lead engineer responsible for the development of the system and the product manager to compare the result against their domain knowledge. In this setup, both the decision maker, the PM, and the engineers are mutually aware of the scoring and weights, giving a further layer of transparency and audit-ability to our GenAI system.
The end is in sight!
Now that we have a LoRA to further refine and improve the output of a generic LLM, thus turning it into something more specialised for our needs (i.e. our own pocket lawyer!) surely we must be ready to unleash this beast of a product into society correct? Or further still, do project managers and stakeholders now have a better understanding on how to identify a generic, thin-client LLM vs something that has a real and viable value?
There is just one more piece to this puzzle that will help make this system both performant and more accurate in the data loading process: retrieval augmented generation (RAG). (And YES, we are still talking about the ETL pipeline) Are both LoRA's and RAGs necessary in the same system? No. But we should perform due diligence to understand both and how they can improve our GenAI system. I hope to see you next time for the final stretch!