Skip to main content
QUICK REVIEW

[Paper Review] RAG vs Fine-tuning: Pipelines, Tradeoffs, and a Case Study on Agriculture

Angels de Luis Balaguer, Vinamra Benara|arXiv (Cornell University)|Jan 16, 2024
Topic ModelingComputer Science50 citations
TL;DR

The paper compares Retrieval-Augmented Generation (RAG) and fine-tuning pipelines for large language models, presents a detailed agriculture case study, and reports additive accuracy gains when combining RAG with fine-tuning.

ABSTRACT

There are two common ways in which developers are incorporating proprietary and domain-specific data when building applications of Large Language Models (LLMs): Retrieval-Augmented Generation (RAG) and Fine-Tuning. RAG augments the prompt with the external data, while fine-Tuning incorporates the additional knowledge into the model itself. However, the pros and cons of both approaches are not well understood. In this paper, we propose a pipeline for fine-tuning and RAG, and present the tradeoffs of both for multiple popular LLMs, including Llama2-13B, GPT-3.5, and GPT-4. Our pipeline consists of multiple stages, including extracting information from PDFs, generating questions and answers, using them for fine-tuning, and leveraging GPT-4 for evaluating the results. We propose metrics to assess the performance of different stages of the RAG and fine-Tuning pipeline. We conduct an in-depth study on an agricultural dataset. Agriculture as an industry has not seen much penetration of AI, and we study a potentially disruptive application - what if we could provide location-specific insights to a farmer? Our results show the effectiveness of our dataset generation pipeline in capturing geographic-specific knowledge, and the quantitative and qualitative benefits of RAG and fine-tuning. We see an accuracy increase of over 6 p.p. when fine-tuning the model and this is cumulative with RAG, which increases accuracy by 5 p.p. further. In one particular experiment, we also demonstrate that the fine-tuned model leverages information from across geographies to answer specific questions, increasing answer similarity from 47% to 72%. Overall, the results point to how systems built using LLMs can be adapted to respond and incorporate knowledge across a dimension that is critical for a specific industry, paving the way for further applications of LLMs in other industrial domains.

Motivation & Objective

  • Motivate how domain-specific data can be integrated into LLMs using RAG or fine-tuning.
  • Develop and evaluate a multi-stage pipeline (data extraction, Q&A generation, RAG, fine-tuning) for domain knowledge.
  • Quantify tradeoffs, costs, and performance across models (Llama2-13B, GPT-3.5, GPT-4) in agriculture.
  • Demonstrate geography-specific knowledge capture and improvements in answer localization.
  • Provide actionable guidance for building industry copilots grounded in domain data.

Proposed method

  • Propose a multi-stage pipeline: data acquisition, PDF information extraction, Q&A generation, RAG-based answer generation, and model fine-tuning.
  • Use GROBID to convert PDFs to structured TEI/JSON preserving document structure for grounding.
  • Generate Q&A with the Guidance framework to control input/output structure and grounding context.
  • Apply RAG with embedding-based retrieval (sentence transformers + FAISS) and GPT-4 for answer synthesis.
  • Fine-tune multiple models (Llama2-13B, GPT-4) using LoRA and FSDP-based training on 8x A100 GPUs; use mixed precision and cosine learning rate schedules.
  • Evaluate with a GPT-4-based metric suite and compare RAG vs fine-tuning across domains and geographies.

Experimental results

Research questions

  • RQ1How do RAG and fine-tuning compare in improving LLM performance on industry-specific agriculture questions?
  • RQ2What is the impact of spatially scoped fine-tuning on geography-specific knowledge accuracy?
  • RQ3What are the cost and performance tradeoffs of fine-tuning large models (e.g., GPT-4) versus using RAG alone or in combination?
  • RQ4Can a geography-aware Q&A pipeline improve answer specificity and cross-geography knowledge transfer?
  • RQ5How do different base models (Llama2-13B, GPT-4, Vicuna) perform in agriculture Q&A with RAG and/or fine-tuning?

Key findings

  • Fine-tuning yields an accuracy increase of over 6 percentage points (p.p.).
  • RAG contributes an additional 5 p.p. accuracy gain when combined with fine-tuning.
  • Fine-tuned models can leverage cross-geography information to raise answer similarity from 47% to 72%.
  • GPT-4 consistently outperforms other models, but its fine-tuning and inference costs are nontrivial.
  • RAG is effective when data is contextually relevant (e.g., farm data) and tends to produce more concise answers than the base model.
  • The study demonstrates a practical, industry-focused pipeline for creating domain-specific AI copilots, starting from Q&A generation to model fine-tuning.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.