AI Engineering Interview Preparation

Interview-ready answers to the 44 questions covered by the AI Upskill program — RAG architecture, vector databases, model configuration, context management, and model selection. Each answer opens with a spoken-length summary, then the depth an interviewer will probe for.

44Questions
5Sections
3Depth tiers
26Tables & diagrams
01

RAG Architecture

How retrieval-augmented generation works, why it exists, and how it breaks in production.

OFFLINE — INDEXING Documents Chunksplit + overlap Embedtext → vector Vector storeHNSW index ONLINE — QUERY TIME User query Embed querysame model Retrieve top-kANN search Rerankcross-encoder Augment promptcontext + query LLM generate+ citations grounded answer
The two halves of every RAG system: an offline indexing pipeline and an online query pipeline. They must share the same embedding model.
Foundational
1.1Can you explain what Retrieval-Augmented Generation (RAG) is and walk me through its core workflow from user query to final response?

RAG is a pattern where, instead of relying on what a model memorised during training, you retrieve relevant documents at query time and put them into the prompt so the model answers from evidence you control.

There are two pipelines. Offline (indexing): documents are loaded, cleaned, split into chunks, passed through an embedding model that turns each chunk into a dense vector, and written to a vector store alongside the original text and metadata.

Online (query time):

  1. The user's query is embedded with the same model used at index time.
  2. The vector store runs an approximate nearest-neighbour search and returns the top-k most similar chunks.
  3. Optionally a reranker — usually a cross-encoder — rescores those candidates and keeps the best few.
  4. The surviving chunks are pasted into a prompt template alongside the question and an instruction like “answer only from the context; if the answer isn't there, say so.”
  5. The LLM generates the answer, ideally citing the chunk IDs it used.

The key insight to say out loud: RAG does not change the model's weights. It changes what is in the context window at inference time. That is why it is cheap to update — reindex a document and the system's knowledge changes instantly.

Trap to avoid

Don't describe RAG as "the model searches the internet." The model does no searching — your retrieval layer does, and the model only sees text you chose to hand it. Interviewers use this to check whether you understand where the boundary sits.

Say these wordschunkingembeddingtop-kANNrerankergroundingcitation
1.2Why would you choose RAG instead of relying solely on a pre-trained LLM? What problem does it solve?

A pre-trained LLM knows only what was in its training data, has no idea which parts it actually knows, and cannot cite anything. RAG fixes all three by grounding answers in retrievable, attributable source text.

Concretely it solves four problems:

Knowledge cutoff
The model cannot know about your product launched last week, or last night's incident report. Retrieval supplies it.
Private data
Your contracts, tickets and wiki were never in any public training set — and you don't want them there.
Hallucination
Grounding in retrieved text plus an instruction to abstain measurably reduces fabricated answers, and gives you something to check the answer against.
Attribution
You can show the user the source paragraph. In regulated domains this is often a hard requirement, not a nice-to-have.

Compared with the alternatives: fine-tuning teaches style, format and task behaviour but is a poor and expensive way to inject facts — and you must retrain to update them. Long-context stuffing (dumping the whole corpus in the prompt) works for a few hundred pages but scales badly on cost, latency and attention quality. RAG is the option where knowledge updates are a database write.

Strong closing line

“Fine-tuning changes how the model behaves; RAG changes what it knows. Most production systems eventually need a bit of both.”

1.3What are the key components of a RAG pipeline, and how do they interact with each other?

Seven components: ingestion, chunker, embedding model, vector store, retriever, reranker, and generator — plus an evaluation loop wrapped around the whole thing.

ComponentJobContract with its neighbours
Ingestion / parsingLoad PDFs, HTML, tickets; strip boilerplate; extract tablesEmits clean text + metadata (source, date, permissions)
ChunkerSplit into retrievable units with overlapChunk size must fit the embedding model's window and leave room in the LLM's context
Embedding modelText → dense vectorMust be identical at index and query time, and its dimensionality fixes the store's schema
Vector storePersist vectors + payload, serve ANN searchIndex type and metric (cosine / dot) must match how embeddings were trained
RetrieverTurn a query into candidate chunks; apply metadata filtersReturns top-k (often 20–50) for the reranker to narrow
RerankerCross-encoder rescoring of query+chunk pairsHigh precision, high cost — runs on tens of candidates, not millions
Generator (LLM)Synthesise a grounded answer with citationsNeeds low temperature and an explicit abstain instruction

The interaction that matters most: quality is bounded by the weakest upstream stage. A frontier LLM cannot rescue a retriever that returned the wrong paragraph, and a great retriever cannot rescue a chunker that cut a table in half. That is why debugging starts at ingestion, not at the prompt.

Intermediate
1.4How does the retrieval step in RAG differ from a traditional keyword-based search?

Keyword search matches strings; vector search matches meaning. BM25 asks “which documents contain these tokens?”, dense retrieval asks “which chunks sit closest to this query in embedding space?”

Keyword (BM25 / inverted index)Dense vector retrieval
Unit of matchExact tokens, stemmedSemantic proximity in ℝⁿ
Handles synonymsNo — “car” ≠ “automobile”Yes — that's the whole point
Rare identifiersExcellent — SKUs, error codes, namesWeak — rare tokens get smoothed away
ExplainabilityYou can see which terms matchedA similarity score with no human-readable reason
Cost of indexCheap, sparseEmbedding compute + memory-heavy index

Two things follow. First, dense retrieval returns something for every query — there's no "no results". A low-relevance answer still comes back with a plausible-looking score, so you need a similarity threshold or a reranker to decide when to say "I don't know."

Second, and this is the answer interviewers want: in production you rarely pick one. Hybrid search runs both and fuses the rankings, because the two fail in opposite directions.

Trap to avoid

Claiming vector search is simply "better." A user searching for invoice INV-2024-8871 or the error ECONNRESET is far better served by BM25. Saying so signals production experience.

1.5What happens when the retrieved context is irrelevant or contradicts the model's training data? How would you handle that?

Two distinct failures. Irrelevant context distracts the model into confidently wrong answers; contradictory context creates a conflict between parametric memory and retrieved evidence, and which one wins is not something you should leave to chance.

Irrelevant context. Models are strongly biased toward using what they're given — a plausible-looking but wrong passage often produces a worse answer than no context at all. Mitigations:

  • Set a similarity floor; if nothing clears it, don't call the LLM with junk — return "no supporting information found."
  • Add a reranker and keep only the top 3–5 after rescoring.
  • Add a lightweight relevance grader (a cheap model that labels each chunk keep/discard) — this is the core idea behind Corrective RAG.
  • Prompt explicitly: “If the context does not contain the answer, reply exactly: Not found in the provided sources.

Contradiction with training data. Decide the precedence rule deliberately and state it in the system prompt: for enterprise knowledge, retrieved documents should win, because they're current and authoritative. Then reinforce it structurally — put source, date and authority level in the context block, and instruct the model to prefer the most recent authoritative source and to surface the disagreement rather than silently pick a side.

What they're really testing

Whether you know that "just tell it to use the context" is not enough on its own. The strong answer pairs a prompt-level rule with a retrieval-level filter and an evaluation metric (faithfulness) that catches regressions.

1.6Can you describe the difference between naive RAG, advanced RAG, and modular RAG architectures?

They're three generations of the same idea: naive RAG is retrieve-then-read in a straight line; advanced RAG adds pre- and post-retrieval optimisation around that line; modular RAG breaks the line into reconfigurable components with routing and loops.

GenerationShapeTechniquesWhen it's enough
NaiveIndex → retrieve top-k → generateFixed chunk size, single dense retrieval, one promptDemos, small homogeneous corpora, first sprint
AdvancedSame line, optimised at both endsPre: query rewriting, HyDE, multi-query expansion, semantic/structure-aware chunking, metadata enrichment. Post: cross-encoder reranking, context compression, deduplication, ordering the best chunk first and lastMost real production systems
ModularA graph of swappable modules, possibly loopingRouters (vector vs SQL vs web), agentic/iterative retrieval, self-reflection and retry (Self-RAG), corrective retrieval fallbacks (CRAG), memory modules, multi-hop planningHeterogeneous sources, multi-hop questions, agentic products

The progression is driven by failure, not fashion. You move to advanced RAG when you discover retrieval is missing obviously relevant documents. You move to modular RAG when a single retrieval pass structurally cannot answer the question — “compare our 2024 and 2025 refund policy and tell me what changed” needs two retrievals and a comparison step.

Trap to avoid

Jumping straight to agentic RAG. Each loop multiplies latency and cost and adds new failure modes. The senior answer is: start naive, measure, and let the evaluation data justify each addition.

Name-dropHyDEmulti-querySelf-RAGCRAGGraphRAGcontext compression
Deep-dive
1.7How would you evaluate the quality of a RAG system? What metrics would you use?

Evaluate retrieval and generation separately, because they fail separately — then add end-to-end and operational metrics on top. If you only measure the final answer you cannot tell whether a bad answer came from bad retrieval or bad synthesis.

Retrieval metrics (need a labelled set of query → relevant-chunk pairs):

  • Recall@k — did the right chunk appear in the top k? Usually the single most important number; if recall is low, nothing downstream can save you.
  • Precision@k — how much of what you retrieved was noise.
  • MRR / nDCG@k — rank-aware: was the right chunk near the top, not just present.

Generation metrics (typically LLM-as-judge, e.g. RAGAS-style):

  • Faithfulness / groundedness — is every claim supported by the retrieved context? This is your hallucination detector.
  • Answer relevance — does it actually address the question asked.
  • Context precision / recall — bridges the two halves: was the useful context ranked highly and was all needed context present.
  • Citation accuracy — do the cited sources really contain the claim.

Operational: p50/p95 latency by stage, cost per query, abstention rate, and — the one that matters commercially — human thumbs-up rate on real traffic.

How to sound senior

“I'd build a golden set of 100–300 real questions with annotated source chunks, run it in CI on every prompt or index change, and treat a Recall@10 or faithfulness regression as a failing build. Offline eval gates the deploy; online feedback and abstention rate tell me whether the offline set still reflects reality.”

1.8What are the failure modes of a RAG pipeline, and how would you debug them in production?

Almost every RAG failure lands in one of six buckets, and you localise it by walking the pipeline backwards from the answer: check what was retrieved before you touch the prompt.

#Failure modeSymptomFix
1Missing contentAnswer is wrong; correct chunk isn't in the index at allIngestion gaps, failed PDF parse, permissions filter too strict
2Retrieval missChunk exists but isn't in top-kHybrid search, query rewriting, better embedding model, raise k then rerank
3Ranking failureRight chunk retrieved but buried at rank 40Add cross-encoder reranker; tune fusion weights
4Context lossRight chunk in the prompt, ignored by the model“Lost in the middle” — trim context, reorder best-first, compress
5Extraction / synthesis errorAnswer contradicts the context it was givenLower temperature, stricter prompt, stronger model, force citations
6Chunking damageHalf a table, an orphaned "it depends", a split sentenceStructure-aware splitting, overlap, parent-document retrieval

The debugging procedure: log every query with its retrieved chunk IDs, scores, final prompt, and answer — this is non-negotiable and is the difference between debugging and guessing. Then for a failing query: (a) is the answer in the corpus at all? (b) if yes, does it appear at any k up to 100? (c) if yes, is it in the final prompt after reranking and truncation? (d) if yes, it's a generation problem. Each "no" points at exactly one stage.

Add if there's time

Mention silent regressions: an embedding model version bump, a document re-parse, or a chunk-size change can quietly wreck recall with no error anywhere. Version your index and pin your embedding model.

1.9How would you handle a scenario where the user's query requires information from multiple retrieved chunks that may conflict with each other?

First establish whether it's a real contradiction or just two documents from different points in time — most "conflicts" in enterprise corpora are versioning problems, and metadata solves them before the LLM ever sees the text.

1. Prevent avoidable conflicts at index time. Every chunk carries source, effective_date, version, authority_tier and status. Deprecated policies get filtered out or down-weighted at retrieval, so the model never has to arbitrate between the 2023 and 2025 handbook.

2. Deduplicate and cluster. Near-identical chunks waste context and amplify whichever version happens to be duplicated more. Collapse them, keeping the newest.

3. Give the model an explicit resolution policy. Present each chunk with a labelled header ([S3 | Policy Manual | v4 | 2025-06-01]) and instruct: prefer the most recent authoritative source; if sources genuinely disagree on a material point, state both positions with their citations rather than silently choosing.

4. For multi-hop questions, decompose. If the answer requires combining facts rather than choosing between them — "which of our EU customers is affected by the clause added in v4?" — a single retrieval pass is the wrong tool. Break the query into sub-questions, retrieve per sub-question, then synthesise.

5. Surface, don't hide. Returning “Source A says 30 days, Source B (newer) says 14 days — I've used 14” is a better product outcome than a confident single number, and it's usually what a compliance stakeholder actually wants.

Trap to avoid

Suggesting the model should "average" or "pick the most common" answer. Majority voting across duplicated documents is how stale policies win. Recency plus authority beats frequency.

02

Vector Databases

Embeddings, index structures, the accuracy/speed/memory triangle, and hybrid retrieval at scale.

Flat (brute force) compares every vector · 100% recall · O(N) IVF (cluster + probe) searches nprobe clusters only · fast build · misses edges HNSW (layered graph) L2L1L0 coarse-to-fine hops · O(log N) · high recall, high RAM
The three index families you will be asked to compare. Flat is exact and slow; IVF partitions the space; HNSW navigates a multi-layer proximity graph.
Foundational
2.1What is a vector database, and how is it fundamentally different from a traditional relational database?

A vector database is built around one operation a relational database cannot do efficiently: find the k items whose high-dimensional embeddings are closest to a query vector. Relational databases answer “which rows match exactly?”; vector databases answer “which rows are most similar?”

Relational DBVector DB
Query typeExact predicates, joins, rangesk-nearest-neighbour by distance
IndexB-tree, hash — 1-D ordered keysHNSW graph, IVF lists, PQ codebooks
ResultDeterministic set — a row matches or it doesn'tRanked list with similarity scores; approximate by design
Correctness bar100% — exactness is the contractRecall of ~95–99% traded for speed
Scaling painWrite throughput, join complexityMemory footprint of the index; index rebuild cost

The deeper reason B-trees don't work: they rely on a total ordering of one dimension. In 768 or 1536 dimensions there is no meaningful sort order, and classic spatial structures like KD-trees degenerate to brute force — the “curse of dimensionality.” So the field gave up on exactness and built approximate structures instead.

Nuance worth adding

“Vector database” is increasingly a feature, not a product category — pgvector puts ANN indexes inside Postgres, and most warehouses and search engines now ship vector types. The interesting question is usually whether you need a dedicated system, not whether you need vectors.

2.2Can you explain what an embedding is and how it is generated from raw text?

An embedding is a fixed-length list of floats — typically 384 to 3072 dimensions — that represents the meaning of a piece of text, arranged so that texts with similar meaning end up close together geometrically.

How it's produced: the text is tokenised, the tokens go through a transformer encoder, and the resulting per-token hidden states are pooled into a single vector — usually mean pooling or the [CLS] token. That vector is then normalised so cosine similarity reduces to a dot product.

Why the geometry means anything is the part people skip: it's the training objective. Embedding models are trained contrastively — pull matched pairs (a question and its answer, a sentence and its paraphrase) together, push mismatched pairs apart, typically with InfoNCE loss over in-batch negatives. The geometry is learned, not inherent.

Three practical consequences:

  • Similarity is model-specific. Two models' vectors are not comparable, even at the same dimensionality.
  • The training data defines "similar." A model trained on web Q&A may cluster legal clauses badly; domain models exist for a reason.
  • Asymmetric tasks need asymmetric handling. Many models expect prefixes like query: / passage:; omitting them quietly costs you recall.
Termscontrastive learningmean poolingcosine similaritydimensionalityMatryoshka
2.3Why do we store embeddings in vector databases rather than in standard databases?

You can store them anywhere — a float array is just bytes. What you can't do in a standard database is search them fast, because there's no index that makes similarity search sublinear without a purpose-built ANN structure.

Put ten million 1536-dimension vectors in a plain table and every query becomes a full scan: ten million dot products of 1536 floats each. That's tens of gigabytes of memory bandwidth per query — hundreds of milliseconds to seconds, single-user. A vector index turns that into a few thousand comparisons and single-digit milliseconds.

Beyond the index, purpose-built stores give you things you'd otherwise build yourself:

  • Filtered ANN — combining metadata predicates with similarity search without destroying recall (harder than it sounds; naive post-filtering can return nothing).
  • Quantization and compression — scalar/product/binary quantization to fit the index in RAM.
  • Hybrid scoring — built-in BM25 + dense fusion.
  • Operational tooling — sharding, replication, namespaces/multi-tenancy, live re-indexing.
The answer that lands

“Below roughly a million vectors, pgvector in the database you already run is usually the right call — one less system, transactional consistency with your source rows. The argument for a dedicated vector DB is scale, filtered-search quality, and operational features, not the ability to store an array.”

Intermediate
2.4What indexing strategies are used in vector databases (HNSW, IVF, Flat)? Explain the trade-offs.

Every index is a point on the same triangle: recall, latency, and memory. Flat maximises recall, HNSW maximises speed at high recall but costs RAM, IVF is the memory-and-build-time compromise, and quantization is the lever you pull on any of them.

IndexHow it worksRecallSpeedMemoryUse when
FlatExhaustive scan, exact distances100%O(N)Vectors only<100k vectors, or generating ground truth to measure other indexes
IVF / IVF-PQk-means into nlist cells; search nprobe nearest cellsTunable via nprobeFastLow (esp. with PQ)Very large static corpora, memory-constrained, batch rebuilds acceptable
HNSWMulti-layer navigable small-world graph; greedy descent95–99%+O(log N)High — graph edges often exceed vector sizeDefault for online RAG; incremental inserts needed
ScaNN / DiskANNAnisotropic quantization; graph on SSDHighHighDisk-residentBillion-scale where RAM is the binding cost

The knobs to name: HNSW has M (edges per node — more edges, better recall, more memory), ef_construction (build-time effort) and ef_search (query-time effort — the runtime recall/latency dial). IVF has nlist and nprobe. Being able to say “I'd fix M and ef_construction at build time and tune ef_search against a recall target measured on a Flat baseline” is what separates a read-about-it answer from a used-it answer.

Trap to avoid

Forgetting HNSW's weakness: deletes are soft (tombstones) and the graph degrades under heavy churn, so high-update workloads need periodic rebuilds. IVF also drifts as data distribution shifts away from the centroids it was trained on.

2.5How does Approximate Nearest Neighbor (ANN) search work, and why is it preferred over exact search in production?

ANN deliberately gives up the guarantee of finding the true nearest neighbours in exchange for sublinear search time — and it's the right trade because in RAG a 98%-correct neighbour list produces an indistinguishable answer at a fraction of the cost.

The mechanism is always some form of "don't look at most of the data":

  • Graph-based (HNSW): vectors become nodes connected to their neighbours across layers of decreasing sparsity. A search enters at the top layer, greedily hops toward the query, drops a layer, repeats. Long edges at the top cover distance; short edges at the bottom give precision. Roughly O(log N).
  • Partition-based (IVF): cluster the space once, then only scan the few cells nearest the query.
  • Hash-based (LSH): hash functions that collide for nearby vectors; check only the matching buckets.

Why exact search loses: at 10M × 1536 dims, brute force is ~15 GFLOPs of dot products per query. That's fine offline, impossible at 100 QPS with a 50 ms budget. And the accuracy you're buying is largely illusory — the embedding itself is a lossy approximation of meaning, so insisting on the exact top-10 of an approximate representation is false precision.

Show you'd measure it

“Recall isn't a vibe — I'd compute ground truth on a sample with a Flat index and tune ef_search until Recall@10 hits, say, 0.98, then check what that costs in p95 latency. That's a business decision, not a default.”

2.6Which vector databases have you worked with? What were your criteria for selecting one over another?

Answer this with a decision framework plus honest specifics — interviewers can tell instantly when someone lists six databases they've only read about. Name what you actually used, then show you know the landscape.

OptionShapeStrengthWatch out for
pgvectorPostgres extensionNo new infrastructure; joins and transactions with your real data; HNSW + quantization is enough for ~10M vectorsYou inherit Postgres' scaling story; index builds are heavy
QdrantOpen-source, RustBest-in-class filtered search, strong hybrid, memory-efficient, easy self-hostSmaller ecosystem than Pinecone
PineconeManaged SaaSZero ops, serverless scaling, mature RAG integrationsCost at scale; vendor lock-in; data residency questions
WeaviateOSS + cloudBuilt-in hybrid search, GraphQL, modules that embed for youHeavier resource footprint
MilvusOSS, distributedGenuinely billion-scale, many index types, GPU supportComplex — needs a platform team
Chroma / FAISSEmbedded libraryFastest path to a prototype; FAISS is the research referenceNot a production database on their own

My selection criteria, in order: (1) scale and expected growth — under a million vectors, the answer is usually "the database you already have"; (2) filtering requirements, especially multi-tenant permission filters, where naive post-filtering silently destroys recall; (3) hybrid search support; (4) ops model — managed vs. self-hosted vs. a team that can run a distributed system; (5) data residency and compliance; (6) cost at projected QPS, not at demo scale.

Honest framing that works

“I've run X in production and prototyped with Y. If I were starting today for <10M vectors I'd default to pgvector, move to Qdrant when filtered-search quality or throughput demanded it, and only reach for Milvus at 100M+.”

Deep-dive
2.7How would you handle embedding drift when your embedding model is updated but your vector store still contains old embeddings?

You can't mix them. Vectors from two different models live in incomparable spaces, so a query embedded with v2 searched against a v1 index returns effectively random results — and it fails silently, with plausible-looking scores. The only correct answer is a full re-embed, executed as a versioned migration.

The migration pattern:

  1. Version everything. Every collection and every vector row carries embedding_model and model_version. Queries assert the version they expect and fail loudly on mismatch.
  2. Build alongside, don't mutate. Create a new v2 collection and backfill it from the stored raw chunk text — which is why you keep the source text in the payload, not just the vector.
  3. Evaluate before switching. Run the golden query set against v1 and v2. A newer model with better MTEB scores can still be worse on your domain; this step is not optional.
  4. Shadow, then cut over. Serve from v1 while mirroring traffic to v2, compare retrieved sets and downstream answer quality, then flip behind a feature flag with a one-line rollback.
  5. Retire v1 after a bake period; keep the option to roll back until you're confident.

Cost control: backfill in batches off-peak, prioritise hot documents, and use a queue so ingest of new documents continues writing to both collections during the transition.

The distinction to draw

Separate model change drift (incompatible spaces — must re-embed) from data drift (the model is unchanged but your corpus vocabulary has moved — new products, new jargon). The second doesn't require re-embedding; it requires monitoring retrieval quality and possibly fine-tuning or swapping models. Interviewers love candidates who notice they're two different problems.

2.8What strategies would you use to optimize retrieval relevance in a vector database at scale?

Work the pipeline in order of leverage: representation first, then retrieval strategy, then ranking, then the index parameters. Tuning ef_search is the last thing I'd do, not the first — index tuning buys recall against your own embeddings, not relevance.

1 · Representation. Pick the embedding model empirically on your data, not from a leaderboard. Fix the chunking — structure-aware splits that respect headings, tables and code blocks, with overlap; prepend document title and section path to each chunk so a fragment carries its context. Consider parent-document retrieval: embed small precise chunks, return the larger parent for generation.

2 · Retrieval strategy. Hybrid dense + BM25 fused with Reciprocal Rank Fusion. Query rewriting for conversational follow-ups ("what about the second one?" is meaningless as an embedding). Multi-query expansion for recall. Metadata pre-filtering to shrink the candidate space before scoring.

3 · Ranking. Retrieve wide (k=50–100), rerank narrow (keep 3–8) with a cross-encoder. This is typically the single largest relevance gain available, because a cross-encoder sees query and passage jointly rather than comparing two independently-computed vectors. Add business-aware boosts: recency, authority, document type.

4 · Index and infra. Now tune ef_search/nprobe against measured recall; quantize to fit in RAM; shard by tenant so filters become cheap; cache embeddings for repeated queries.

Close with measurement

“All of this is guesswork without a golden set and offline eval in CI. I'd change one thing at a time and keep the Recall@k / nDCG deltas.”

2.9How would you design a hybrid search system that combines vector similarity search with keyword-based filtering?

Distinguish two things that both get called "hybrid": fusion of two ranked result sets (dense + sparse), and filtering by structured metadata. They're different problems with different failure modes.

Fusion — combining BM25 and vector results. The scores aren't comparable (BM25 is unbounded, cosine is [-1,1]), so don't naively add them. Use Reciprocal Rank Fusion: score = Σ 1/(k + rank_i), typically k=60. It's rank-based, needs no score normalisation, and is remarkably hard to beat. If you do want weighted score fusion, normalise per-query (min-max over the returned set) and expose the weight as a tunable α — then tune α on your golden set, not by intuition.

Filtering — the part that actually bites. Three strategies:

StrategyHowFailure mode
Post-filterANN first, drop non-matching resultsEmpty or thin results when the filter is selective — the top-100 may contain zero matches
Pre-filterResolve the predicate, then brute-force within the subsetSlow when the subset is still large
Filtered ANNPredicate evaluated during graph traversal (Qdrant, Weaviate, Milvus)Best of both; graph connectivity can degrade under very selective filters

The design I'd propose: permissions and tenancy as hard pre-filters (never post-filter security — it's a correctness and leak risk, and thin results are the least of it); soft attributes like recency and doc type as reranking boosts; dense + BM25 fused with RRF; cross-encoder rerank over the fused top-50; return top-5 with citations. Then measure each stage's contribution by ablation.

TermsRRFBM25SPLADEpre/post-filtercross-encoder
03

Model Configuration & Parameters

What each sampling knob actually does to the probability distribution — and which one to touch when output goes wrong.

Raw logits next-token scores ÷ T Temperature T = 0.2 · peaked T = 1.4 · flat Top-K = 3 fixed count, ignores shape Top-P = 0.9 cumulative mass, adapts Order of operations: logits → temperature → top-k → top-p → renormalise → sample
Temperature reshapes the distribution; top-k and top-p truncate it. Penalties act on the logits before any of this.
Foundational
3.1What does the temperature parameter control in an LLM, and when would you set it low versus high?

Temperature is a divisor applied to the logits before the softmax. It controls how sharply peaked the next-token probability distribution is — low temperature concentrates probability on the model's top candidates, high temperature flattens the distribution and lets unlikely tokens through.

Mathematically: p_i = softmax(z_i / T). As T → 0 the distribution collapses onto the argmax (greedy decoding). At T = 1 you sample from the model's raw learned distribution. Above 1 you're deliberately flattening it.

SettingBehaviourUse for
0 – 0.2Near-deterministic, repetitive, safeRAG answers, classification, extraction, JSON/tool-call generation, code, SQL
0.3 – 0.7Slight variety, still coherentSummarisation, chat assistants, rewriting
0.8 – 1.2Creative, surprising, occasionally incoherentBrainstorming, fiction, marketing variants, synthetic data diversity
>1.5Frequently degenerateRarely useful outside experiments
Trap to avoid

Saying "temperature 0 stops hallucination." It doesn't. It makes the model deterministically produce its most likely output — and if the most likely output is wrong, you now get the same wrong answer every time. Temperature controls variance, not truth. Grounding controls truth.

3.2What is the max tokens parameter, and how does it affect the model's response?

Max tokens is a hard ceiling on how many tokens the model may generate. It is not a length instruction — the model doesn't plan around it. When the limit is hit, generation stops mid-sentence and the API returns a length finish reason.

Three things to get right:

  • It's output-only, but it competes with input. Input + output must fit the context window. Many APIs reserve the max-tokens budget up front, so an over-generous setting can cause a request to fail even though the actual answer would have been short.
  • It's a cost and latency cap, not a style control. To get short answers, instruct the model ("answer in two sentences") and set max tokens as a safety net. Relying on the cap alone gives you truncated garbage.
  • Always check the finish reason. A response truncated at the limit is a bug you should detect and handle — retry with a larger budget, or stream and continue — not silently ship. This is especially dangerous with JSON output, where truncation produces unparseable results.

Reasoning models add a wrinkle worth mentioning: thinking tokens consume the output budget before any visible text is produced, so a limit that was comfortable for a non-reasoning model can leave nothing for the actual answer.

One-liner that shows care

“I set max tokens to roughly 1.5× the longest legitimate answer I've observed, log every finish_reason == "length", and alert if that rate rises.”

Intermediate
3.3Explain Top-P (nucleus sampling) and how it differs from Top-K. When would you use one over the other?

Both truncate the candidate set before sampling. Top-K keeps a fixed number of tokens; Top-P keeps however many tokens are needed to reach a cumulative probability mass. The difference is that Top-P adapts to the shape of the distribution and Top-K doesn't.

Worked example. Suppose the model is very confident — the top token has p = 0.92. With Top-K = 40 you've just admitted 39 tokens with a combined 8% probability, giving nonsense a chance it didn't earn. With Top-P = 0.9 the nucleus is a single token; you sample the obvious continuation. Now suppose the model is genuinely uncertain, with 200 tokens each around 0.4%. Top-K = 40 arbitrarily amputates a legitimate long tail; Top-P = 0.9 expands to include ~180 of them.

Top-KTop-P (nucleus)
RuleKeep the K highest-probability tokensKeep the smallest set whose cumulative p ≥ P
Candidate countFixedVaries per token
Confident modelAdmits junkNarrows automatically
Uncertain modelCuts valid optionsWidens automatically
Typical values20–500.9–0.95

Which to use: Top-P is the sensible default and is what most APIs expose. Top-K is useful as a hard safety cap on the tail, and some stacks apply both (K first, then P). The practical guidance most providers give — and a good line to repeat — is tune temperature or top-p, not both simultaneously, because you can't attribute the effect.

3.4What are frequency and presence penalties? How do they influence repetition and diversity?

Both subtract from the logits of tokens that have already appeared, discouraging repetition — but they differ in whether the penalty scales with how often the token appeared.

frequency_penalty
Penalty proportional to the count of prior occurrences. A word used five times is penalised five times as hard as one used once. Targets verbatim loops and overused words.
presence_penalty
Flat penalty applied once a token has appeared at all, regardless of count. Pushes the model toward introducing new vocabulary and new topics.

Typical ranges are −2.0 to 2.0, with useful values usually between 0.1 and 0.8. Rules of thumb: use a small frequency penalty when output degenerates into repeated phrases; use a small presence penalty when you want topical breadth, e.g. "give me 20 distinct ideas" where the model keeps circling the same three.

Trap to avoid — this is the real answer

These penalties are blunt token-level instruments with no semantic awareness. Push them above ~1.0 and the model starts avoiding words it needs: technical terms, the subject's name, required JSON keys, recurring identifiers in code. In factual or structured-output tasks, high penalties actively cause errors. For most RAG and extraction workloads the right value is 0 — if you're seeing repetition there, fix the prompt or the retrieved context, not the sampler.

Note also that not every provider exposes both; some expose a single repetition penalty (a multiplicative variant common in open-source stacks), which is worth flagging if you're asked about portability across models.

3.5How would you configure parameters differently for a creative writing task versus a factual Q&A system?

They optimise for opposite properties: creative writing wants variance and surprise, factual Q&A wants reproducibility and grounding. Almost every parameter moves in the opposite direction.

ParameterFactual Q&A / RAGCreative writingWhy
temperature0 – 0.20.8 – 1.1Reproducibility vs. surprise
top_p1.0 (let temperature do the work)0.9 – 0.95Trim the incoherent tail without flattening voice
frequency_penalty00.2 – 0.5Facts need repeated terms; prose doesn't
presence_penalty00.2 – 0.6Encourage new imagery and topics
max_tokensTight — answers are shortGenerousCost control vs. room to develop
stop sequencesOften used for structureRareStructured output needs boundaries
seedSet itLeave unsetRegression testing vs. variety across generations

Beyond sampling, the whole configuration differs. Factual Q&A gets a strict system prompt with an abstain instruction, structured output / JSON schema enforcement, low top-k retrieval with citations, and a faithfulness check on the output. Creative writing gets a rich persona prompt, few-shot style examples, no schema, and human judgement instead of automated scoring.

Bonus point

Mention generating n candidates at high temperature and selecting the best with a critic model — the creative-task equivalent of retrieval reranking.

Deep-dive
3.6What is output determinism, and how would you achieve near-deterministic outputs in production?

Determinism means identical inputs produce identical outputs. Note the word "near" in the question — that's deliberate, and acknowledging why full determinism is unattainable with a hosted model is the point of the question.

What you control:

  • temperature = 0 (greedy decoding) and a fixed seed where the provider supports one.
  • Pin the model versionmodel-2026-05-01, never a floating -latest alias. Silent model upgrades are the most common cause of "it changed and we didn't touch anything."
  • Freeze the prompt, and everything that composes it: template version, retrieved chunks, chunk order. In RAG this is the big one — non-deterministic retrieval makes the LLM's determinism irrelevant.
  • Constrain the output space — JSON schema / structured outputs / grammar-constrained decoding removes whole classes of variation.
  • Cache — for a genuinely fixed input, serving a cached response is exact determinism, and it's cheaper.

Why residual non-determinism remains: floating-point addition isn't associative, so GPU kernel reductions vary with batch composition and hardware; providers batch requests from many tenants, so your numerics depend on who else is calling. Ties in the argmax then break differently, and a single divergent token cascades. Mixture-of-experts routing adds another batch-dependent source. Providers expose system_fingerprint precisely so you can detect when the backend configuration changed.

How to close

“So I'd design for stability rather than bit-exactness: pin versions, constrain outputs, cache, and — most importantly — write tests that assert semantic properties (schema valid, correct field extracted, faithful to context) rather than exact string equality. String-equality tests against an LLM are flaky by construction.”

3.7How do parameters like temperature interact with each other? Can conflicting settings cause unintended behaviour?

Yes — they compose in a specific order, and several common combinations are either redundant or actively self-defeating. The pipeline is: logits → penalties → temperature scaling → top-k truncation → top-p truncation → renormalise → sample.

The interactions that matter:

  • Temperature 0 makes top-p and top-k inert. Greedy decoding picks the argmax; truncating a distribution you never sample from changes nothing. Setting temperature=0, top_p=0.7 isn't wrong, it's just theatre — and it misleads the next engineer into thinking top_p is doing something.
  • High temperature + low top-p partially cancel. You flatten the distribution, then cut off the tail you just created. The result is more uniform sampling among a few candidates — not the same as either setting alone, and hard to reason about. This is why the standard advice is to tune one.
  • Low temperature + high penalties fight each other. The temperature says "be confident and consistent"; the penalty forcibly suppresses the confident token because it appeared before. In structured output this produces malformed JSON — the model is banned from repeating a key it needs.
  • Top-k and top-p together: the more restrictive one wins for that token, so the effective behaviour flips between them unpredictably as the distribution shape changes.
  • max_tokens interacts with everything downstream: higher temperature tends toward more rambling output, which hits the ceiling more often, which shows up as truncation bugs rather than as a sampling problem.
The principle to state

“Change one parameter at a time, against a fixed eval set, and record the deltas. Most production configs I've seen with five tuned knobs are the residue of undocumented debugging, and half the settings do nothing.”

3.8If a deployed model is producing inconsistent or hallucinated outputs, which parameters would you adjust first and why?

I'd separate the two symptoms first, because they have different causes. Inconsistency is usually a sampling or version problem and parameters fix it. Hallucination is usually a grounding problem, and parameters barely touch it — so answering “lower the temperature” alone is the wrong answer here.

For inconsistency — parameters first, in this order:

  1. temperature → 0–0.2. Biggest single lever on variance.
  2. Check for a floating model alias; pin the version. Then check system_fingerprint for a silent backend change.
  3. Neutralise redundant knobs: top_p = 1, penalties = 0, so one thing controls variance.
  4. Set a seed if available; add structured output constraints.
  5. Verify the prompt is actually identical — retrieved chunks, chunk ordering, timestamps and conversation history injected into the template are common hidden sources of variation.

For hallucination — parameters are step zero, not the fix:

  1. Drop temperature to near 0 and zero the penalties. Cheap, worth doing, rarely sufficient.
  2. Inspect the retrieved context. Was the answer even in the prompt? Most "hallucinations" in RAG are retrieval failures wearing a disguise.
  3. Tighten the prompt: explicit abstain instruction, require citations per claim, clearly delimit the context block.
  4. Reduce noise: rerank and keep fewer, better chunks; irrelevant context increases fabrication.
  5. Add a verification pass — faithfulness scoring or a claim-checking step — and route low-confidence answers to abstention or a human.
  6. Consider a stronger model for the generation step; some are markedly better at declining to answer.
The line that wins this question

“Temperature controls variance, not veracity. A hallucinating model at temperature 0 just hallucinates consistently.”

04

Context Management

Windows, token budgets, chunking, the lost-in-the-middle effect, and memory beyond a single conversation.

“Lost in the middle” retrieval accuracy high low start position of the relevant fact end accuracy dips in the middle Context budget allocation system prompt retrieved context conversation history user query reserved for output every section is a budget line — decide the split before you build the prompt
Two things to internalise: attention is not uniform across position, and the window is a budget you allocate rather than a bucket you fill.
Foundational
4.1What is a context window in the context of LLMs, and why does it matter?

The context window is the maximum number of tokens a model can attend to in a single forward pass — system prompt, conversation history, retrieved documents, the user's question, and the generated output all share it. It is the model's entire working memory for that request.

Why it matters, in four directions:

  • Capability. It bounds what the model can reason over at once — a 200-page contract, a whole codebase, a long support thread.
  • Statelessness. LLMs have no memory between calls. A multi-turn conversation feels continuous only because you resend the history every turn. The context window is therefore the hard limit on apparent memory.
  • Cost and latency. Attention cost grows quadratically with sequence length in the classic formulation, and you pay per input token. Prefill time scales with input size, so a large context directly increases time-to-first-token.
  • Quality. The advertised maximum is not the useful maximum. Performance typically degrades well before the limit, so "it fits" and "it works well" are different claims.
Definition to be precise about

Tokens aren't words. Roughly 1 token ≈ 4 characters ≈ 0.75 English words; code, JSON and non-English text tokenise less efficiently. Quoting the ratio shows you've actually budgeted a prompt.

4.2How do token limits vary across models you've worked with? Can you give approximate figures?

Give tiers and ranges rather than precise numbers — they change every few months, and the strong answer signals that you know the difference between advertised and effective window size.

TierApprox. windowRepresentative models (mid-2026)Typical use
Small / local4K – 32KSmall open-weight and older/embedded modelsEdge, classification, cheap high-volume tasks
Standard128K – 200KClaude Haiku 4.5 (200K); most mid-tier open modelsEveryday RAG and chat — 200K ≈ a 400–500 page book
Large500KClaude Opus 4.6–4.8, Sonnet 4.6Whole-repository and multi-document work
Frontier~1MClaude Sonnet 5 and Claude 4.6+ generally, plus the current GPT and Gemini flagshipsCodebase-scale reasoning, long agentic sessions
Headline2M – 10M advertisedGemini Pro long-context tiers; Llama 4 Scout (10M)Mostly a marketing ceiling — quality is not demonstrated near the top

The two caveats that make this a good answer: first, most models deliver reliable quality at only roughly 60–70% of their stated maximum, so treat the number as a hard limit rather than a working target. Second, output limits are separate and much smaller than input limits — a model with a 1M input window may cap generation at a few tens of thousands of tokens.

Say this

“I'd quote ranges rather than exact figures because they move quarterly — and in design reviews I check the vendor docs rather than trusting a remembered number. What I'd actually design around is the effective window, measured with a needle-in-a-haystack test on my own data.”

4.3What happens when a user's input exceeds the model's maximum context length?

The request fails — you get a hard API error (a context-length-exceeded 400), not a graceful degradation. The model cannot process the sequence at all, because positional and attention structures are defined only up to the trained length.

The important nuance is that input + reserved output must fit, so you can be rejected while the input alone is under the limit. And behaviour differs by layer:

  • Raw API: immediate error. Clean, and preferable — it's visible.
  • Frameworks and chat products: often silently truncate the oldest messages or drop retrieved chunks. This is far more dangerous, because the system keeps answering while quietly forgetting the system prompt or the instruction that mattered.

What I'd do about it: count tokens before sending, using the model's actual tokenizer rather than a character heuristic. Budget the window explicitly — a fixed reserve for the system prompt and output, then allocate what's left between retrieved context and history. When the budget is exceeded, degrade deliberately and log it: summarise older turns, drop the lowest-scoring chunks first, or fall back to a longer-context model. Never truncate blindly from the front, which is exactly how systems lose their safety instructions.

Trap to avoid

Saying "the model just forgets the earliest part." That's the framework's truncation policy talking, not the model. Attributing framework behaviour to the model is a common tell.

Intermediate
4.4What strategies would you use for documents or conversations that exceed the context window?

Match the strategy to the task, because the right answer differs for "answer a question about this document" versus "summarise the whole thing" versus "keep this conversation coherent."

For long documents:

  • Retrieval (RAG) — the default for targeted questions. Don't read the document; retrieve the relevant few thousand tokens.
  • Map-reduce — for tasks that genuinely need the whole document (summarise, extract every clause of type X): process chunks independently, then combine.
  • Refine / iterative — carry a running answer through the chunks sequentially. Better for narrative coherence, worse for latency, and drifts over many steps.
  • Hierarchical summarisation — summarise sections, then summarise the summaries. Good for whole-corpus overviews; lossy by construction.

For long conversations:

  • Sliding window — keep the last N turns verbatim. Simple, cheap, forgets abruptly.
  • Rolling summary + recent window — the workhorse: a compact running summary of everything older, plus the last few turns in full.
  • Retrieval over history — embed past turns and pull back only what's relevant now. Scales indefinitely.
  • Structured state — extract durable facts (user's name, constraints, decisions) into a small key–value store that's always injected, so they never fall out of the window.

Cross-cutting: use prompt caching for the stable prefix (system prompt, long shared documents) — it cuts cost dramatically on repeated calls; compress retrieved context; and always leave headroom for the output.

4.5How does chunking strategy affect the quality of information passed into the context window in a RAG pipeline?

Chunking is the highest-leverage and most under-tuned decision in RAG. The chunk is simultaneously the unit of embedding, the unit of retrieval, and the unit of context — so a bad split degrades all three at once, and no downstream component can repair it.

The core tension:

Small chunks (~200 tokens)Large chunks (~1500 tokens)
Embedding qualityFocused, one idea per vectorDiluted — averaging many topics
Retrieval precisionHighLower — matches for the wrong reason
Context sufficiencyFragments; answers get cut in halfSelf-contained
Cost per queryLow, but you need more of themHigh token spend, more noise in the window

What actually fixes it isn't finding a magic number — it's respecting structure. Split on semantic boundaries (headings, sections, paragraphs, function definitions), never mid-table or mid-sentence. Add 10–20% overlap so a fact spanning a boundary survives. Prepend the document title and heading path to every chunk so a retrieved fragment still knows what it's about. And consider parent-document / small-to-big retrieval: embed small precise chunks for matching, but hand the LLM the surrounding parent section — which resolves the tension rather than compromising on it.

Trap to avoid

Quoting "512 tokens with 50 overlap" as a rule. It's a reasonable starting point, not an answer. The right response is that chunk size is an empirical parameter you sweep against your golden set — and that the optimum for API reference docs, legal contracts and Slack threads are wildly different.

4.6Difference between sliding window, hierarchical summarisation, and retrieval-based approaches to long contexts?

They differ in what they throw away: sliding window discards by age, hierarchical summarisation discards by detail, and retrieval discards by relevance. That framing answers the question in one sentence — then compare.

Sliding windowHierarchical summarisationRetrieval-based
MechanismKeep the most recent N tokens/turns, drop the restSummarise chunks, then summarise summaries into a treeIndex everything; fetch only what's relevant to the current query
KeepsRecency, verbatimGlobal gistQuery-relevant detail from anywhere
LosesAnything older — abruptlySpecifics; errors compound up the treeAnything retrieval misses; global overview
CostCheapest — no extra LLM callsExpensive to build, cheap to reuseIndex cost + per-query search
LatencyNone addedHigh at build timeLow (single ANN lookup)
Best forShort chat sessions“Summarise this 500-page report”“What does clause 14.2 say?”

The failure each one has: sliding windows forget a constraint the user set twenty turns ago; summarisation smooths away the exact number someone will later be held to; retrieval can't answer questions whose answer isn't localised in any chunk ("what's the overall tone of this contract?").

The production answer

“In practice I'd combine them — a recent verbatim window for immediacy, a rolling summary for continuity, and retrieval over the full archive for specifics. Each covers the others' blind spot, and that hybrid is essentially what a good conversational memory system is.”

Deep-dive
4.7How does the “lost in the middle” problem affect performance with long contexts, and how would you mitigate it?

Models attend unevenly across position: accuracy at retrieving a fact from the context follows a U-shape, highest at the beginning and end and measurably worse in the middle. So a relevant document buried mid-prompt can be effectively invisible even though it's technically there.

Why it happens: a mix of primacy from causal attention and positional encoding behaviour, recency bias, and training-data distribution — instructions typically appear at the start of documents and conclusions at the end, so the model learns those positions carry weight. The effect worsens as context length grows.

Mitigations, roughly in order of impact:

  1. Use less context. The most effective fix. Rerank aggressively and pass 3–5 excellent chunks instead of 20 mediocre ones — the U-curve barely matters when there's no middle.
  2. Order strategically. Put the highest-scoring chunks first and last, weakest in the middle (sometimes called "lost-in-the-middle reordering"). Cheap and measurable.
  3. Repeat the instruction at the end. Restate the question after the context block so it occupies a high-attention position.
  4. Structure the context. Numbered, delimited chunks with headers and source labels make retrieval-within-the-prompt easier than an undifferentiated wall of text.
  5. Compress. Extractive filtering of retrieved passages before they enter the prompt.
  6. Decompose. For genuinely long material, several focused calls beat one enormous one — map-reduce sidesteps the problem entirely.
Show you'd verify it

“I'd run a needle-in-a-haystack test on my own model and prompt format — insert a known fact at varying depths and measure recall. Vendors' long-context claims are benchmark results; the position curve for your prompt shape is an empirical question.”

4.8What are the cost and latency implications of large context windows in production, and how would you optimise both?

Cost scales roughly linearly with input tokens; latency is worse than linear because prefill attention scales quadratically with sequence length. A 10× bigger prompt costs about 10× more and adds disproportionately to time-to-first-token — and often produces a worse answer because of the middle-of-context effect.

Where the money and milliseconds go:

  • Prefill — processing the input. Dominates TTFT and scales with prompt size.
  • Decode — generating tokens, roughly linear in output length, and where most of the wall-clock time goes for long answers.
  • KV cache memory — grows with sequence length and directly limits how many concurrent requests a served model can handle. On self-hosted infra this is the real constraint on throughput.

Optimisations that actually move the numbers:

  1. Prompt caching — the single biggest win for repeated stable prefixes. Cached reads are typically ~90% cheaper than fresh input tokens, so structure prompts with the static part (system prompt, long shared document, few-shot examples) first and the variable part last.
  2. Retrieve less, rerank harder. Fewer, better chunks cut cost and improve quality simultaneously — the rare free lunch.
  3. Route by difficulty. Send easy queries to a small cheap model, escalate only what needs a frontier model. Often a 5–10× blended cost reduction.
  4. Stream — doesn't reduce total latency, but cuts perceived latency dramatically.
  5. Cap and monitor — token budgets per request, plus dashboards on tokens-per-query and cost-per-resolved-question rather than raw spend.
  6. Semantic caching of whole responses for repeated or near-duplicate questions.
Trap to avoid

Treating a big context window as a replacement for RAG. "Just put everything in the prompt" is defensible at small scale and indefensible at 100 QPS — and it usually degrades accuracy too, so it fails on both axes at once.

4.9How would you design a memory system for a multi-turn conversational AI that maintains coherence beyond a single context window?

I'd design it as tiers with different lifetimes and different retrieval rules, modelled loosely on working / episodic / semantic memory — because "keep the last N turns" and "remember the user is vegetarian" are different problems that shouldn't share a mechanism.

TierHoldsStorageInjection rule
WorkingLast 5–15 turns, verbatimIn the promptAlways, until the budget runs out
EpisodicEverything said in this and past sessionsVector store, chunked by turn/topic with timestampsRetrieved on relevance to the current message
Semantic / profileDurable facts: name, role, preferences, constraints, decisionsStructured key–value or small JSON docAlways injected — small and high value
SummaryRolling compressed narrative of older turnsText, regenerated periodicallyAlways injected, refreshed on a turn or token threshold

Write path: after each turn, an extraction step decides what is worth promoting from working memory into the profile — and, critically, handles updates and contradictions. "I moved to Berlin" must overwrite the old city, not sit alongside it. Every fact carries a timestamp, a source turn, and a confidence, so newer explicit statements win.

Read path: assemble the prompt in a fixed budget — system prompt, profile, rolling summary, retrieved episodic snippets, recent turns verbatim, current message. Order matters: put durable instructions where attention is strongest.

The hard parts to name — these are what the interviewer is listening for: forgetting and decay (memory that only grows becomes noise), contradiction resolution, privacy and deletion (a user must be able to say "forget that", and GDPR erasure has to reach the vector store too), and evaluation — you need tests for "does it remember X after 50 turns" and for false memories, which are worse than forgetting.

Termsworking memoryepisodicsemantic memoryrolling summarymemory decayright to erasure
05

Model Differentiation

Choosing between models: architecture families, proprietary vs. open weights, benchmarking, and quantization.

Encoder-only Bidirectional sees left + right label / vector BERT · embedding models · rerankers Decoder-only Causal / masked sees only the left next token GPT · Claude · Llama · Mistral · Gemini Encoder–decoder Encoder Decoder cross-attn output sequence T5 · BART · translation models
The attention mask is the real difference: bidirectional for understanding, causal for generation, both for sequence-to-sequence.
Foundational
5.1What are the key differences between the GPT, Claude and Gemini families in terms of capabilities and use cases?

At the frontier the capability gaps are narrower than the marketing suggests and they change with every release — so answer in terms of ecosystem, integration and durable design differences rather than claiming one is smarter.

OpenAI (GPT)Anthropic (Claude)Google (Gemini)
Reputation forBroadest ecosystem, strong tool/function calling, large third-party tooling surfaceLong-form reasoning, coding and agentic workflows, careful instruction-following, low-drama refusalsNative multimodality (video, audio, image) and very long context; deep GCP integration
DeploymentOpenAI API + Azure OpenAIAnthropic API, AWS Bedrock, Google VertexVertex AI / Google Cloud
Picks itself whenYou want the widest library/SDK supportLong documents, code, agents, enterprise governanceYou're on GCP, or the input is video/audio

Where genuine differences persist: input modalities supported natively; context window and effective long-context behaviour; the shape of tool-calling and structured-output APIs; safety and refusal behaviour, which materially affects some enterprise domains; data-residency and compliance options; and price per million tokens, which can differ severalfold for comparable quality.

The framing that impresses

“I'd resist ranking them in the abstract. Published benchmarks saturate and leak; what I'd do is take 50–100 representative tasks from the actual product, run all three, and score on accuracy, latency, cost and failure mode. In my experience the ranking flips by task — and I'd build behind an abstraction layer so switching is a config change, not a rewrite.”

5.2What is the difference between a proprietary model and an open-source model? What are the trade-offs?

Proprietary models are served to you through an API — you rent capability. Open-weight models give you the weights to run yourself — you own the deployment and everything that comes with it. Note the terminology point: most "open-source" LLMs are open-weight; the training data and code usually aren't released, and licences vary.

Proprietary (API)Open-weight (self-hosted)
Capability ceilingHighest availableClose behind, and closing
Cost modelPer token — scales with usage, zero fixed costFixed GPU cost — cheap per token at high, steady volume
Data controlData leaves your perimeter (contractual protections)Never leaves — VPC or on-prem
CustomisationPrompting, limited fine-tuningFull fine-tuning, LoRA, quantization, custom decoding
Ops burdenNoneGPUs, serving stack, scaling, on-call
Version stabilityVendor may deprecate or silently updateFrozen forever — full reproducibility
Latency floorNetwork + shared queueControllable; can co-locate

The crossover logic: API models win on time-to-market, spiky traffic and frontier capability. Self-hosting wins on strict data residency, very high steady volume, heavy customisation, or a need for reproducibility. The break-even is genuinely a spreadsheet exercise — a GPU costs the same whether it's busy or idle, so utilisation is the deciding variable.

Common production answer

“Hybrid: a small open model self-hosted for high-volume classification, routing and extraction, and a frontier API model for the hard reasoning tail. That usually beats either pure strategy on blended cost.”

5.3How would you decide which LLM to use for a given business use case?

I'd work backwards from the constraints that can disqualify a model outright, then benchmark only the survivors on real tasks. Starting from "which model is best?" is the wrong direction — most decisions are settled by requirements, not by leaderboard position.

Step 1 — hard constraints (these eliminate candidates): data residency and compliance; whether data may leave the perimeter at all; required modalities; latency SLA; maximum acceptable cost per request; licence terms for commercial use.

Step 2 — task requirements: what does the task actually demand? Extraction and classification need accuracy and structured output, not reasoning depth. Agentic workflows need reliable tool calling. Long-document analysis needs effective long context. Match the requirement, not the reputation.

Step 3 — build a task-specific evaluation. 50–200 real examples with expected outputs, scored automatically where possible plus human review of a sample. Run every surviving candidate, including a small cheap one — you will often find a model a tenth of the price is indistinguishable on your task.

Step 4 — score on the full picture: quality, p95 latency, cost per 1,000 requests at projected volume, failure modes (does it fail loudly or plausibly?), rate limits and availability, and switching cost.

Step 5 — design for change. Abstract the provider behind an interface, keep prompts versioned and portable, and re-run the eval when new models ship. The right model in six months is probably not today's.

Trap to avoid

Defaulting to the biggest model "to be safe." That's how teams end up paying frontier prices for sentiment classification. The senior instinct is to start with the cheapest model that could plausibly work and escalate only where the eval says you must.

Intermediate
5.4What are the architectural differences between encoder-only, decoder-only, and encoder-decoder transformers? Give examples.

The difference reduces to the attention mask and the training objective. Encoders attend bidirectionally and are trained to understand; decoders attend causally and are trained to continue; encoder-decoders do both and are trained to transform one sequence into another.

Encoder-onlyDecoder-onlyEncoder–decoder
AttentionBidirectional — every token sees all othersCausal mask — token i sees only 1…iBidirectional encoder + causal decoder joined by cross-attention
ObjectiveMasked language modellingNext-token predictionSpan corruption / seq2seq
OutputRepresentations — a vector or a labelGenerated textA transformed output sequence
ExamplesBERT, RoBERTa, DeBERTa; embedding models and cross-encoder rerankersGPT, Claude, Llama, Mistral, Gemini, Qwen — essentially all modern chat LLMsT5, FLAN-T5, BART, mT5; classical NMT
Can it generate?NoYesYes

Why decoder-only won is a good thing to be able to explain: it's a single stack, so it scales more simply; every token is a training signal, making pre-training data-efficient; the KV cache makes autoregressive inference efficient; and in-context learning turned out to make explicit task-specific architectures unnecessary — you just prompt.

Connect it back to RAG

This isn't trivia — your RAG stack uses all three families' descendants. The embedding model and the cross-encoder reranker are encoder-style; the generator is decoder-only. Saying that out loud ties Section 5 to Sections 1 and 2 and reads as real understanding.

5.5When would you choose a smaller, fine-tuned model over a large general-purpose model?

When the task is narrow, high-volume and well-specified. A fine-tuned 7B model can match or beat a frontier model on a single task at a fraction of the cost and latency — the frontier model's advantage is breadth, and on a narrow task you're paying for breadth you don't use.

Choose the small fine-tuned model when:

  • The task is stable and repetitive — classification, entity extraction, routing, structured parsing, tone rewriting, moderation.
  • Volume is high. Millions of calls a day is where per-token pricing hurts and a fixed GPU cost wins.
  • Latency matters. A small model on your own hardware can be an order of magnitude faster to first token.
  • You have labelled data — ideally a few thousand examples, which you can bootstrap by distilling from a frontier model.
  • Data can't leave your perimeter, or you need the exact same weights available in five years.
  • Output format must be rigid — fine-tuning is very effective at locking in a schema, and it also shortens prompts, since the instructions are baked into the weights.

Stay with the large general model when the task space is open-ended, requirements change weekly, you lack training data, reasoning depth is the actual product, or volume is low enough that engineering time dwarfs inference cost.

The pattern to name

“Prototype with the frontier model to prove the task is solvable and to generate labelled data; distil into a small fine-tuned model once the spec stabilises; keep an escalation path to the big model for the hard tail. And try prompt engineering and few-shot first — fine-tuning adds a training and evaluation pipeline you have to maintain forever.”

5.6How do instruction-tuned models differ from base models, and when is each appropriate?

A base model is a raw next-token predictor trained on unlabelled text — ask it a question and it may well continue with more questions, because that's what documents do. An instruction-tuned model has been post-trained on instruction–response pairs (SFT) and usually aligned with preference optimisation (RLHF/DPO) so it treats input as a request to fulfil.

Base / pretrainedInstruction-tuned (-Instruct / -Chat)
TrainingNext-token prediction on a large corpus+ SFT on instruction pairs, + RLHF/DPO alignment
Behaviour on “Explain photosynthesis”May continue with a list of similar exam questionsExplains photosynthesis
Chat templateNone — plain text completionExpects a specific role/turn format; using the wrong template degrades quality badly
Safety behaviourEssentially noneTrained refusals and guardrails
Best forYour own fine-tuning starting point; research; pure text completion; measuring raw capabilityPractically every application — chat, RAG, agents, tools

The practical rule: if you're building a product, use the instruction-tuned variant. Reach for the base model only when you intend to do your own substantial fine-tuning — starting from base avoids inheriting another team's alignment and formatting habits, and gives you a cleaner canvas for a heavily domain-specific model.

Detail that signals hands-on experience

Mention the chat template. Silently formatting prompts incorrectly for an instruct model — wrong special tokens, missing system role — is one of the most common causes of "this open model is terrible," and it's a formatting bug, not a model quality issue.

Deep-dive
5.7Compare the performance trade-offs between a small open model (e.g. Mistral 7B), a mid-size open model (e.g. Llama 3/4) and a frontier API model for a cost-sensitive enterprise application.

Frame it as three cost structures, not three quality levels — and lead with the observation that for a cost-sensitive application the right architecture is usually a router across all three, not a single choice.

Small open (~7B)Mid/large open (~70B+ or MoE)Frontier API
QualityGood on narrow tasks, weak multi-step reasoningStrong on most enterprise tasksBest, especially on the hard tail
Cost shapeFixed GPU; cheapest per token at volume — can run on a single mid-range GPU quantizedFixed but substantial GPU footprint; needs real utilisation to pay offPure per-token; zero fixed cost
LatencyLowest, self-hostedModerateNetwork-bound; variable under load
OpsModestSerious — multi-GPU serving, scalingNone
Data residencyFull controlFull controlContractual
Best roleClassification, extraction, routing, guardrails, high-volume simple turnsThe main workhorse when volume is steady and data must stay in-houseHard reasoning, low-volume high-value queries, rapid iteration

The economics to state explicitly: a self-hosted GPU costs the same whether it serves one request or a million, so self-hosting only wins above a utilisation threshold — and that threshold is a real calculation involving GPU-hour price, tokens/second throughput, and the vendor's per-million-token rate. Below it, the API is cheaper and better. Above it, self-hosting can be several times cheaper. Add engineering time honestly: an ML platform engineer costs more than a lot of API tokens.

The recommendation to give

“Start entirely on the API to establish quality and gather real traffic. Instrument which queries are actually easy. Then move the high-volume easy segment to a small self-hosted model behind a confidence-based router, keeping the frontier model for escalation. That typically cuts blended cost several-fold without a measurable quality loss — and I'd prove that with an A/B, not an assumption.”

5.8What factors would you evaluate when benchmarking two competing LLMs for a specific production task?

Public benchmarks are close to useless for this decision — they're saturated, subject to training-set contamination, and measure tasks that aren't yours. I'd build a task-specific evaluation set and treat the comparison as an experiment with controls.

Quality: accuracy against a golden set of 100–300 real examples; task-appropriate metrics (exact match for extraction, faithfulness and citation accuracy for RAG, pass@1 for code, LLM-as-judge with a human-validated rubric for open-ended text). Report distributions, not just means — a model that's usually great and occasionally catastrophic may be worse for you than a consistent one.

Reliability: structured-output validity rate, tool-call correctness, instruction adherence, refusal rate on legitimate requests, and behaviour under adversarial or malformed input. Crucially: how does it fail — loudly, or with a confident wrong answer?

Performance: p50/p95/p99 latency and time-to-first-token measured at realistic concurrency, not single-request; throughput; rate limits and observed availability.

Cost: cost per completed task (not per token — a chattier model with cheaper tokens can lose), including retries and failed attempts. Model prompt-cache savings if the workload has a stable prefix.

Fairness of the comparison — this is where candidates slip: prompts must be optimised for each model separately. Handing model B a prompt tuned for model A and declaring B worse is the most common benchmarking error. Fix sampling parameters, run multiple trials per example to measure variance, use held-out data neither model was tuned on, and blind the human raters.

Close with the operational point

“And I'd keep the harness — it becomes the regression suite that tells me whether next quarter's model is actually an upgrade.”

5.9How does quantization (GGUF, INT8, INT4) affect model performance, accuracy, and deployment feasibility?

Quantization stores weights at lower numerical precision — 16-bit floats down to 8 or 4 bits — which shrinks the model roughly proportionally. Since LLM inference is memory-bandwidth-bound rather than compute-bound, smaller weights mean both a smaller footprint and faster generation, at some accuracy cost.

PrecisionSize, 7B modelTypical quality impactNotes
FP16 / BF16~14 GBBaselineStandard training/serving precision
INT8~7 GBNear-negligibleSafe default; widely supported
INT4~3.5 GBSmall but real — worst on reasoning, math, long-context and rare knowledgeWhere consumer-hardware deployment becomes possible
Below 4-bit<3 GBNoticeable degradationResearch/extreme-constraint territory

Terminology to keep straight — a common differentiator: GGUF is a file format (the llama.cpp ecosystem) that happens to package quantized weights at various levels like Q4_K_M or Q8_0, and it supports CPU and hybrid CPU/GPU offload. INT8/INT4 are precisions. GPTQ and AWQ are post-training quantization methods for GPU serving; QLoRA is fine-tuning on a quantized base. Conflating the format with the precision is the mistake to avoid.

Deployment consequences: a 70B model at INT4 fits on a single 48 GB GPU instead of needing multiple cards — that's the difference between a feasible and infeasible deployment, and it's usually the actual motivation. It also frees VRAM for a bigger KV cache, which raises concurrency.

The judgement call to state

“Given a fixed memory budget, a larger model quantized to 4-bit usually beats a smaller model at full precision. But quantization damage is task-dependent — I'd evaluate the quantized model on my own task rather than trusting a perplexity delta, because perplexity can look fine while multi-step reasoning quietly degrades.”

TermsGGUFGPTQAWQQLoRAKV cachememory-bandwidth-bound
No questions match that search.