0
0
LangChainframework~10 mins

Similarity search vs MMR retrieval in LangChain - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to perform a similarity search using LangChain.

LangChain
results = vectorstore.[1](query="What is AI?", k=3)
Drag options to blanks, or click blank then click option'
Asearch_documents
Bsimilarity_search
Cmmr_search
Dget_relevant_documents
Attempts:
3 left
💡 Hint
Common Mistakes
Using MMR search method instead of similarity search.
2fill in blank
medium

Complete the code to perform an MMR retrieval with LangChain.

LangChain
results = vectorstore.[1](query="Explain machine learning", k=4, lambda_mult=0.5)
Drag options to blanks, or click blank then click option'
Amax_marginal_relevance_search
Bsimilarity_search
Cretrieve_mmr
Dsearch_mmr
Attempts:
3 left
💡 Hint
Common Mistakes
Using similarity search instead of MMR search.
3fill in blank
hard

Fix the error in the MMR search call by completing the missing method name.

LangChain
docs = vectorstore.[1](query="Benefits of AI", k=5, lambda_mult=0.7)
Drag options to blanks, or click blank then click option'
Asearch
Bsimilarity_search
Cmax_marginal_relevance_search
Dretrieve
Attempts:
3 left
💡 Hint
Common Mistakes
Using generic search methods without MMR support.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps documents to their similarity scores greater than 0.8.

LangChain
high_scores = {doc: score for doc, score in vectorstore.similarity_search_with_score(query) if score [1] 0.8 and doc.[2] is not None}
Drag options to blanks, or click blank then click option'
A>
B<
Cmetadata
Dcontent
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for score comparison.
Checking wrong document attribute.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps document titles to their content length for documents retrieved by MMR with score above 0.5.

LangChain
doc_info = {doc.[1]: len(doc.[2]) for doc, score in vectorstore.[3](query, k=6, lambda_mult=0.6) if score > 0.5}
Drag options to blanks, or click blank then click option'
Ametadata['title']
Bpage_content
Cmax_marginal_relevance_search_with_score
Dsimilarity_search
Attempts:
3 left
💡 Hint
Common Mistakes
Using similarity_search instead of max_marginal_relevance_search_with_score.
Accessing wrong document attributes.