Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The vector similarity score is weighted by 0.5 before adding the keyword score to balance both methods.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' filters out good results.
Using '==' is too strict and excludes most results.
✗ Incorrect
We keep results with hybrid scores greater than or equal to 0.7 to ensure relevance.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Multiplying by max_keyword mixes up normalization.
Using vector_score again ignores normalization.
✗ Incorrect
The vector score is multiplied by its weight before adding the normalized keyword score.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' includes low scores.
Using '==' None excludes valid IDs.
✗ Incorrect
We select docs with scores greater than 0.6 and IDs that are not None.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting 'id' instead of 'title'.
Using '<' includes unwanted docs.
✗ Incorrect
We extract the 'title' field for docs with hybrid_score > 0.75 and keyword_matches > 2.