Web/Guru

RAG vs fine-tuning vs prompt engineering: which does your product need? (2026)

What RAG, fine-tuning and prompting each change, a decision table, a Node.js retrieval example, and where you can still fine-tune OpenAI, Claude or Gemini.

Published
Updated
October 5, 2026
Read time
12 min read
Written by
Webguru
RAG vs fine-tuning vs prompt engineering: which does your product need? (2026)
/On this page01 / 11

Most teams that ask "should we fine-tune?" actually have a knowledge problem, and fine-tuning is the wrong tool for that. Prompt engineering, retrieval augmented generation (RAG) and fine-tuning each change a different part of an AI feature. Pick the wrong one and you pay for training runs that fix nothing, or for a vector database you didn't need.

Below: what each technique changes, a decision table by problem type, a RAG architecture with a small Node.js example, where fine-tuning stands at OpenAI, Anthropic (via Amazon Bedrock) and Google as of September 25, 2026, and the order we recommend trying things in.

The short answer

  • Prompt engineering changes the instructions and examples the model sees. Always start here: it's the cheapest thing to change and the fastest to test.
  • RAG changes the *information* the model sees at answer time, by searching your documents and putting the relevant passages in the prompt. Use it when answers depend on private, fresh or large amounts of content, or when you need citations.
  • Fine-tuning changes the model's *behavior*: format, tone, classification labels, how terse it is. Google's Vertex AI docs describe supervised fine-tuning as a way to adapt "model behavior with a labeled dataset." Use it when well-built prompts still aren't consistent enough and you have clean examples of the output you want.

Most production systems combine them: a good prompt, plus retrieval, and occasionally a tuned model underneath.

What each technique changes

Prompt engineeringRAGFine-tuning
What changesInstructions, examples, context you paste inThe documents placed in context per requestThe model's weights
Good atTask framing, format, tone, reasoning stepsPrivate and fresh knowledge, citations, per-user dataConsistent format and behavior, narrow tasks, shorter prompts
Weak atKnowledge that doesn't fit in the promptBehavior and style on its ownFacts that change; explaining where an answer came from
Update cycleEdit the prompt and redeployRe-index changed documentsCollect data, retrain, re-evaluate
NeedsAn eval set and a first draftA document pipeline, embeddings, a search indexLabeled examples, an eval set, a vendor that still offers tuning for your model

Decision table by problem type

Your problemStart withWhy
Answers depend on content that changes (policies, stock, prices, docs)RAGUpdate the index, not the model.
Users or auditors need to see the sourceRAG with citationsClaude's citations feature and OpenAI's file search both return pointers to the source documents.
A small, stable knowledge basePrompt with the whole document in contextAnthropic's 2024 guidance: under about 200,000 tokens (about 500 pages), "you can just include the entire knowledge base in the prompt," ideally with prompt caching.
Output format or tone is inconsistentPrompt engineering with examples, then fine-tuningVertex AI lists "specific structures or formats" and "terse or verbose output" as tuning use cases once prompts stop being enough.
High-volume classification into fixed labelsPrompt first; fine-tune with labeled data if results varyClassification is one of the tasks both OpenAI and Google list for supervised fine-tuning.
A long few-shot prompt makes every call expensiveFine-tuning, or a smaller modelVertex AI names reducing context length "by removing the few-shot examples" as a reason to tune.
Responses are too slowModel choice and prompt length firstAnthropic notes you can "sometimes improve latency and cost more easily by selecting a different model."
Each customer may only see their own dataRAG with metadata filtersOpenAI file search supports attribute filters; your own index needs the same. Tuning can't enforce permissions.
The assistant must look up live orders or take actionsTool calling to your APIsThat's neither RAG nor tuning. See our page on AI agents and our guide to AI agents for business.

How a RAG system is put together

A RAG pipeline has two halves. Google's RAG Engine docs describe the same stages most teams build: ingestion, transformation (chunking), embedding, indexing, retrieval and generation.

Indexing (offline):

  1. Ingest and clean. Pull documents from your CMS, help center, PDFs or database and strip boilerplate. Claude can't cite scanned PDFs that have no extractable text, so run OCR on those first.
  2. Chunk. Split documents into passages. OpenAI's file search defaults to 800-token chunks with 400 tokens of overlap, which is a sensible starting point to test against. Keep headings with their text so a chunk still makes sense alone.
  3. Add context to chunks. Anthropic's contextual retrieval approach prepends a short explanation of where each chunk sits in its document before embedding it. In Anthropic's own tests, contextual embeddings plus contextual BM25 cut failed retrievals by 49%, and 67% with reranking added. Test it on your data rather than assuming the same gain.
  4. Embed and store. Turn each chunk into a vector with an embedding model and store it with metadata (source URL, document title, customer or tenant ID, last updated). Postgres with pgvector is a practical default if you already run Postgres.

Answering (per request):

  1. Embed the question with the same embedding model you indexed with.
  2. Hybrid search. Combine vector similarity with keyword search (BM25 or Postgres full-text). Vectors find paraphrases; keywords find SKUs, error codes and product names. The pgvector docs mention merging the two with Reciprocal Rank Fusion. OpenAI's file search exposes weights for embedding versus keyword matches.
  3. Rerank. Pass the top results through a reranker model and keep the best few. Anthropic notes that reranking adds latency at runtime, so measure it.
  4. Generate with citations. Put the passages in the prompt with IDs and ask the model to answer only from them. Claude's citations and search result blocks, and OpenAI's file_citation annotations, do this in the API rather than by prompt alone.

Managed options exist if you don't want to run your own index: OpenAI's file search (vector stores on the Responses API), Google's RAG Engine and Claude's document citations. Check their regions and data controls before you commit. For example, Google's RAG Engine page lists Frankfurt as generally available and London in preview, and says data residency controls aren't supported.

A minimal retrieval example in Node.js

This uses the official openai npm package, keeps vectors in memory and uses cosine similarity. It's enough to test retrieval quality on a few hundred chunks before you choose a database. Save it as an .mjs file (it uses top-level await). In production, store vectors in pgvector or another vector store and add keyword search.

js
import OpenAI from "openai";
const openai = new OpenAI(); // reads OPENAI_API_KEY
const EMBED_MODEL = "text-embedding-3-small";
// Sample chunks; in practice these come from your chunking step
const chunks = [
  { id: "returns-1", text: "Unworn items can be returned within the return window shown on the order page." },
  { id: "shipping-2", text: "International orders are shipped with tracking. Duties are shown at checkout." },
  { id: "warranty-1", text: "Electronics are covered by the manufacturer warranty listed on the product page." },
];
async function embed(texts) {
  const res = await openai.embeddings.create({ model: EMBED_MODEL, input: texts });
  return res.data.map((d) => d.embedding);
}
function cosine(a, b) {
  let dot = 0, na = 0, nb = 0;
  for (let i = 0; i < a.length; i++) {
    dot += a[i] * b[i];
    na += a[i] * a[i];
    nb += b[i] * b[i];
  }
  return dot / (Math.sqrt(na) * Math.sqrt(nb));
}
// 1. Index once
const vectors = await embed(chunks.map((c) => c.text));
const index = chunks.map((c, i) => ({ ...c, vector: vectors[i] }));
// 2. Retrieve the top k chunks for a question
async function retrieve(question, k = 2) {
  const [q] = await embed([question]);
  return index
    .map((c) => ({ id: c.id, text: c.text, score: cosine(q, c.vector) }))
    .sort((a, b) => b.score - a.score)
    .slice(0, k);
}
// 3. Answer only from the retrieved sources, with citations
const question = "Can I send back shoes I wore once?";
const hits = await retrieve(question);
const sources = hits.map((h) => `[${h.id}] ${h.text}`).join("\n");
const response = await openai.responses.create({
  model: process.env.OPENAI_MODEL, // choose a current model from OpenAI's models page
  instructions: "Answer only from the sources. Cite source ids in square brackets. If the sources don't answer the question, say so.",
  input: `Sources:\n${sources}\nQuestion: ${question}`,
});
console.log(response.output_text);
console.log(hits.map((h) => `${h.id}: ${h.score.toFixed(3)}`));

OpenAI's embeddings are normalized to length 1, so a plain dot product gives the same ranking. The full cosine function keeps the code correct if you switch to a provider whose vectors aren't normalized. Log the scores: when the right chunk isn't in the top results, no prompt will fix the answer.

Fine-tuning in 2026: prerequisites and what's actually available

Before you plan a tuning project, check that your vendor still offers it for the model you want. As of September 25, 2026:

VendorWhat the docs listWatch out for
OpenAISupervised and preference (DPO) tuning on gpt-4.1, gpt-4.1-mini and gpt-4.1-nano (2025-04-14); reinforcement fine-tuning on o4-mini; vision tuning on gpt-4o-2024-08-06OpenAI is winding down its fine-tuning platform. Since May 7, 2026, organizations that never ran fine-tuning can't create jobs. Since July 2, 2026, neither can organizations that haven't run inference on a fine-tuned model in the past 60 days. Active existing customers lose the ability to create new jobs on January 6, 2027. Existing tuned models keep serving until their base models are deprecated.
Anthropic (Claude)Amazon Bedrock's fine-tuning table lists Claude 3 Haiku only, in US West (Oregon)Anthropic retired claude-3-haiku-20240307 on its own API on April 20, 2026. Check Bedrock's model lifecycle before building on it.
Google (Vertex AI)Supervised tuning for Gemini 3.5 Flash, Gemini 3.1 Flash-Lite, Gemini 2.5 Pro, Gemini 2.5 Flash and Gemini 2.5 Flash-Lite; preference and reinforcement tuning are also documentedTuning isn't covered by an SLA. For Gemini 3.5 Flash and 3.1 Flash-Lite, tuning runs in us-central1 or europe-west4, and tuned models serve from the US and EU multi-region endpoints only.

Open-weight models (Bedrock's table also lists several Llama models) are the other route: full control, but you take on hosting and upgrades.

Prerequisites before any tuning run:

  • A task you can define. Google describes supervised tuning as a good fit when "you have a well-defined task with available labeled data."
  • Enough clean examples. OpenAI's minimum is 10 examples and it suggests "starting with 50 well-crafted demonstrations." Its best-practice guide says a smaller amount of high-quality data generally beats a larger amount of low-quality data. Check that examples written by different people are consistent.
  • A held-out test set. Split your data so the test portion is only used for evals, never for training.
  • A prompt baseline. If you haven't measured your best prompt on the same test set, you can't tell whether tuning helped.
  • A re-tuning plan. A tuned model is tied to its base model. When the base is deprecated, you retrain.

Google also documents two practical details: set thinking to the minimum on tuned Gemini models, and skip controlled generation (structured output mode) at inference, because tuning without it and serving with it can lower quality.

How to evaluate, whichever technique you pick

  1. Write success criteria first. Anthropic's guidance is that criteria should be specific, measurable, achievable and relevant. "Answers returns questions correctly and cites the policy" is testable. "Works well" isn't.
  2. Build the eval set from real traffic. Take questions from support tickets, search logs or chat transcripts, with the expected answer and source document. Include questions your content can't answer, to test that the system says so.
  3. Score retrieval separately from generation. For RAG, check whether the right chunk was retrieved (recall) and how much noise came with it (precision) before judging the final answer. OpenAI's eval guide uses context recall and precision for RAG systems.
  4. Automate grading, then calibrate it. Use exact match or code checks where you can and an LLM grader where you can't. OpenAI's guide warns against "vibe-based evals" and recommends calibrating automated scores against human feedback.
  5. Re-run on every change: prompt edits, chunk sizes, embedding model, reranker and model version.

Our AI MVP guide includes a minimal eval harness in Node.js you can adapt for this.

Cost and latency: what moves the bill

We don't quote prices here because they change often; check each vendor's pricing page on the day you budget. What drives cost and latency:

  • Prompt engineering: longer prompts mean more input tokens on every call. Prompt caching on Claude and OpenAI cuts the cost and latency of a repeated prefix, which makes "put the whole document in the prompt" cheaper than it looks.
  • RAG: embedding calls at index and query time, vector storage (OpenAI bills vector store storage above a free allowance), the extra retrieval step, and reranking. OpenAI's max_num_results setting exists to reduce "both token usage and latency."
  • Fine-tuning: training runs, data preparation time, and retraining whenever the base model changes. The payoff is shorter prompts on high-volume, narrow tasks.
  • Model choice often beats all three. Try a smaller or faster model against your eval set before you build anything.

Common mistakes

  • Fine-tuning to teach facts. Tuning shapes behavior. For facts that change or need a source, use retrieval.
  • No eval set. Without one, you can't tell whether RAG, a new prompt or a tuned model is actually better.
  • Vector search only. Pure embeddings often miss exact identifiers like SKUs, part numbers and error codes. Add keyword search.
  • Chunks that lose their context. "It must be returned within the window" means nothing without its document. Keep headings, or add chunk context.
  • Ignoring permissions. Filter retrieval by user, customer or tenant before the model sees anything. The model can't enforce access rules on text it has already been given. Our guide to integrating AI into a SaaS product shows where the tenant filter sits.
  • Combining Claude citations with structured outputs. Anthropic documents these as incompatible: the API returns a 400 error.
  • Planning around a tuning platform that's closing. Check the vendor's deprecations page before you collect training data.

Start here: a practical path

  1. Collect a few dozen real questions with expected answers and sources. This is your eval set.
  2. Write a solid prompt on a current model and measure it. Many products stop here.
  3. If answers lack knowledge: if the content is small and stable, put it in the prompt with caching. If it's large, changing or permissioned, add RAG, starting with a managed option or the in-memory example above.
  4. If retrieval misses: add keyword search, chunk context and a reranker, one at a time, measuring each.
  5. If format or behavior still fails after good prompts, and you have at least 50 clean examples plus a vendor path that will still exist next year, try fine-tuning and compare it against the prompt baseline on the same test set.
  6. Log production traffic and add every failure to the eval set.

For more on where this fits in a wider AI roadmap, see our AI development services. If your content lives in a Shopify store, our AI for Shopify page covers catalog and support assistants, and our guide to AI for Shopify stores compares built-in, app and custom options.

Want help choosing and building it?

We build prompt pipelines, RAG systems on pgvector or managed vector stores, and eval harnesses that tell you whether a change helped. Tell us what your product needs to answer, and we'll tell you honestly whether you need RAG, fine-tuning or just a better prompt. Start on our AI integration page.

Sources

/Tags#AI#RAG#Fine-tuning#Prompt engineering

Written by

Webguru

Engineering Team

Webguru.pk is a Shopify development team in Lahore, Pakistan, building stores, custom apps and integrations for brands worldwide.

/Share

Need a hand with this?

We design, build and fix this kind of work for Shopify, SaaS and AI products.

/faqs

RAG vs Fine-Tuning: Frequently Asked Questions

RAG searches your documents at answer time and puts the relevant passages in the prompt, so it changes what the model knows for that request. Fine-tuning trains the model on examples, so it changes how the model behaves, such as output format, tone or classification labels.

It's the wrong tool for facts that change or need a source. Use RAG for knowledge and citations, and reserve fine-tuning for consistent behavior and format that prompts alone can't achieve.

Only if your organization already uses OpenAI fine-tuning and has run a fine-tuned model recently. OpenAI is winding down its fine-tuning platform: since May 7, 2026, organizations that never ran fine-tuning can't create jobs, since July 2, 2026, organizations that haven't run inference on a fine-tuned model in the past 60 days can't either, and active existing customers can't create new jobs from January 6, 2027. Existing fine-tuned models keep serving until their base models are deprecated.

OpenAI's supervised fine-tuning requires at least 10 examples and suggests starting with 50 well-crafted demonstrations. Quality matters more than volume, and you should hold back a separate test set for evaluation.

Not always. If your knowledge base is small and stable, Anthropic's guidance is that under about 200,000 tokens you can put it all in the prompt, ideally with prompt caching. For larger or changing content, use a vector store such as Postgres with pgvector or a managed option like OpenAI file search or Google's RAG Engine.

Build an eval set of real questions with expected answers and sources before you change anything, then score retrieval and final answers separately on every change. Calibrate any automated or LLM-based grading against human review.

Not sure if you need RAG, fine-tuning or a better prompt?

Tell us what your product has to answer and we'll help you pick, build and measure the simplest approach that works.

or write to+44 7882 755642