Bird
0
0

Given this simplified Langchain code snippet, what will be the output of the retriever's document titles?

medium📝 Predict Output Q4 of 15
LangChain - Conversational RAG
Given this simplified Langchain code snippet, what will be the output of the retriever's document titles? ```python history = ["What is AI?", "Explain machine learning."] query = "How does RAG use history?" docs = retriever.get_relevant_documents(query + ' ' + ' '.join(history)) titles = [doc.metadata['title'] for doc in docs] print(titles) ```
AA list of document titles related to RAG and conversation history.
BAn empty list because the retriever cannot handle concatenated queries.
CA list of all documents in the database regardless of query.
DA runtime error due to incorrect string concatenation.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze how the query is formed

    The query combines the current question with conversation history as one string, providing context.
  2. Step 2: Understand retriever behavior

    The retriever uses the combined query to find relevant documents, so titles will relate to RAG and history.
  3. Final Answer:

    A list of document titles related to RAG and conversation history. -> Option A
  4. Quick Check:

    Combined query retrieves relevant docs = C [OK]
Quick Trick: Concatenate history to query for better retrieval [OK]
Common Mistakes:
  • Assuming retriever fails on concatenated strings
  • Expecting all documents returned
  • Thinking code causes runtime error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes