Query expansion, decomposition, transformation

Lesson 3 of 4 in Retrieval Engineering.

Users do not write retrieval-friendly queries — they write compound questions, vague fragments, and pronouns referring to three turns ago. Three repairs answer that. Query expansion: an FM enriches the query with synonyms, acronym expansions, and rephrasings so retrieval matches vocabulary the user didn't type. Query decomposition: a multi-part question is split into focused sub-queries that retrieve separately before results pool — one embedding of a compound question is semantically diluted, which is why Knowledge Bases ships this natively as the QUERY_DECOMPOSITION transformation on RetrieveAndGenerate ("break down queries" in the console). Query transformation/rewriting: strip chit-chat, resolve references from conversation history, canonicalize terms — Lambda for single rewrites, Step Functions when the transformation is a multi-step pipeline, exactly the service mapping the AIP-C01 exam guide gives.

A compound question through a query-handling pipeline

  1. Raw question

    "Where is the Waterfront building and how did the whistleblower case hurt the brand?" — two unrelated asks sharing one sentence.

  2. Rewrite & resolve

    Strip filler, resolve pronouns from history, canonicalize names — Lambda-sized work.

  3. Complex?

    Single-intent queries skip straight to retrieval; compound ones decompose.

  4. Decompose into sub-queries

    One sub-query per intent — the knowledge base's QUERY_DECOMPOSITION, or your own FM prompt doing the splitting.

  5. Retrieve per sub-query

    Each focused sub-query hits the index precisely; expansion adds synonym variants where recall is thin.

  6. Pool + rerank

    Candidates from all sub-queries merge and rerank into one context set.

  7. Generate with citations

    The model answers every part of the original question — because every part got its own retrieval.

Expansion vs decomposition — the one-line test

Expansion widens one intent (synonyms and phrasings for the same ask — fixes vocabulary mismatch / low recall). Decomposition separates several intents (sub-queries for a compound ask — fixes semantic dilution on multi-part questions). Stems that quote a two-part question want decomposition; stems about jargon mismatch want expansion.

Where each runs on AWS

The guide's own mapping: Amazon Bedrock for query expansion (an FM generates the variants), Lambda for query decomposition you implement yourself, Step Functions for multi-step query transformation pipelines — and Knowledge Bases' built-in QUERY_DECOMPOSITION when the managed path suffices.

The cost shape

Every transformation adds an FM call or more retrievals before generation even starts. Reserve the pipeline for queries that need it (the "complex?" router above) — a professional stem that says "simple lookups got slower and pricier" is pointing at transformation applied indiscriminately.

Interactive checkpoint quiz (2 questions) — open this page in a browser to take it.