0
0
Prompt Engineering / GenAIml~12 mins

Hybrid search (semantic + keyword) in Prompt Engineering / GenAI - Model Pipeline Trace

Choose your learning style9 modes available
Model Pipeline - Hybrid search (semantic + keyword)

This hybrid search pipeline combines keyword matching with semantic understanding to find the most relevant documents. It first filters documents by keywords, then ranks them by semantic similarity using a trained model.

Data Flow - 5 Stages
1Input Query
1 query stringUser inputs a search query1 query string
"best Italian restaurants near me"
2Keyword Filtering
N documents x textFilter documents containing query keywordsM documents x text (M ≤ N)
From 1000 docs, filter to 150 docs containing words like 'Italian', 'restaurants'
3Semantic Embedding
1 query string and M documents x textConvert query and documents to vector embeddings1 query vector (768 dims), M document vectors (768 dims each)
Query vector: [0.12, -0.05, ..., 0.33], Document vector: [0.10, -0.02, ..., 0.30]
4Similarity Scoring
1 query vector, M document vectorsCalculate cosine similarity between query and each document vectorM similarity scores (float between -1 and 1)
[0.85, 0.78, 0.65, ...]
5Ranking and Output
M documents with similarity scoresSort documents by similarity score descendingTop K documents ranked
Top 5 documents with scores: [(doc23, 0.85), (doc7, 0.83), ...]
Training Trace - Epoch by Epoch

Loss
0.7 |****
0.6 |*** 
0.5 |**  
0.4 |*   
0.3 |*   
0.2 |    
     1 2 3 4 5 Epochs
EpochLoss ↓Accuracy ↑Observation
10.650.60Model starts learning semantic relations, initial moderate accuracy
20.480.72Loss decreases, accuracy improves as embeddings better capture meaning
30.350.81Model converges, semantic similarity scores become more reliable
40.300.85Fine tuning improves ranking quality, loss stabilizes
50.280.87Final epoch shows best balance of loss and accuracy
Prediction Trace - 4 Layers
Layer 1: Keyword Filtering
Layer 2: Semantic Embedding
Layer 3: Similarity Scoring
Layer 4: Ranking
Model Quiz - 3 Questions
Test your understanding
What is the main purpose of the keyword filtering stage?
ATo reduce the number of documents before semantic comparison
BTo convert text into vectors
CTo calculate similarity scores
DTo rank documents by relevance
Key Insight
Combining keyword filtering with semantic similarity balances speed and understanding, enabling efficient and meaningful search results.