Bird
Raised Fist0
Prompt Engineering / GenAIml~20 mins

RAG architecture overview in Prompt Engineering / GenAI - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
RAG Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the main purpose of the Retriever component in RAG?

In the Retrieval-Augmented Generation (RAG) architecture, the Retriever plays a key role. What is its main purpose?

ATo train the model using labeled data
BTo generate natural language text based on retrieved information
CTo find relevant documents or passages from a large knowledge base based on the input query
DTo evaluate the quality of generated answers
Attempts:
2 left
💡 Hint

Think about which part searches for information before generating answers.

Predict Output
intermediate
2:00remaining
What is the output shape of the combined embeddings in RAG?

Given a batch of 2 queries, each retrieving 3 documents, and each embedding vector has size 768, what is the shape of the combined embeddings tensor before generation?

Prompt Engineering / GenAI
batch_size = 2
num_docs = 3
embedding_size = 768

# Assume embeddings shape is (batch_size, num_docs, embedding_size)
embeddings_shape = (batch_size, num_docs, embedding_size)

# Combined embeddings shape after flattening documents per query
combined_shape = (batch_size, num_docs * embedding_size)

print(combined_shape)
A(2, 2304)
B(2, 3, 768)
C(6, 768)
D(2, 768)
Attempts:
2 left
💡 Hint

Multiply the number of documents by the embedding size for each query.

Model Choice
advanced
2:00remaining
Which model type is typically used as the Generator in RAG?

In the RAG architecture, which type of model is commonly used as the Generator to produce answers from retrieved documents?

ASequence-to-sequence Transformer model like BART or T5
BConvolutional Neural Network (CNN)
CRecurrent Neural Network (RNN) without attention
DFeedforward Neural Network
Attempts:
2 left
💡 Hint

Think about models designed for text generation with attention mechanisms.

Hyperparameter
advanced
2:00remaining
Which hyperparameter controls how many documents the Retriever fetches in RAG?

In RAG, you can adjust how many documents the Retriever returns for each query. What is this hyperparameter commonly called?

Aembedding_dim
Bbatch_size
Clearning_rate
Dnum_retrieved_docs
Attempts:
2 left
💡 Hint

It relates to the count of documents fetched per query.

Metrics
expert
3:00remaining
Which metric best evaluates the quality of answers generated by RAG on open-domain QA tasks?

When testing a RAG model on open-domain question answering, which metric is most suitable to measure how well the generated answers match the correct ones?

AMean Squared Error (MSE)
BExact Match (EM) score
CBLEU score
DAccuracy on classification labels
Attempts:
2 left
💡 Hint

Consider a metric that checks if the generated answer exactly matches the reference answer.

Practice

(1/5)
1. What is the main purpose of the retriever component in a RAG architecture?
easy
A. To find relevant documents or information from a large dataset
B. To generate natural language answers from scratch
C. To train the model on labeled data
D. To evaluate the accuracy of the answers

Solution

  1. Step 1: Understand the role of retriever in RAG

    The retriever searches a large collection of documents to find relevant information related to the question.
  2. Step 2: Differentiate retriever from generator

    The generator uses the retrieved information to create a natural language answer, not to find documents.
  3. Final Answer:

    To find relevant documents or information from a large dataset -> Option A
  4. Quick Check:

    Retriever = Find info [OK]
Hint: Retriever searches data; generator writes answers [OK]
Common Mistakes:
  • Confusing retriever with generator
  • Thinking retriever generates answers
  • Assuming retriever evaluates answers
2. Which of the following correctly describes the sequence of operations in a RAG model?
easy
A. Generate answer first, then retrieve documents
B. Retrieve documents first, then generate answer
C. Train model, then retrieve documents
D. Evaluate answer, then generate documents

Solution

  1. Step 1: Recall RAG workflow

    RAG first retrieves relevant documents to provide context for the answer.
  2. Step 2: Understand generation step

    After retrieval, the generator uses the documents to produce a final answer.
  3. Final Answer:

    Retrieve documents first, then generate answer -> Option B
  4. Quick Check:

    Retrieve before generate [OK]
Hint: Retrieve info before writing answer [OK]
Common Mistakes:
  • Thinking generation happens before retrieval
  • Mixing training with retrieval steps
  • Confusing evaluation with generation
3. Consider this simplified Python pseudocode for a RAG-like process:
retrieved_docs = retriever.search(query)
answer = generator.generate(retrieved_docs, query)
print(answer)
What will be printed if the retriever returns an empty list?
medium
A. An answer generated without context, possibly generic or incorrect
B. A runtime error because generator cannot handle empty input
C. The original query string printed
D. An empty string printed

Solution

  1. Step 1: Analyze retriever output

    The retriever returns an empty list, meaning no documents found.
  2. Step 2: Understand generator behavior

    The generator tries to create an answer without context, so it may produce a generic or less accurate answer, but no error occurs.
  3. Final Answer:

    An answer generated without context, possibly generic or incorrect -> Option A
  4. Quick Check:

    Empty retrieval leads to generic answer [OK]
Hint: Empty retrieval means generic answer, not error [OK]
Common Mistakes:
  • Assuming empty retrieval causes error
  • Thinking query is printed directly
  • Expecting empty string output
4. You have a RAG model that always returns irrelevant answers. Which of these is the most likely cause?
medium
A. The model is overfitting on training data
B. Generator is not trained on any data
C. Retriever is returning unrelated documents
D. The evaluation metric is incorrect

Solution

  1. Step 1: Identify cause of irrelevant answers

    If answers are irrelevant, the source documents are likely unrelated to the question.
  2. Step 2: Check retriever role

    The retriever finds documents; if it returns unrelated ones, the generator has poor context to answer.
  3. Final Answer:

    Retriever is returning unrelated documents -> Option C
  4. Quick Check:

    Bad retrieval causes irrelevant answers [OK]
Hint: Check retriever output first for relevance [OK]
Common Mistakes:
  • Blaming generator without checking retrieval
  • Confusing overfitting with retrieval errors
  • Ignoring data quality issues
5. In a RAG system designed for a constantly updated news database, which advantage does RAG provide compared to a standard language model?
hard
A. It generates answers faster by skipping retrieval
B. It always produces shorter answers
C. It requires no training data at all
D. It can access fresh news by retrieving documents without retraining

Solution

  1. Step 1: Understand RAG with dynamic data

    RAG retrieves documents from an external source, so it can use new data without retraining the generator.
  2. Step 2: Compare with standard language models

    Standard models need retraining to learn new info, but RAG updates answers by searching fresh documents.
  3. Final Answer:

    It can access fresh news by retrieving documents without retraining -> Option D
  4. Quick Check:

    RAG updates answers via retrieval [OK]
Hint: RAG uses retrieval to handle new data easily [OK]
Common Mistakes:
  • Thinking RAG skips retrieval
  • Assuming no training data needed
  • Believing RAG limits answer length