0
0
Agentic AIml~10 mins

Retrieval strategies (similarity, MMR, hybrid) in Agentic AI - Interactive Code Practice

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

Complete the code to compute cosine similarity between query and documents.

Agentic AI
similarity_scores = cosine_similarity(query_vector, [1])
Drag options to blanks, or click blank then click option'
Aempty_vectors
Bquery_vector
Crandom_vectors
Ddocument_vectors
Attempts:
3 left
💡 Hint
Common Mistakes
Using the query vector instead of document vectors for comparison.
2fill in blank
medium

Complete the code to select top k documents based on similarity scores.

Agentic AI
top_k_indices = similarity_scores.argsort()[::-1][:[1]]
Drag options to blanks, or click blank then click option'
A0
Bn
Ck
Dlen
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or len instead of k for slicing.
3fill in blank
hard

Fix the error in the Maximal Marginal Relevance (MMR) score calculation.

Agentic AI
mmr_score = lambda doc, selected: lambda_param * similarity(doc, query) - (1 - lambda_param) * max(similarity(doc, s) for s in [1])
Drag options to blanks, or click blank then click option'
Aselected
Bquery
Call_docs
Ddocuments
Attempts:
3 left
💡 Hint
Common Mistakes
Using the query or all documents instead of selected documents for redundancy check.
4fill in blank
hard

Fill both blanks to implement a hybrid retrieval score combining similarity and MMR.

Agentic AI
hybrid_score = lambda doc, selected: alpha * similarity(doc, query) + (1 - alpha) * [1](doc, selected)
selected_doc = max(candidates, key=lambda doc: [2](doc, selected))
Drag options to blanks, or click blank then click option'
Ammr_score
Bsimilarity
Chybrid_score
Dredundancy_score
Attempts:
3 left
💡 Hint
Common Mistakes
Using similarity instead of mmr_score for the first blank.
Using similarity instead of hybrid_score for selection.
5fill in blank
hard

Fill all three blanks to create a dictionary of document scores filtered by a threshold.

Agentic AI
filtered_scores = {doc: [1] for doc, score in scores.items() if score [2] [3]
Drag options to blanks, or click blank then click option'
Ascore
B>
Cthreshold
Ddoc
Attempts:
3 left
💡 Hint
Common Mistakes
Using doc instead of score as dictionary value.
Using '<' instead of '>' for filtering.