Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add conversation history to the retriever query.
LangChain
query = [1] + ' ' + user_input
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated or empty strings instead of conversation history.
Not including any context in the query.
✗ Incorrect
Adding the conversation history to the query helps the retriever understand the context better.
2fill in blank
mediumComplete the code to update the conversation history after each user input.
LangChain
conversation_history = conversation_history + '\nUser: ' + [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Appending system responses instead of user inputs.
Not updating the conversation history at all.
✗ Incorrect
We add the latest user input to the conversation history to keep context updated.
3fill in blank
hardFix the error in the code that combines conversation history and user input for retrieval.
LangChain
retrieval_query = [1] + ' ' + user_input
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using system responses or empty strings instead of conversation history.
Forgetting to include conversation history in the retrieval query.
✗ Incorrect
The retrieval query must include the conversation history to provide context for the retriever.
4fill in blank
hardFill both blanks to create a function that updates conversation history and prepares the retrieval query.
LangChain
def update_and_query(user_input, [1]): [2] += '\nUser: ' + user_input retrieval_query = [2] return retrieval_query, [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using system_response instead of conversation_history.
Mixing up parameter and variable names.
✗ Incorrect
The function updates the conversation history and uses it to build the retrieval query.
5fill in blank
hardFill all three blanks to implement a retrieval-augmented generation step using conversation history.
LangChain
def rag_step(user_input, [1]): [2] += '\nUser: ' + user_input retrieval_query = [2] retrieved_docs = retriever.retrieve([3]) return retrieved_docs, [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing user_input directly to retriever instead of the combined query.
Not updating conversation history before retrieval.
✗ Incorrect
This function updates conversation history, builds a retrieval query, and retrieves documents based on that query.