AI EngineeringInterview preparation
Intermediate·Concept·2 min read

Retrieval, context construction, and prompt construction

Practice this question

Overview

  • Retrieval selects candidate evidence.
  • Context construction chooses which evidence and conversation details the model sees.
  • Prompt construction combines trusted instructions, the user's question, and clearly labeled untrusted source material.

Why this matters

Retrieved data alone does not specify how to answer, handle gaps, or resolve conflicting sources.

An everyday example

An employee selects the applicable handbook pages and a task brief rather than placing every document on the desk.

A technical example

Provide S1: [policy/version/page] passage, S2: ..., and require source IDs for material claims.

How it works

  1. Derive filters
  2. Search
  3. Merge/rerank
  4. Remove duplicates
  5. Select complete clauses
  6. Enforce token budget
  7. Build prompt with evidence and abstention instructions.

Architecture and flow

Eligible candidates → relevance/freshness checks → context budget → prompt → answer.

The insurance assistant example

Use the customer's policy wording, not a generic product brochure, when explaining exclusions.

When to use it

Every RAG answer should have an explicit context-building policy.

When to avoid it

Do not stuff top-100 results into the prompt or instruct the model to follow instructions found inside documents.

Interview answer

“I retrieve broadly enough for recall, select precise eligible evidence, and give the model clear grounding and abstention rules.”

Benefits, trade-offs, and production considerations

  • Distinguish “no results,” “search failed,” and “sources conflict.” These need different responses.
  • A vector score alone is insufficient to confirm answerability; validate complete, applicable supporting evidence.
Adapted from 13_AI.MD · “Retrieval, context construction, and prompt construction”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.