Query Retrieval Instructions
Retrieval Methodology
- Embed document chunks using sentence-transformers model
- Embed user query using same model
- Calculate cosine similarity between query and chunk embeddings
- Return top-k results with similarity scores above threshold
Advanced Features
- Hybrid search: Combine semantic and keyword matching
- Query expansion: Add synonyms and related terms
- Reranking: Use cross-encoder for better precision
- Caching: Store embeddings to avoid recomputation
Implementation
def retrieve_relevant_chunks(query, chunks, top_k=5):
# Implementation here
pass