NEW RELEASE

MLRun 1.7 is here! Unlock the power of enhanced LLM monitoring, flexible Docker image deployment, and more.

RAG vs. Fine-tuning: When to Use Each One?

In RAG, the model queries an external dataset or knowledge base, typically using a vector space model where documents or data snippets are encoded as vectors. When a query (prompt) comes in, the model performs a similarity search to retrieve the most relevant information. This retrieved content is then used by the generative component of the model to craft a response that is informed by this external data.

RAG is particularly useful in scenarios where the required knowledge is vast or frequently updated, such as news updates, scientific research, or detailed customer data. It ensures that the model can provide accurate and relevant information without needing frequent retraining.

Fine-tuning is a technique where a pre-trained model is further trained (fine-tuned) on a smaller, specialized dataset. This secondary training phase adjusts the model’s weights to perform better on tasks specific to the characteristics of the new data.

Fine-tuning involves continuing the training process of an already trained model but focuses on a narrower scope or a specific domain. This targeted training helps the model to better understand and generate responses that are aligned with the specific nuances and requirements of the target domain.

mlrun

Demo: Fine-Tune LLMs

Learn how to fine tune a LLM and build an ML application

Fine-tuning is helpful when the model needs to adopt a specific tone, style, or set of knowledge, such as legal terminology, technical support for a specific product, or company-specific guidelines. Fine-tuning is also used to implement "guardrails" or constraints that guide the model’s outputs to avoid undesirable content or biases.

RAG and retraining are not mutually exclusive and can be combined to leverage their respective strengths.

Need help?

Contact our team of experts or ask a question in the community.

Have a question?

Submit your questions on machine learning and data science to get answers from out team of data scientists, ML engineers and IT leaders.