WhoBuilt

Layering every technique in RAG, one query at a time

Jul 29, 2025· 20 min· 19K views·Watch on YouTube

Speaker

David Karam of Pi Labs, formerly of Google Search, explains how to improve RAG systems through information retrieval techniques at AI Engineer.

Start with outcomes and failure analysis

Karam recommends defining a product quality bar and building easy, medium, and hard query sets to measure progress. Establish a baseline, inspect failures, then choose techniques based on likely impact and implementation effort. He suggests trying simple options such as BM25 before investing in difficult work like custom embeddings.

Match retrieval methods to the queries

For a small collection, Karam says to try putting all the documents into the model context first, as in NotebookLM. When the collection grows, BM25 can retrieve keyword matches, while relevance embeddings help with natural-language queries such as asking how long an iPhone lasts before charging. If BM25 and embeddings return conflicting results, cross-encoder rerankers can score a smaller candidate set, at higher cost.

Rank with domain and user signals

Semantic relevance alone can miss specialized meanings, such as legal uses of “regime,” “moot,” and “material,” so Karam says to consider custom embeddings when evaluation data shows that standard models fail. Ranking may also need signals like price, merchant, popularity, and user clicks. He illustrates the problem with a shopping query for gifts costing $50 or more that still returned items below that budget.

Expand queries and retrieval sources

A language model may not know how to phrase queries for a particular search backend. Karam describes fan-out as breaking a complex request into narrower searches, citing Google AI Mode, which can issue 15 or 20 queries. He also recommends searching more backends when intent is ambiguous, such as a query about a Middle Eastern dish that could call for restaurants or images.

Balance cost with product design

When many backends and queries become expensive, distillation can reduce model size while holding quality steady, though Karam says it is difficult and most useful when latency matters. Since stochastic systems will always fail sometimes, he also recommends designing the product to adjust its interface to its level of understanding. Google Shopping can offer filters when its data is strong, or show a simpler list when confidence is lower.

Takeaways

  • Set a product quality bar and evaluate your own representative query sets.
  • Choose retrieval techniques by diagnosing failures, then weigh their likely impact against their cost and effort.
  • Use keyword retrieval, embeddings, and rerankers for the kinds of queries each handles well.
  • Add domain, price, popularity, and user preference signals when relevance alone does not produce good rankings.
  • Design the experience to degrade gracefully when the system is uncertain, and consider distillation when latency becomes a problem.

Mentioned in this talk

Search inside this talk

What was claimed 9

  • founded
    “we left and started Pi Labs”
    YouTube
    Verified2 sources· Talk, Web· archived
  • feature
    quality engineering loop: Baseline, analyze failures, then improve quality
    “baseline yourself. Do a loss analysis ... Then do what we call quality engineering”
    YouTube
    Unverified1 source· Talk
  • feature
    BM25: Keyword retrieval using query term frequency, document length, and term occurrence
    “It’s based on ... query term frequency ... document length”
    YouTube
    Unverified1 source· Talk
  • feature
    relevance embeddings: Semantic retrieval in vector space
    “vector space can handle way more nuance than keyword space”
    YouTube
    Unverified1 source· Talk
  • feature
    cross-encoders: Score a query and document together while attending to both
    “They take both the query and the document and give you a score while attending to both”
    YouTube
    Unverified1 source· Talk
  • feature
    PageRank: Measures prominence through links pointing to a page
    “How many things outside my document point to me? That has nothing to do with relevance”
    YouTube
    Unverified1 source· Talk
  • feature
    Google AI Mode: Fans out a complex request into multiple queries
    “you can see it's making multiple queries—15, 20 queries”
    YouTube
    Unverified1 source· Talk
  • feature
    supplementary retrieval: Calls more backends to increase recall
    “When you're trying to get high recall, you should always be searching more”
    YouTube
    Unverified1 source· Talk
Show all 9 facts

Related talks