RAG vs Fine-Tuning vs Prompt Engineering: Optimizing AI… — Transcript

Explore RAG, fine-tuning, and prompt engineering to optimize AI model responses with IBM technology insights.

Key Takeaways

  • RAG is best for incorporating fresh, domain-specific data dynamically but has higher latency and infrastructure costs.
  • Fine-tuning is ideal for deep domain expertise with faster responses but requires significant training effort and resources.
  • Prompt engineering is a low-cost method to improve outputs by carefully designing queries without retraining or external data.
  • Each method has trade-offs in complexity, cost, and performance depending on the use case.
  • Understanding these approaches helps optimize AI model deployment for specific organizational needs.

Summary

  • The video compares three methods to improve large language model outputs: Retrieval Augmented Generation (RAG), fine-tuning, and prompt engineering.
  • RAG enhances responses by retrieving up-to-date, domain-specific information using vector embeddings and incorporating it into the query.
  • Fine-tuning involves additional training of a pre-trained model on specialized datasets to embed domain expertise directly into model weights.
  • Prompt engineering improves outputs by crafting precise queries that guide the model’s attention without additional training or data retrieval.
  • RAG is valuable for real-time, domain-specific info but adds latency and infrastructure costs due to retrieval and vector storage.
  • Fine-tuning offers faster inference and deep domain knowledge but requires extensive training data, computational resources, and risks catastrophic forgetting.
  • Prompt engineering is cost-effective and flexible but depends on the skill of query formulation to direct model reasoning effectively.
  • RAG uses semantic search via vector embeddings rather than keyword matching to find relevant documents.
  • Fine-tuning modifies model parameters through supervised learning with input-output pairs to improve domain-specific accuracy.
  • Prompt engineering leverages attention mechanisms in the model to highlight relevant patterns learned during training.

Full Transcript — Download SRT & Markdown

00:00
Speaker A
Remember how back in the day people would Google themselves, you type your name into a search engine.
00:08
Speaker A
And you see what it knows about you. Well, the modern equivalent of that is to do the same thing with a chatbot.
00:13
Speaker A
So when I ask a large language model, who is Martin Keen, well, the response varies greatly depending upon which model I'm asking.
00:22
Speaker A
Because different models, they have different training data sets, they have different knowledge cut off dates, so what a given model knows about me, well, it differs greatly.
00:32
Speaker A
But how could we improve the model's answer?
00:36
Speaker A
Well, there's three ways, so let's start with a model here, and we're going to see how we can improve its responses.
00:44
Speaker A
Well, the first thing it could do is it could go out and it could perform a search, a search for new data that either wasn't in its training data set, or it was just data that became available after the model finished training.
00:58
Speaker A
And then it could incorporate those results from the search back into its answer.
01:05
Speaker A
That is called RAG, or retrieval augmented generation.
01:11
Speaker A
That's one method.
01:12
Speaker A
Or we could pick a specialized model, a model that's been trained on, let's say, transcripts of these videos.
01:20
Speaker A
That would be an example of something called fine tuning.
01:24
Speaker A
Or we could ask the model a query that better specifies what we're looking for.
01:30
Speaker A
So maybe the LLM already knows plenty about the Martin Keens of the world, but let's tell the model that we're referring to the Martin Keen who works at IBM, rather than the Martin Keen that founded Keen shoes.
01:39
Speaker A
That is an example of prompt engineering.
01:43
Speaker A
Three ways to get better outputs out of large language models, each with their pluses and minuses.
01:49
Speaker A
So let's start with RAG.
01:51
Speaker A
So let's break it down, first there's retrieval.
01:55
Speaker A
So retrieval of external up-to-date information.
01:58
Speaker A
Then there's augmentation, that's augmentation of the original prompt.
02:02
Speaker A
With the retrieved information added in, and then finally there's generation.
02:07
Speaker A
That's generation of a response based on all of this enriched context.
02:11
Speaker A
So we can think of it like this.
02:15
Speaker A
So we start with a query, and the query comes in to a large language model.
02:20
Speaker A
Now, what RAG is going to do is it's first going to go searching through a corpus of information.
02:27
Speaker A
So we have this corpus here full of some sort of data.
02:32
Speaker A
Now, perhaps that's your organization's documents, so it might be spreadsheets, PDFs, internal wikis, you know, stuff like that.
02:38
Speaker A
But unlike a typical search engine that just matches keywords, RAG converts both your question, the query, and all of the documents into something called vector embeddings.
02:50
Speaker A
So these are all converted into vectors.
02:54
Speaker A
Essentially turning words and phrases into long lists of numbers that capture their meaning.
03:00
Speaker A
So when you ask a query like, what was our company's revenue growth last quarter?
03:07
Speaker A
Well, RAG will find documents that are mathematically similar in meaning to your question, even if they don't use the exact same words.
03:16
Speaker A
So it might find documents mentioning fourth quarter performance or quarterly sales.
03:22
Speaker A
Those don't contain the keyword revenue growth, but they are semantically similar.
03:27
Speaker A
Now, once RAG finds the relevant information, it adds this information back into your original query.
03:35
Speaker A
Before passing it to the language model.
03:38
Speaker A
So instead of the model just kind of guessing based on its training data, it can now generate a response that incorporates your actual facts and figures.
03:46
Speaker A
So this makes RAG particularly valuable when you are looking for information that is up-to-date.
03:53
Speaker A
And it's also very valuable when you need to add in information that is domain specific as well.
03:59
Speaker A
But there are some costs to this.
04:01
Speaker A
Let's get with the red pen, so one cost that would be the cost of performance for performing all of this.
04:07
Speaker A
Because you have this retrieval step here, and that adds latency to each query compared to a simple prompt to a model.
04:14
Speaker A
There are also costs related to just kind of the the processing of this as well.
04:20
Speaker A
So if we think about what we're having to do here, we've got documents that need to be vector embeddings.
04:28
Speaker A
And we need to store these vector embeddings in a database.
04:33
Speaker A
All of this adds to processing costs, it adds to infrastructure costs to make this solution work.
04:38
Speaker A
All right, next up, fine tuning.
04:40
Speaker A
So remember how we discussed getting better answers about me by training a model specifically on, let's say, my video transcripts?
04:47
Speaker A
Well, that is fine tuning in action.
04:50
Speaker A
So what we do with fine tuning is we take a model.
04:56
Speaker A
But specifically an existing model.
05:00
Speaker A
And that existing model has broad knowledge.
05:03
Speaker A
And then we're going to give it additional specialized training on a focused data set.
05:09
Speaker A
So this is now specialized to what we want to develop particular expertise on.
05:14
Speaker A
Now, during fine tuning, we're updating the model's internal parameters through additional training.
05:20
Speaker A
So the model starts out with some weights here.
05:24
Speaker A
And those weights were optimized during its initial pre-training.
05:29
Speaker A
And as we fine tune, we're making small adjustments here to the model's weights using this specialized data set.
05:37
Speaker A
So this is being incorporated.
05:43
Speaker A
Now, this process typically uses supervised learning, where we provide input-output pairs that demonstrate the kind of responses we want.
05:50
Speaker A
So, for example, if we're fine tuning for technical support, we might provide thousands of examples of customer queries.
05:58
Speaker A
And those would be paired with correct technical responses.
06:02
Speaker A
The model adjusts its weights through back propagation to minimize the difference between its predicted outputs and the targeted responses.
06:09
Speaker A
So we're not just teaching the model new facts here, we're actually modifying how it processes information.
06:16
Speaker A
The model is learning to recognize domain specific patterns.
06:20
Speaker A
So fine tuning shows its strengths when you particularly need a model that has very deep domain expertise.
06:26
Speaker A
That's what we can really add in with fine tuning.
06:30
Speaker A
And also, it's much faster specifically at inference time.
06:35
Speaker A
So when we are putting the queries in, it's faster than RAG because it doesn't need to search through external data.
06:40
Speaker A
And because the knowledge is kind of baked into the model's weights, you don't need to maintain a separate vector database.
06:45
Speaker A
But there are some downsides as well.
06:47
Speaker A
Well, there's certainly issues here with the training complexity of all of this.
06:52
Speaker A
You're going to need thousands of high quality training examples.
06:57
Speaker A
There are also issues with computational cost.
07:02
Speaker A
The computational cost for training this model can be substantial and it's going to require a whole bunch of GPUs.
07:07
Speaker A
And there's also challenges related to maintenance as well.
07:13
Speaker A
Because unlike RAG where you can easily add new documents to your knowledge base at any point, updating a fine-tuned model requires another round of training.
07:20
Speaker A
And then perhaps most importantly of all, there is a risk of something called catastrophic forgetting.
07:27
Speaker A
Now that's where the model loses some of its general capabilities while it's busy learning these specialized ones.
07:33
Speaker A
So finally, let's explore prompt engineering.
07:36
Speaker A
Now specifying Martin Keen who works at IBM versus Martin Keen who founded Keen shoes, that's prompt engineering.
07:44
Speaker A
But at its most basic.
07:46
Speaker A
Prompt engineering goes far beyond simple clarification.
07:49
Speaker A
So let's think about when we input a prompt.
07:54
Speaker A
The model receives this prompt.
07:58
Speaker A
And it processes it through a series of layers.
08:03
Speaker A
And these layers are essentially attention mechanisms.
08:09
Speaker A
And each one focuses on different aspects of your prompt text that came in.
08:14
Speaker A
And by including specific elements in your prompt, so examples, or context, or how you want the format to look, you're directing the model's attention to relevant patterns it learned during training.
08:23
Speaker A
So, for example, telling a model to think about this step by step, that activates patterns it learned from training data where methodical reasoning led to accurate results.
08:31
Speaker A
So a well-engineered prompt can transform a model's output without any additional training or without data retrieval.
08:38
Speaker A
So take an example of a of a prompt.
08:41
Speaker A
Let's say we say, is this code secure?
08:43
Speaker A
Not a very good prompt.
08:45
Speaker A
An engineered prompt, it might read a bit more like this.
08:50
Speaker A
It's much more detailed.
08:52
Speaker A
Now, we haven't changed the model, we haven't added new data.
08:58
Speaker A
We've just better activated its existing capabilities.
09:02
Speaker A
Now, I think the benefits to this are pretty obvious.
09:05
Speaker A
One is that we don't need to change any of our back end infrastructure here.
09:11
Speaker A
Because there are no infrastructure changes at all.
09:14
Speaker A
In order to prompt better, it's all on the user.
09:16
Speaker A
There's also the benefit that by doing this, you get to see immediate responses.
09:21
Speaker A
An immediate results to what you do.
09:25
Speaker A
We don't have to add in new training data or any kind of data processing.
09:30
Speaker A
But of course, there are some limitations to this as well.
09:32
Speaker A
Prompt engineering is as much an art as it is a science.
09:38
Speaker A
So there is certainly a a good amount of trial and error in this sort of process to find effective prompts.
09:43
Speaker A
And you're also limited in what you can do here.
09:49
Speaker A
You're limited to existing knowledge.
09:53
Speaker A
Because you're not able to actually add anything else in here.
10:00
Speaker A
No additional amount of prompt engineering is going to teach it truly new information.
10:04
Speaker A
You're not going to teach the model anything that's outdated in the model.
10:07
Speaker A
So we've talked about now RAG as being one option.
10:12
Speaker A
And we talked about fine tuning as being another one.
10:16
Speaker A
And now just now, we've talked about prompt engineering as well.
10:20
Speaker A
And I've really talked about those as three different distinct things here.
10:24
Speaker A
But they're commonly used actually in combination.
10:27
Speaker A
We might use all three together.
10:28
Speaker A
So consider a legal AI system, RAG, that could retrieve specific cases and recent court decisions.
10:34
Speaker A
Uh, the prompt engineering part, that could make sure that we follow proper legal document formats by asking for it.
10:40
Speaker A
And then fine tuning, that could help the model master firm specific policies.
10:44
Speaker A
I mean, basically we can think of it like this.
10:50
Speaker A
We can think that prompt engineering offers flexibility and immediate results.
10:55
Speaker A
But it can't extend knowledge.
10:57
Speaker A
RAG, that can extend knowledge, it provides up-to-date information.
11:02
Speaker A
But with computational overhead, and then fine tuning.
11:06
Speaker A
That enables deep domain expertise, but it requires significant resources and maintenance.
11:11
Speaker A
Basically, it comes down to picking the methods that work for you.
11:14
Speaker A
You know, we've we've sure come a long way from vanity searching on Google.
Topics:Retrieval Augmented GenerationRAGFine-tuningPrompt EngineeringLarge Language ModelsAI OptimizationIBM TechnologyVector EmbeddingsDomain ExpertiseModel Training

Frequently Asked Questions

What is Retrieval Augmented Generation (RAG)?

RAG is a method where a model retrieves relevant external information using vector embeddings and incorporates it into the prompt to generate more accurate and up-to-date responses.

How does fine-tuning improve AI model performance?

Fine-tuning adjusts a pre-trained model’s internal parameters using specialized datasets, enabling it to develop deep domain expertise and provide more accurate responses specific to that domain.

What role does prompt engineering play in optimizing AI models?

Prompt engineering involves crafting precise and context-rich queries that guide the model’s attention to relevant patterns, improving output quality without additional training or data retrieval.

Get More with the Söz AI App

Transcribe recordings, audio files, and YouTube videos — with AI summaries, speaker detection, and unlimited transcriptions.

Or transcribe another YouTube video here →