0
0
Prompt Engineering / GenAIml~10 mins

Hybrid search strategies in Prompt Engineering / GenAI - Interactive Code Practice

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

Complete the code to combine vector similarity and keyword matching in a hybrid search.

Prompt Engineering / GenAI
hybrid_score = vector_score * [1] + keyword_score
Drag options to blanks, or click blank then click option'
A1.0
B0.5
C2.0
Dvector_score
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1.0 or 2.0 makes vector similarity dominate too much.
Using 'vector_score' again causes a wrong calculation.
2fill in blank
medium

Complete the code to filter search results by a minimum hybrid score threshold.

Prompt Engineering / GenAI
filtered_results = [r for r in results if r['hybrid_score'] [1] 0.7]
Drag options to blanks, or click blank then click option'
A==
B<
C!=
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' filters out good results.
Using '==' is too strict and excludes most results.
3fill in blank
hard

Fix the error in the code that calculates the final hybrid score by normalizing vector and keyword scores.

Prompt Engineering / GenAI
final_score = (vector_score / max_vector) * [1] + (keyword_score / max_keyword)
Drag options to blanks, or click blank then click option'
Avector_score
Bmax_keyword
Cweight_vector
Dweight_keyword
Attempts:
3 left
💡 Hint
Common Mistakes
Multiplying by max_keyword mixes up normalization.
Using vector_score again ignores normalization.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps document IDs to their hybrid scores only if the score is above 0.6.

Prompt Engineering / GenAI
hybrid_dict = {doc['id']: doc['score'] for doc in docs if doc['score'] [1] 0.6 and doc['id'] [2] None}
Drag options to blanks, or click blank then click option'
A>
B!=
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' includes low scores.
Using '==' None excludes valid IDs.
5fill in blank
hard

Fill all three blanks to create a list comprehension that extracts titles of documents with hybrid scores above 0.75 and keyword matches greater than 2.

Prompt Engineering / GenAI
selected_titles = [doc[1] for doc in documents if doc['hybrid_score'] [2] 0.75 and doc['keyword_matches'] [3] 2]
Drag options to blanks, or click blank then click option'
A['title']
B>
D['id']
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting 'id' instead of 'title'.
Using '<' includes unwanted docs.