0
0
Prompt Engineering / GenAIml~20 mins

Similarity search and retrieval in Prompt Engineering / GenAI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Similarity Search Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is the main purpose of similarity search in AI?
Imagine you have a large photo album and want to find pictures that look like a specific photo. What does similarity search do in this context?
AIt finds photos that are exactly the same as the given photo.
BIt finds photos that share similar features or patterns with the given photo.
CIt sorts all photos by their file size.
DIt deletes photos that are not similar to the given photo.
Attempts:
2 left
💡 Hint
Think about how you find things that look alike, not exactly the same.
Predict Output
intermediate
1:30remaining
Output of cosine similarity calculation
What is the output of this cosine similarity calculation between vectors A and B?
Prompt Engineering / GenAI
import numpy as np
A = np.array([1, 2, 3])
B = np.array([4, 5, 6])
cos_sim = np.dot(A, B) / (np.linalg.norm(A) * np.linalg.norm(B))
print(round(cos_sim, 2))
A0.97
B1.00
C0.87
D0.75
Attempts:
2 left
💡 Hint
Recall cosine similarity formula and calculate dot product and norms carefully.
Model Choice
advanced
2:00remaining
Best model type for similarity search on text data
You want to build a system that finds similar sentences in a large document collection. Which model type is best suited for this task?
AK-means clustering on raw text tokens
BRecurrent Neural Network (RNN) trained for language modeling
CConvolutional Neural Network (CNN) trained for image classification
DTransformer-based model producing sentence embeddings
Attempts:
2 left
💡 Hint
Think about models that create meaningful vector representations of sentences.
Metrics
advanced
1:30remaining
Choosing the right metric for nearest neighbor search
Which distance metric is most appropriate for measuring similarity between high-dimensional dense vectors from a neural network embedding?
ACosine similarity
BManhattan distance
CEuclidean distance
DHamming distance
Attempts:
2 left
💡 Hint
Consider which metric focuses on the angle between vectors rather than magnitude.
🔧 Debug
expert
2:00remaining
Debugging a similarity search code snippet
What error does this code raise when trying to compute similarity between two lists of different lengths?
Prompt Engineering / GenAI
def jaccard_similarity(list1, list2):
    intersection = len(set(list1) & set(list2))
    union = len(set(list1) | set(list2))
    return intersection / union

result = jaccard_similarity([1, 2, 3], [1, 2])
print(result)
ANo error, output is 0.67
BTypeError
CZeroDivisionError
DIndexError
Attempts:
2 left
💡 Hint
Check how sets handle different length lists and the division operation.