Coders In Hoods
  • Courses
  • Roles
  • Blog
  • Setup

Coders In Hoods AI Academy

Every course is free. Sign in to start, and your progress, quiz scores and bookmarks follow you.

AI Academy

  • Courses
  • Paths
  • Setup guides
  • How we teach

Role roadmaps

  • AI Engineer
  • Forward Deployed Engineer
  • Machine Learning Engineer
  • All roles

Coders In Hoods

  • The agency
  • Coaching for teams
  • Blog
  • LinkedIn
  • X (Twitter)

Contact

codersinhoods@gmail.com

© Coders In Hoods · since 2019

Course overview

Retrieval and Knowledge Systems

Free · sign in to start and track progress

1 · Building the index

  • 1Embeddings in practice
  • 2Chunking structured documents
  • 3Vector indexes and databases
  • 4Measuring retrieval

2 · Retrieval that reasons

  • 5Hybrid search and reranking
  • 6Agentic retrieval
  • 7Knowledge graphs and GraphRAG
  • 8Long context versus RAG

    Exercise answers

    • Answer: Compare long context, RAG and a router on your questions
CapstoneA measured retrieval service for cases and reference documentsReference implementation

Module 2 · Retrieval that reasons · Lesson 8

Long context versus RAG

When to put a whole case file in the prompt and when to retrieve, using current prices, prompt caching and the research evidence on accuracy, and how to route between the two.

65 min 1 video 2 exercises 6-question quiz Answers
Setup for the exercises:Install Claude CodePython with uvGet an OpenRouter keyLocal models with Ollama

By the end of this lesson you can

  • Compute the cost of answering a session of questions with cached long context versus RAG, and find the break-even point
  • Summarise what the research says about long-context versus RAG accuracy, and its limits
  • Choose between whole-case context, document-level retrieval, chunk RAG and agentic search for a given workload
  • Design a router that sends each question to the cheapest approach likely to answer it, with a fallback

On this page

  • Three costs of long context
  • The cost model, with caching
  • What the research says about accuracy
  • Which approach for which work
  • A router in practice
  • Connections
  • Summary
  • Sources & further reading
  • Quiz

In this lesson

  1. 01Three costs of long context
  2. 02The cost model, with caching
  3. 03What the research says about accuracy
  4. 04Which approach for which work
  5. 05Connections
  6. 06Summary

Sources & further reading

  • Retrieval Augmented Generation or Long-Context LLMs? A Comprehensive Study and Hybrid ApproachPaper · Li, Li, Zhang, Mei, Bendersky · 2024The study to read first. With enough resources, long context beat RAG on average; RAG and long context gave identical predictions on 63% of queries; Self-Route sends each query to RAG or long context by self-reflection and cut cost by 65% (Gemini 1.5 Pro) and 39% (GPT-4o).
  • LaRA: Benchmarking Retrieval-Augmented Generation and Long-Context LLMs – No Silver Bullet for LC or RAG RoutingPaper · Li et al. · 20252,326 test cases across 11 models. The better choice depends on model size, long-context ability, context length, task type and the retrieved chunks. Read the analysis by task type.
  • Lost in the Middle: How Language Models Use Long ContextsPaper · Liu et al. · 2023The position effect behind many long-context failures. Current models are much better, but the paper explains why distractor-heavy legal bundles still need care.
  • Introducing Contextual RetrievalLab research · Anthropic · 2024Its opening section gives Anthropic's rule of thumb that a knowledge base under 200,000 tokens can go straight into the prompt with prompt caching.
  • Claude pricingDocs · AnthropicCurrent per-token, cache write, cache read and batch prices, and the long-context pricing rules, including Haiku 5.5's higher price above 100,000 prompt tokens.
  • Context windowsDocs · AnthropicWhich Claude models have a 1M-token window, how cached tokens still count against it, and Anthropic's note that accuracy and recall degrade as token count grows.
Free · sign in to start

Sign in to keep reading.

Free, no card. We use your account to save progress, quiz scores, bookmarks and occasionally send updates from our team.

  • 6 more sections
  • 2 hands-on exercises
  • A 6-question quiz
  • Progress, quiz scores and bookmarks