0
0
Prompt Engineering / GenAIml~10 mins

Hybrid search (semantic + keyword) 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 semantic and keyword search scores by adding them.

Prompt Engineering / GenAI
final_score = semantic_score [1] keyword_score
Drag options to blanks, or click blank then click option'
A*
B-
C+
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication instead of addition
Using subtraction which lowers the score
2fill in blank
medium

Complete the code to normalize the semantic vector before searching.

Prompt Engineering / GenAI
normalized_vector = semantic_vector [1] np.linalg.norm(semantic_vector)
Drag options to blanks, or click blank then click option'
A/
B*
C+
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Multiplying instead of dividing
Adding or subtracting which does not normalize
3fill in blank
hard

Fix the error in the code to filter documents containing the keyword 'AI'.

Prompt Engineering / GenAI
filtered_docs = [doc for doc in documents if 'AI' [1] doc['keywords']]
Drag options to blanks, or click blank then click option'
A==
Bin
Cnot in
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' which compares equality incorrectly
Using 'not in' which excludes documents with 'AI'
4fill in blank
hard

Fill both blanks to create a dictionary of document IDs and their combined scores, filtering for scores above 0.5.

Prompt Engineering / GenAI
result = {doc['id']: doc['semantic_score'] [1] doc['keyword_score'] for doc in docs if (doc['semantic_score'] [2] doc['keyword_score']) > 0.5}
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication or division which changes score meaning
Using subtraction which can lower scores incorrectly
5fill in blank
hard

Fill all three blanks to create a list of document titles where the combined score is above 0.7.

Prompt Engineering / GenAI
top_titles = [doc[[1]] for doc in docs if (doc[[2]] + doc[[3]]) > 0.7]
Drag options to blanks, or click blank then click option'
A'title'
B'semantic_score'
C'keyword_score'
D'id'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'id' instead of 'title' for the first blank
Mixing up score fields or using wrong keys