text stringlengths 0 59.1k |
|---|
import ModelPerformanceComparator from '@site/src/components/blog-widgets/ModelPerformanceComparator'; |
This is among the most common questions we get when building our AI agent framework. Developers are always asking: "How do I train my agent on my own data?" RAG or fine-tuning? |
Both are implemented in our framework, and I have seen quite a lot of different use cases over the years. I found it helpful to pass on my experience to new learners who have difficulties figuring out what is best for their case. |
That's why I'm writing this article. To pass on what I've learned and hopefully help you make the right decision. |
## Two Ways, One Big Decision |
One of the biggest decisions you'll make in creating agents is this: _How do I enhance this agent in my own space?_ GPT-4 is amazing, but how would it ever know about your company's internal operations or special lexicon? |
Two general approaches I see in our model: |
- RAG: "Let the agent be on its own, I'll give it the information it needs at runtime" |
- Fine-tuning: "I'll train the agent with my data" |
Which one makes more sense? Having been a maintainer of a framework for years: _it depends on your specific needs_. |
:::tip |
Start with RAG for your first project. It's faster to implement, cheaper to test, and you can always add fine-tuning later if needed. |
::: |
## RAG: Retrieval-Augmented Generation |
### How Does RAG Work? |
Think about RAG from an agent framework perspective: When the agent is assigned a task, it first queries its knowledge base, gets associated context, and then goes ahead to the LLM with this context. |
<ZoomableMermaid |
chart={` |
%%{init: {'theme':'base', 'themeVariables': {'primaryColor': '#10b981', 'primaryTextColor': '#10b981', 'primaryBorderColor': '#10b981', 'lineColor': '#10b981', 'secondaryColor': '#ecfdf5', 'tertiaryColor': '#d1fae5', 'background': '#ffffff', 'mainBkg': '#ecfdf5', 'secondBkg': '#d1fae5', 'tertiaryBkg': '#a7f3d0'}}}%% |
sequenceDiagram |
participant U as User |
participant A as Agent |
participant V as Vector DB |
participant L as LLM |
U->>A: Ask Question |
A->>V: Query Knowledge Base |
V->>A: Return Relevant Context |
A->>L: Question + Context |
L->>A: Generate Response |
A->>U: Final Answer |
`} |
/> |
Here's how we accomplished that in our framework: |
1. Document ingestion pipeline |
2. Vector embedding and indexing |
3. Semantic search at agent runtime |
4. Context injection before LLM invocation |
That's easiest for our users. Plug-and-play code. |
### RAG's Super Powers |
**Latest information:** One of the highlights of our system. Client uploads a fresh document, agent starts utilizing that information instantly. Real-time information update. |
**Cost-effective:** Agent deployment does not change. Knowledge base alone is updated. Infrastructure cost is minimal. |
**Traceability:** When you debug, when you wonder "Why did the agent make this decision?", you are able to view which documents it was being fed from. This is particularly useful in framework development. |
**Multi-domain flexibility:** Single agent, multiple knowledge bases per client. Wonderful for scalability. |
### RAG's Advanced Capabilities |
RAG has evolved beyond simple text retrieval. Modern implementations now support [multimodal RAG](https://voltagent.dev/blog/multimodal-rag/), which can process images, documents, and other media types together. This opens up entirely new possibilities for agent interactions. |
### RAG's Challenges |
Problems I've seen while developing the framework: |
**Retrieval quality dependency:** If you implement the system poorly, the agent is fed useless information. Garbage in, garbage out. |
**Context window management:** You have to inject 4-5 heterogeneous document pieces but token limit says "no". Then you need priority logic. |
**Latency overhead:** Vector search on every agent action. Might be problematic in performance-critical applications. |
:::warning |
RAG adds latency to every query. If you're building high-frequency trading bots or real-time systems where milliseconds matter, carefully measure this overhead before committing to RAG. |
::: |
<ModelPerformanceComparator /> |
## Fine-tuning: "Customized Agent" Approach |
### What Does Fine-tuning Mean in Agent Framework? |
You use the base model and fine-tune it for the client's specific application. The agent is converted into a native speaker of that domain. |
<ZoomableMermaid |
chart={` |
%%{init: {'theme':'base', 'themeVariables': {'primaryColor': '#10b981', 'primaryTextColor': '#10b981', 'primaryBorderColor': '#10b981', 'lineColor': '#10b981', 'secondaryColor': '#ecfdf5', 'tertiaryColor': '#d1fae5', 'background': '#ffffff', 'mainBkg': '#ecfdf5', 'secondBkg': '#d1fae5', 'tertiaryBkg': '#a7f3d0'}}}%% |
sequenceDiagram |
participant D as Training Data |
participant M as Base Model |
participant F as Fine-tuning Process |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.