Teaching Keywords to Think: Term Expansion & SPLADE

Part of the free Generative AI course on LogicWiz, module: Finding the Needle: Hybrid Search & Retrieval.

Episode 43: Teaching Keywords to Think — Term Expansion & SPLADE

"'Bright' will never match 'luminous,'" Arjun sighed. "Unless," said Anjali, "you put 'bright' into the luminous lamp's index — before anyone searches."


The Problem: Keyword Search Is Too Literal

The inverted index from last episode is fast and precise — but it's completely literal. It can only match words that are physically present in a document.

Picture it: a shopper searches "bright lamp." You stock the perfect product — but its title reads "luminous LED light." Not a single shared word. So the inverted index returns… nothing. The ideal product is invisible, and you just lost a sale to a vocabulary mismatch.

This is the same vocabulary-mismatch problem from Episode 39, and it's the price of pure keyword search: it matches spellings, not meanings. The goal now is to keep the speed and precision of sparse search, but teach it that "bright" and "luminous" are the same idea.

The Fix: Add the Words That Aren't There

Think of a great librarian. Ask for books on "cars," and instead of checking only the shelf literally labelled "cars," they also walk you over to "automobiles" and "vehicles" — because they know those mean the same thing.

Term expansion gives your search engine that same instinct: quietly add related words so different phrasings for one idea finally overlap. You can do it in two places:

  • Query-side: the shopper types "bright," and the system also searches for "luminous," "daylight," "radiant." Any one of them matching a product counts as a hit.
  • Document-side: when you store a product that says "sofa," you also file it under "couch" — so a later search for "couch" finds it, even though that word was never in the text.

{{visual:term-expansion}}

You'll build this exact mechanism — and measure how much more it retrieves — in this lesson's lab.

💡 Expansion isn't applied blindly to every word. It's guided by importance (rare, meaningful words get expanded; "the" doesn't) and it's probabilistic — the goal is to raise the odds of a relevant overlap, not to force an exact match.

SPLADE: Expansion, Learned Automatically

Hand-writing synonym lists works for a demo, but in the real world it's a nightmare — endless to maintain, and blind to context. So instead of writing the lists ourselves, we let a model learn them. That model is SPLADE.

The simplest way to picture SPLADE is as a small AI auto-tagger. Feed it a piece of text; it reads the text and writes out an expanded list of tags — every important word that's actually there, plus related words it knows belong, each with a weight.

The name spells out exactly that — Sparse Lexical And Expansion:

  • Sparse Lexical → it outputs the word-checklist from last episode (one slot per vocabulary word, mostly zeros).
  • And Expansion → but it also ticks boxes for related words that never appeared in the text.

Here's the striking part. Feed SPLADE the 11-word sentence "The city library is a great place to study machine learning," and it lights up about 49 slots — the original words (weighted by importance) plus learned relatives it was never given, like "librarian," "machines," "learn," and "street." Now a search using any of those finds the sentence, even though it never contained them.

That's the leap: classic keyword scoring (TF-IDF, BM25) can only tick boxes for words physically in the text. SPLADE ticks boxes for words that aren't — giving keyword search a dose of meaning, while staying a fast, reversible sparse vector (you can still read the exact words back out, which a dense vector can never do).

Walk the real code that turns a sentence into a SPLADE vector and decodes it back into weighted words:

{{visual:splade-walkthrough}}

Now run the real model yourself and watch the added words appear (this executes actual SPLADE on a server):

{{cell:l43-splade-run}}

"Why Not Just Use a Small Language Model?"

A fair question: if models are so smart, why not drop a Small Language Model (SLM) in place of all this retrieval machinery? Short answer — it's the wrong tool for the job:

  • An SLM can't reliably "memorise" a million-product catalogue. Ask it to, and it hallucinates answers and adds latency a dedicated index doesn't. And there's a catch-22: train it on enough data to be trustworthy, and it's no longer small — it's just an LLM.
  • Where small models do shine is around search, not instead of it: generating synonyms for expansion, or re-ranking the shortlist a retriever returns. They sharpen the input and output of search — they aren't the search.

📌 The takeaway: SPLADE keeps the precision and speed of sparse retrieval but adds the semantic reach of a neural model — no full dense vector required. It's the "learned sparsity" the field chased for years.

What Nova Learns Next

Nova now has two strong, fast retrievers: dense (HNSW) for meaning and SPLADE-powered sparse (inverted index) for expanded keywords. The obvious move is to run both and merge their answers — but their scores live on different scales. In Episode 44 we combine them properly with Reciprocal Rank Fusion.