Bird
Raised Fist0
Agentic AIml~10 mins

Why RAG gives agents knowledge in Agentic AI - Test Your Understanding

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
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load documents for retrieval in RAG.

Agentic AI
from langchain.document_loaders import TextLoader
loader = TextLoader('[1]')
docs = loader.load()
Drag options to blanks, or click blank then click option'
Aagent.py
Bdata.txt
Cconfig.json
Dmodel.py
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a code or config file instead of a text file.
2fill in blank
medium

Complete the code to create a retriever from documents for RAG.

Agentic AI
from langchain.vectorstores import FAISS
retriever = FAISS.from_documents(docs, [1]).as_retriever()
Drag options to blanks, or click blank then click option'
Aloss_function
Btokenizer
Coptimizer
Dembedding_model
Attempts:
3 left
💡 Hint
Common Mistakes
Using tokenizer or optimizer which are unrelated to vector search.
3fill in blank
hard

Fix the error in the RAG agent creation by completing the missing argument.

Agentic AI
from langchain.chains import RetrievalQA
rag_agent = RetrievalQA.from_chain_type(llm=llm, retriever=[1], return_source_documents=True)
Drag options to blanks, or click blank then click option'
Aretriever
Bembedding_model
Ctokenizer
Doptimizer
Attempts:
3 left
💡 Hint
Common Mistakes
Passing tokenizer or embedding model instead of retriever.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that filters documents by length and stores their text.

Agentic AI
filtered_docs = {doc.metadata['title']: doc.page_content for doc in docs if len(doc.page_content) [1] 100 and doc.metadata['source'] [2] 'trusted_source'}
Drag options to blanks, or click blank then click option'
A<
B>
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' for length or '!=' for source causes wrong filtering.
5fill in blank
hard

Fill all three blanks to build a RAG pipeline that embeds, retrieves, and answers questions.

Agentic AI
embedding = [1]()
retriever = FAISS.from_documents(docs, embedding).as_retriever()
rag_agent = RetrievalQA.from_chain_type(llm=[2](), retriever=retriever, return_source_documents=True)
answer = rag_agent.run([3])
Drag options to blanks, or click blank then click option'
AOpenAIEmbeddings
BOpenAI
C'What is RAG?'
DGPT2
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPT2 as LLM or passing a non-string question.

Practice

(1/5)
1. What is the main reason RAG (Retrieval-Augmented Generation) helps AI agents have better knowledge?
easy
A. It ignores external information sources.
B. It only uses pre-trained data without updates.
C. It combines retrieving information with generating answers.
D. It relies solely on random guessing.

Solution

  1. Step 1: Understand RAG's components

    RAG combines two parts: retrieval (finding relevant info) and generation (creating answers).
  2. Step 2: Connect combination to knowledge improvement

    By mixing retrieval and generation, agents can use both stored and new info, improving knowledge.
  3. Final Answer:

    It combines retrieving information with generating answers. -> Option C
  4. Quick Check:

    RAG = retrieval + generation [OK]
Hint: Remember RAG mixes retrieval and generation [OK]
Common Mistakes:
  • Thinking RAG only uses pre-trained data
  • Believing RAG ignores external info
  • Assuming RAG guesses randomly
2. Which of the following is the correct way to describe RAG's process in simple terms?
easy
A. RAG retrieves relevant documents, then generates answers using them.
B. RAG generates answers first, then searches for info.
C. RAG only retrieves documents without generating answers.
D. RAG randomly selects answers without retrieval.

Solution

  1. Step 1: Identify RAG's sequence

    RAG first retrieves relevant documents from a source.
  2. Step 2: Understand generation step

    Then it generates answers based on the retrieved documents.
  3. Final Answer:

    RAG retrieves relevant documents, then generates answers using them. -> Option A
  4. Quick Check:

    Retrieve then generate [OK]
Hint: RAG retrieves first, then generates answers [OK]
Common Mistakes:
  • Thinking generation happens before retrieval
  • Believing RAG only retrieves without generation
  • Assuming random answer selection
3. Given this simplified code snippet for a RAG agent:
retrieved_docs = ['Doc about cats', 'Doc about dogs']
query = 'Tell me about cats'
answer = generate_answer(query, retrieved_docs)
print(answer)
What is the expected output behavior?
medium
A. The answer will only use the query without documents.
B. The answer will ignore retrieved_docs and be random.
C. The code will cause an error because generate_answer is undefined.
D. The answer will be generated using information about cats and dogs.

Solution

  1. Step 1: Understand inputs to generate_answer

    The function gets the query and the retrieved documents about cats and dogs.
  2. Step 2: Predict output behavior

    Since retrieved_docs include relevant info, the answer will use that info to respond about cats.
  3. Final Answer:

    The answer will be generated using information about cats and dogs. -> Option D
  4. Quick Check:

    RAG uses retrieved docs to generate answers [OK]
Hint: Check if retrieved docs are used in generation [OK]
Common Mistakes:
  • Assuming generate_answer is undefined error
  • Thinking answer ignores retrieved docs
  • Believing answer is random
4. Consider this code snippet for a RAG agent:
def rag_agent(query):
    docs = retrieve_docs(query)
    answer = generate_answer(docs)
    return answer

print(rag_agent('What is AI?'))
What is the main error in this code?
medium
A. generate_answer is called without the query parameter.
B. retrieve_docs is missing the query argument.
C. rag_agent returns docs instead of answer.
D. print statement is outside the function.

Solution

  1. Step 1: Check function calls and parameters

    retrieve_docs is called with query, which is correct.
  2. Step 2: Identify generate_answer call issue

    generate_answer is called with only docs, but it needs both query and docs to generate a proper answer.
  3. Final Answer:

    generate_answer is called without the query parameter. -> Option A
  4. Quick Check:

    generate_answer needs query and docs [OK]
Hint: Check if all required parameters are passed to functions [OK]
Common Mistakes:
  • Thinking retrieve_docs lacks argument
  • Believing rag_agent returns wrong value
  • Confusing print statement placement
5. How does RAG improve an AI agent's ability to answer questions about recent events not in its training data?
hard
A. By only relying on its fixed training data without updates.
B. By retrieving up-to-date documents and generating answers using them.
C. By guessing answers based on old data patterns.
D. By ignoring external information and focusing on generation.

Solution

  1. Step 1: Understand RAG's retrieval role

    RAG retrieves current documents from external sources, including recent events.
  2. Step 2: Understand generation with new info

    It then generates answers using this fresh info, allowing it to handle new questions accurately.
  3. Final Answer:

    By retrieving up-to-date documents and generating answers using them. -> Option B
  4. Quick Check:

    RAG uses fresh retrieval for new knowledge [OK]
Hint: Remember RAG updates knowledge via retrieval [OK]
Common Mistakes:
  • Thinking RAG only uses old training data
  • Assuming RAG guesses without info
  • Believing RAG ignores external data