AI Engineering
/
RAG & Data Pipelines
/

Retrieve evidence for a follow-up question

RAG & Data Pipelines · 60 to 90 minutes

Retrieve evidence for a follow-up question

Turn a follow-up message into a standalone retrieval query, keep access filters tied to the signed-in session on every turn, and decide which turns should not retrieve at all.

Easy
Conceptual

1.5 h

Used in interview rounds:

Technical Screen (Easy)

Overview

A follow-up such as "And for meals?" makes sense to a reader who saw the earlier turns, but a retriever sees only one query string. This level teaches you to build a standalone retrieval query, keep access scope tied to the signed-in session on every turn, and decide when a turn should not retrieve at all. You practice on a fictional employee-policy assistant.

Study time: 60 to 90 minutes

Interview format: Conceptual screen with a turn-by-turn prediction exercise

By the end you can

  • Explain why a follow-up message retrieves the wrong evidence, or none, when it is sent to retrieval as typed
  • Rewrite a follow-up into a standalone retrieval query, keep the original message for the generator, and log both
  • State where access filters come from on every turn, and why neither the user's text nor a rewrite can widen them
  • Decide when a turn should skip retrieval, ask a clarifying question, or start a fresh query after a topic switch
  • Name the ways a rewrite can fail and the few multi-turn test cases that catch them

This topic covers ingestion, grounding, citations, and the document lifecycle. Embeddings & Retrieval covers how candidates are found and ranked.

Two inputs in a conversational assistant

A turn that uses retrieval has two separate inputs.

  • The generator request carries the instructions, the recent turns (usually resent by the application on every request), the latest message, and the retrieved passages.
  • The retrieval call usually takes one query string plus filters. It does not read the conversation unless the application puts the needed parts into that string.

So the generator can follow "And for meals?" from the history while the retriever cannot, and a fluent answer built from whatever came back can hide that retrieval was asked the wrong question.

Why a follow-up fails as a query

Suppose a travel assistant has just answered "What is the hotel limit per night for trips abroad?" Follow-ups lean on that turn in two ways:

  • Coreference: "Does that include breakfast?" uses "that" for the hotel limit.
  • Ellipsis: "And for meals?" leaves out "trips abroad" and "limit".

Sent as typed, such a message has few meaningful words. The retriever may match an incidental word ("meals" pulls up an office canteen page) or return weak closest matches, so the generator gets the wrong evidence or none.

Conversational search research, such as the QReCC dataset and the TREC Conversational Assistance Track (CAsT), studies rewriting a question that depends on earlier turns into one that stands alone, and evaluates whether the system then retrieves the right passages. In CAsT 2019, rewrites written by people still beat the best automatic system.

Write a standalone query

A standalone query is one question that a reader who has not seen the conversation could understand. It keeps every subject and condition the message refers to and leaves out filler such as thanks or "never mind".

Identity is not the query's job: "I" and "my region" are enforced by filters from the session (see "Scope comes from the session on every turn"). Writing a region into the query may change ranking, but it restricts nothing.

MethodHow it worksTrade-off
Template rewriteFill a pattern from structured state (current subject plus new condition)Cheap and predictable; brittle when a message does not fit
Model rewriteSend the last few turns and the latest message with a rewrite instructionHandles varied phrasing; adds one model call per turn

Skip the rewrite when there is no history, as on the first message. Frameworks package this step: LlamaIndex's condense-question chat mode, for example, builds a standalone question from the conversation and the last message, then queries the index with it (as of November 2026). A rewrite instruction can be short:

Rewrite instruction
Rewrite the latest message as one standalone question that a reader
who has not seen the conversation could understand.
Keep every subject and condition it refers to. Do not answer it.
Do not add names, numbers, or conditions that are not in the conversation.
If the message starts a new topic, rewrite it from that message alone.
Return only the question.

Keep the original message and log both

The standalone query is a retrieval tool, not a replacement for what the user wrote. The generator still answers the user's actual message, keeping its tone and any format request, together with recent history.

InputRetrievalGeneratorTrace
Message as typedNoYesYes
Standalone queryYesNot neededYes
Session filtersYes, as filtersMay be stated as factsYes, with their source
Retrieved passagesIts outputYes, labeledTheir IDs

Logging both the original and the rewrite lets a reviewer tell a bad rewrite from a bad retrieval. Here is one turn of the travel assistant, for a contractor in the South region:

{
  "turn": 2,
  "original_message": "And for meals?",
  "standalone_query": "What is the limit for meals on trips abroad?",
  "rewrite": { "method": "model", "prompt_version": "rewrite-v3" },
  "decision": "retrieve",
  "filters": { "tenant": "tenant-a", "region": ["South", "all"], "audience": ["contractor", "all"] },
  "filters_source": "session",
  "retrieved_ids": ["TR4", "TR1"]
}

Scope comes from the session on every turn

Access scope decides which documents a user may see: tenant, employee, groups, region, employment type. On every turn, follow-ups included, the server looks it up from the authenticated session and passes it to retrieval as filters. Azure AI Search calls this security trimming: at query time the caller's identity becomes the filter, so documents that do not match are excluded.

Scope never comes from the message text ("I'm on the Finance team"), the standalone query, earlier assistant replies, or retrieved passages. A model rewrite that writes "for the Finance team" into the query has no authority to add Finance to the filters. An employee may still ask about the Finance team's travel limit: the query can mention Finance, because that is the question, but the filter stays the same.

Passages reused from an earlier turn were retrieved under that turn's scope; if the session has changed since, recheck them (Security & Privacy covers revocation and caches). OWASP LLM08:2025 (Vector and Embedding Weaknesses) lists inadequate access control on embedding stores as a cause of unauthorized retrieval and recommends permission-aware stores.

When not to retrieve

Retrieving on every turn has costs: each call adds cost and latency, new passages can change an answer the user only asked to reformat, and questions about the conversation itself ("What did I ask you first?") are answered from history. LlamaIndex notes that a chat mode that always queries the index can struggle with such meta questions.

Apply these checks in order to each new message.

  1. No new policy question. An acknowledgement, a greeting, an empty message, a question about the conversation itself, or a request to change the format, length, or tone of an earlier answer. Do not retrieve. Reply directly, or rework the earlier answer using only its facts and citations.
  2. Two possible referents. The message points back with "it", "that", or "this", two or more earlier things fit, and the answer would differ between them. Ask one short clarifying question, and retrieve after the reply.
  3. New topic. The message names its own subject and does not depend on earlier turns (this includes the first message). Retrieve with a query built from this message only, and drop entities from earlier turns.
  4. Follow-up. Anything else that depends on earlier turns. Rewrite it into a standalone query, then retrieve.

On every retrieval, the filters come from the session.

Worked session: an employee-policy assistant

Worked example

Suppose an internal policy assistant at a fictional company answers employees' questions from HR policy passages. The passages and figures are fictional.

Session facts (from the sign-in token and the HR record)

FieldValue
Tenanttenant-a
EmployeeE-417
RegionNorth
Employment typefull-time

Eligibility rule. A passage is eligible for an employee when its tenant matches, its region is the employee's region or all, and its audience is the employee's employment type or all. Regional documents are visible only to employees of that region.

Passages (all in tenant-a)

IDPassage (shortened)RegionAudience
P1Parental leave after a birth: 60 working days of paid leave.Northfull-time
P2Parental leave for adoption: 60 working days of paid leave, starting from the date of placement.Northfull-time
P3Parental leave after a birth or adoption: 45 working days of paid leave.Southfull-time
P4Adoption fee reimbursement: agency fees are reimbursed up to a fixed cap. Claim them through an expense report.allall
P5Parental leave for part-time staff: leave is pro-rated by contracted hours.Northpart-time
P6Requesting leave: submit the leave request form in the HR portal at least 30 days before the start date.allall
P7Internal job postings: how to apply for an open role.allall
P8Laptop damage: the company pays for one accidental-damage repair per year. Report it to the IT service desk.allall

Transcript (the assistant's replies after A2 are not shown)

TurnSpeakerMessage
T1EmployeeHow many days of parental leave do I get?
A1AssistantYou get 60 working days of paid parental leave after a birth [P1].
T2EmployeeWhat about if I adopt?
A2AssistantAdoption gives the same 60 working days of paid leave, starting from the date of placement [P2]. The company also reimburses adoption agency fees up to a fixed cap [P4].
T3EmployeeDo employees in the South region get the same number of days?
T4EmployeePut the adoption answer in two bullet points.
T5EmployeeThanks!
T6EmployeeHow do I apply for it?
T7EmployeeNever mind. My laptop screen cracked this morning. Who pays for the repair?

Predict what each turn should do

Use the session facts, the passages, and the four checks in "When not to retrieve".

Predict the outcome

Predict what each turn should do

For each employee message in the worked session, decide whether the assistant retrieves, asks a clarifying question, or replies without retrieval. For each retrieval, write the standalone query and the filters applied, then reveal the answers.

TurnEmployee messageDecisionStandalone queryFilters applied
T1How many days of parental leave do I get????
T2What about if I adopt????
T3Do employees in the South region get the same number of days????
T4Put the adoption answer in two bullet points.???
T5Thanks!???
T6How do I apply for it????
T7Never mind. My laptop screen cracked this morning. Who pays for the repair????

What a rewrite does not guarantee

A rewrite is model or template output, so it can be wrong. It can drop a condition, add an entity or number the conversation never mentioned, keep a stale entity after a topic switch, answer instead of rewriting, or pick one meaning of an ambiguous "it". Even a correct rewrite does not guarantee that retrieval finds the passage or that the answer uses it.

Log the original message and the rewrite together, and keep a handful of multi-turn cases with the expected decision and query (follow-up, reformat, ambiguous reference, topic switch, out-of-scope request). Rerun them when the rewrite prompt or model changes. Measurement at scale belongs to Evaluation & Observability.

Spot the faulty rewrite

These rows come from the travel assistant, not the policy session.

Predict the outcome

Spot the faulty rewrite

Each row shows an earlier turn, the latest message, and a proposed standalone query. Name the problem with the proposed query, if any, and write a better one before you reveal the answers. A good query keeps every subject and condition the conversation supplies, adds nothing the conversation does not contain, drops entities from an abandoned topic, and is a question rather than an answer.

Earlier turnLatest messageProposed rewriteProblemBetter query
Can I expense taxis on trips abroad?And rental cars?Can I expense rental cars???
Can I book business class?What about on long flights?Can managers book business class on flights over 6 hours???
What is the limit for meals on trips abroad?How do I book a meeting room for Friday?How do I book a meeting room abroad for Friday???
What is the hotel limit per night for trips abroad?Does that include breakfast?Yes, breakfast is included in the hotel limit.??
Can I book business class?Does that need approval?Does booking business class need approval???

Completion checklist

  • Explain why T2 fails as a query and write its standalone query.
  • Name E-417's filter values and where each one comes from.
  • Predict the decision for all seven turns without looking.
  • Say whether each proposed rewrite has a fault, and name it.

Sources

The session, policy passages, travel examples, transcript, fixtures, and rubric are original synthetic teaching material about fictional assistants; the leave figures are not real entitlements. Study times and readiness thresholds are editorial estimates. Framework behavior is cited as an example and is as of November 2026; check the current documentation of the library you use.

Practice the interview question

Answer it in your own words before you look at the reference answer.