Bird
Raised Fist0
Prompt Engineering / GenAIml~20 mins

Hybrid search (semantic + keyword) in Prompt Engineering / GenAI - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Hybrid Search Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why combine semantic and keyword search in hybrid search?

Hybrid search uses both semantic and keyword search methods. What is the main benefit of combining these two?

AIt reduces the time needed to index documents by skipping keyword extraction.
BIt improves search accuracy by capturing both exact matches and related meanings.
CIt eliminates the need for any text preprocessing before searching.
DIt guarantees that only exact keyword matches are returned.
Attempts:
2 left
💡 Hint

Think about how semantic search understands meaning and keyword search looks for exact words.

Predict Output
intermediate
1:30remaining
Output of hybrid search scoring function

Given the following Python code snippet for a hybrid search score, what is the printed output?

Prompt Engineering / GenAI
semantic_score = 0.7
keyword_score = 0.5
alpha = 0.6
hybrid_score = alpha * semantic_score + (1 - alpha) * keyword_score
print(round(hybrid_score, 2))
A0.65
B0.58
C0.60
D0.62
Attempts:
2 left
💡 Hint

Calculate weighted average: multiply semantic score by alpha, keyword score by (1 - alpha), then add.

Model Choice
advanced
2:00remaining
Choosing a model for semantic search in hybrid search

You want to build a hybrid search system combining keyword and semantic search. Which model is best suited for the semantic search part?

AA pretrained transformer-based sentence embedding model like Sentence-BERT
BA simple TF-IDF vectorizer without embeddings
CA rule-based keyword matching system
DA clustering algorithm like K-Means
Attempts:
2 left
💡 Hint

Semantic search needs to understand meaning, not just word counts.

Hyperparameter
advanced
1:30remaining
Effect of alpha in hybrid search scoring

In hybrid search, the combined score is calculated as:
hybrid_score = alpha * semantic_score + (1 - alpha) * keyword_score.
What happens if alpha is set to 1?

AOnly semantic search scores are used, ignoring keyword matches.
BThe scores are averaged equally between semantic and keyword search.
COnly keyword search scores are used, ignoring semantic matches.
DThe hybrid score becomes zero regardless of input scores.
Attempts:
2 left
💡 Hint

Consider what multiplying by 1 or 0 does to each score.

Metrics
expert
2:30remaining
Evaluating hybrid search effectiveness

You run a hybrid search system and want to measure how well it balances semantic and keyword search results. Which metric best captures both relevance and ranking quality?

ARoot Mean Squared Error (RMSE)
BPrecision at K (P@K)
CNormalized Discounted Cumulative Gain (NDCG)
DMean Reciprocal Rank (MRR)
Attempts:
2 left
💡 Hint

Look for a metric that considers position of relevant results and graded relevance.

Practice

(1/5)
1. What is the main advantage of hybrid search combining semantic and keyword methods?
easy
A. It improves search relevance by using both exact words and meaning.
B. It only uses exact keyword matching for faster results.
C. It ignores word meanings to focus on keyword frequency.
D. It replaces keywords with random words for variety.

Solution

  1. Step 1: Understand keyword and semantic search roles

    Keyword search finds exact word matches; semantic search finds meaning matches.
  2. Step 2: Combine both for better results

    Hybrid search uses both to improve relevance and user satisfaction.
  3. Final Answer:

    It improves search relevance by using both exact words and meaning. -> Option A
  4. Quick Check:

    Hybrid search = better relevance [OK]
Hint: Hybrid = exact words + meaning for best results [OK]
Common Mistakes:
  • Thinking hybrid search uses only keywords
  • Assuming semantic search ignores keywords
  • Believing hybrid search slows down search always
2. Which of the following is the correct way to combine semantic and keyword scores in hybrid search?
easy
A. final_score = semantic_score * keyword_score
B. final_score = semantic_score / keyword_score
C. final_score = semantic_score - keyword_score
D. final_score = semantic_score + keyword_score

Solution

  1. Step 1: Understand score combination methods

    Adding scores balances contributions from both semantic and keyword parts.
  2. Step 2: Choose addition for hybrid scoring

    Adding semantic and keyword scores is common to combine relevance signals.
  3. Final Answer:

    final_score = semantic_score + keyword_score -> Option D
  4. Quick Check:

    Hybrid score = sum of semantic and keyword [OK]
Hint: Add scores to combine semantic and keyword relevance [OK]
Common Mistakes:
  • Multiplying scores causing very small or large values
  • Subtracting scores losing positive relevance
  • Dividing scores causing errors if denominator is zero
3. Given the code snippet:
semantic_scores = [0.8, 0.5, 0.3]
keyword_scores = [0.6, 0.7, 0.4]
final_scores = [s + k for s, k in zip(semantic_scores, keyword_scores)]
print(final_scores)

What is the output?
medium
A. [1.4, 1.2, 0.7]
B. [0.2, -0.2, -0.1]
C. [0.48, 0.35, 0.12]
D. [1.2, 1.4, 0.7]

Solution

  1. Step 1: Add corresponding semantic and keyword scores

    0.8+0.6=1.4, 0.5+0.7=1.2, 0.3+0.4=0.7
  2. Step 2: Create list of summed scores

    final_scores = [1.4, 1.2, 0.7]
  3. Final Answer:

    [1.4, 1.2, 0.7] -> Option A
  4. Quick Check:

    Sum pairs = [1.4, 1.2, 0.7] [OK]
Hint: Add pairs element-wise for final scores [OK]
Common Mistakes:
  • Multiplying instead of adding scores
  • Mixing order of scores in zip
  • Confusing subtraction with addition
4. Identify the error in this hybrid search scoring code:
semantic_scores = [0.9, 0.4, 0.7]
keyword_scores = [0.5, 0.6]
final_scores = [s + k for s, k in zip(semantic_scores, keyword_scores)]
print(final_scores)
medium
A. Adding scores should use multiplication instead.
B. Using zip causes a syntax error here.
C. Lists have different lengths causing missing scores.
D. The print statement is missing parentheses.

Solution

  1. Step 1: Check list lengths

    semantic_scores has 3 items; keyword_scores has 2 items.
  2. Step 2: Understand zip behavior

    zip stops at shortest list length, so last semantic score is ignored.
  3. Final Answer:

    Lists have different lengths causing missing scores. -> Option C
  4. Quick Check:

    Unequal list lengths truncate results [OK]
Hint: Ensure lists are same length before zipping [OK]
Common Mistakes:
  • Assuming zip pads shorter list automatically
  • Thinking zip causes syntax error
  • Believing multiplication is required for hybrid scores
5. You want to improve a hybrid search system by weighting semantic similarity twice as much as keyword matching. Which formula correctly applies this?
hard
A. final_score = semantic_score + 2 * keyword_score
B. final_score = 2 * semantic_score + keyword_score
C. final_score = semantic_score * keyword_score * 2
D. final_score = (semantic_score + keyword_score) / 2

Solution

  1. Step 1: Identify weighting requirement

    Semantic similarity should count double compared to keyword score.
  2. Step 2: Apply weights in formula

    Multiply semantic_score by 2, then add keyword_score.
  3. Final Answer:

    final_score = 2 * semantic_score + keyword_score -> Option B
  4. Quick Check:

    Semantic weighted double = 2 * semantic + keyword [OK]
Hint: Multiply semantic score by 2 before adding keyword [OK]
Common Mistakes:
  • Weighting keyword score instead of semantic
  • Multiplying all scores together
  • Dividing sum instead of weighting