Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the LangChain RetrievalQA class.
LangChain
from langchain.chains import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated classes like TextSplitter or OpenAI instead of RetrievalQA.
✗ Incorrect
The RetrievalQA class is used to create a retrieval-augmented generation chain in LangChain.
2fill in blank
mediumComplete the code to initialize the RetrievalQA chain with the retriever.
LangChain
qa_chain = RetrievalQA.from_chain_type(llm=llm, retriever=[1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing embedding or document instead of the retriever.
✗ Incorrect
The retriever object is passed to the RetrievalQA chain to fetch relevant documents.
3fill in blank
hardFix the error in the code to run the RAG chain and get the answer.
LangChain
result = qa_chain.[1](query) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using search or predict instead of run to execute the chain.
✗ Incorrect
The run() method executes the chain with the input query and returns the answer.
4fill in blank
hardFill both blanks to create a LangChain LLMChain with a prompt template and an LLM.
LangChain
from langchain.chains import [1] from langchain.prompts import [2] llm_chain = LLMChain(llm=llm, prompt=prompt)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated classes like Retriever or VectorStore here.
✗ Incorrect
LLMChain and PromptTemplate are imported to create a chain with a prompt and language model.
5fill in blank
hardFill all three blanks to create a dictionary comprehension filtering documents by length and score.
LangChain
filtered_docs = {doc: score for doc, score in docs.items() if len(doc) [1] 100 and score [2] 0.5 and doc not in [3] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators or forgetting to exclude documents.
✗ Incorrect
We filter documents shorter than 100 characters, with score greater than 0.5, and not in excluded_docs.