0
0
LangChainframework~20 mins

Basic RAG chain with LCEL in LangChain - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
RAG Chain Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is the main purpose of a Retrieval-Augmented Generation (RAG) chain?

In simple terms, what does a RAG chain do in a language model system?

AIt compresses large documents into smaller summaries without generating new text.
BIt only generates text without using any external information.
CIt translates text from one language to another without retrieving documents.
DIt retrieves relevant documents and uses them to generate more accurate answers.
Attempts:
2 left
💡 Hint

Think about how RAG combines searching and writing.

Predict Output
intermediate
2:00remaining
Output of a simple RAG chain

Given the following code snippet using LangChain, what will be the output?

LangChain
from langchain.chains import RetrievalQA
from langchain.llms import OpenAI

retriever = DummyRetriever()
qa = RetrievalQA.from_chain_type(llm=OpenAI(temperature=0), chain_type="stuff", retriever=retriever)

query = "What is AI?"
result = qa.run(query)
print(result)
ASyntaxError: invalid syntax in chain_type argument
B"AI is a type of hardware used in computers."
C"AI stands for Artificial Intelligence, which is the simulation of human intelligence by machines."
DTypeError: 'DummyRetriever' object is not callable
Attempts:
2 left
💡 Hint

Assume DummyRetriever returns a document defining AI correctly.

Hyperparameter
advanced
1:30remaining
Choosing the best temperature setting for a RAG chain

In a RAG chain using LCEL, which temperature setting is best for producing consistent factual answers?

ATemperature = 0 (lowest randomness)
BTemperature = 1 (highest randomness)
CTemperature = 0.7 (medium randomness)
DTemperature = -1 (invalid value)
Attempts:
2 left
💡 Hint

Lower temperature means less creativity, more factual.

Metrics
advanced
1:00remaining
Evaluating RAG chain performance with accuracy

You run a RAG chain on 100 questions. It answers 85 correctly. What is the accuracy?

A15%
B85%
C100%
DCannot be determined without loss value
Attempts:
2 left
💡 Hint

Accuracy = (correct answers / total questions) * 100

🔧 Debug
expert
2:30remaining
Debugging a RAG chain that returns empty answers

Given this snippet, why does the RAG chain return empty answers?

retriever = SomeRetriever()
qa_chain = RetrievalQA.from_chain_type(llm=OpenAI(), retriever=retriever)
answer = qa_chain.run("")
print(answer)
AThe query string is empty, so no documents are retrieved or answers generated.
BThe retriever is not initialized properly, causing a runtime error.
CThe OpenAI model is not connected to the internet.
DThe chain_type argument is missing, causing a syntax error.
Attempts:
2 left
💡 Hint

Check the input query string.