The quality of Quest’s responses depends heavily on how you phrase your queries. This guide covers techniques for writing queries that return the most relevant and helpful results.
Understanding Quest’s Retrieval System
Quest uses a two-stage retrieval system:
Exact match search - Checks for direct title matches using a hash map
Semantic search - Uses FAISS HNSW index with sentence embeddings
def answer_question ( self , query : str , k : int = 5 , min_confidence : float = 0.6 ) -> str :
# Normalize the query for exact matching
normalized_query = self ._normalize_title(query)
# Check for exact match in the hash map
if normalized_query in self .exact_match_map:
exact_match_solution = self .exact_match_map[normalized_query]
logger.info( "Exact match found. Returning solution directly." )
return f "Exact Match Solution: \n { exact_match_solution.solution } "
# Retrieve relevant context using semantic search
retrieved_solutions = self .retriever.search(query, k = k, return_scores = True )
filtered_solutions = [sol for sol in retrieved_solutions
if hasattr (sol, 'score' ) and float (sol.score) >= min_confidence]
Exact Title Matching
For fastest and most accurate results, use exact problem titles.
How It Works
The system normalizes titles by converting to lowercase and stripping whitespace:
def _normalize_title ( self , title : str ) -> str :
"""Normalize a title for exact match search."""
return title.strip().lower()
Examples
Good - Exact Title
Good - Case Insensitive
Good - Extra Whitespace OK
Bad - Incomplete Title
If you know the exact problem name, use it! Quest will return the solution instantly without semantic search.
Semantic Search Queries
When you don’t know the exact title, semantic search finds similar problems.
Query Structure
The retriever uses sentence-transformers to encode queries:
def search ( self , query : str , k : int = 3 , return_scores : bool = True ) -> List[Tuple[Solution, float ]]:
# Encode query
query_vector = self .encoder.encode([query], show_progress_bar = False )
query_vector = query_vector.astype(np.float32)
# Search index
distances, indices = self .index.search(query_vector, k)
Good Query Patterns
Conceptual Queries
Data Structure Queries
Algorithm Queries
Problem Type Queries
Describe the algorithm or concept: Find two numbers that add up to target
Reverse a linked list iteratively
Find longest palindromic substring
These work well because they match the problem descriptions in the database. Mention specific data structures: Binary tree level order traversal
Hash map for finding duplicates
Stack for valid parentheses
Reference specific algorithms: Dynamic programming coin change
Binary search in rotated array
DFS graph traversal
Describe the problem category: Sliding window substring problem
Two pointer array problem
Greedy interval scheduling
Bad Query Patterns
Too vague: arrays
trees
help with coding
These return low-confidence matches because they don’t describe a specific problem.
Too specific with irrelevant details: I'm preparing for a Google interview and need help with a problem that uses arrays and I think it might involve sorting but I'm not sure
Extra context confuses the semantic search. Be concise.
Implementation-focused instead of problem-focused: How do I write a for loop in Python?
What is the syntax for a class?
Quest searches problem solutions, not general programming help.
Confidence Thresholds
Quest filters results by confidence score to ensure quality.
Default Threshold
confidence_threshold: float = 0.7 , # In __init__
# In answer_question:
min_confidence: float = 0.6
filtered_solutions = [sol for sol in retrieved_solutions
if hasattr (sol, 'score' ) and float (sol.score) >= min_confidence]
What Confidence Scores Mean
Score Range Quality Action 0.9 - 1.0 Excellent match Direct answer 0.7 - 0.9 Good match High confidence answer 0.6 - 0.7 Moderate match Answer with lower confidence < 0.6 Poor match Automatic retry with relaxed threshold
Automatic Fallback
If no solutions meet the confidence threshold, Quest automatically retries:
# Fallback if no solutions meet confidence threshold
if not filtered_solutions and k < 5 :
return self .answer_question(query, k = k + 2 , min_confidence = min_confidence - 0.1 )
This:
Retrieves more results (k + 2)
Lowers the threshold (min_confidence - 0.1)
Tries again
If you consistently get low-confidence results, try rephrasing your query with more specific keywords.
Optimizing Query Parameters
You can adjust retrieval parameters for different use cases.
Retrieve More Results
# Default: k=5
response = rag_engine.answer_question( "binary search" , k = 10 )
Higher k values:
✅ More diverse results
✅ Better chance of finding relevant solutions
❌ Slower retrieval
❌ May include less relevant results
Adjust Confidence Threshold
# Default: min_confidence=0.6
response = rag_engine.answer_question( "tree traversal" , min_confidence = 0.8 )
Higher thresholds:
✅ Only high-quality matches
❌ May return fewer results
Lower thresholds:
✅ More results
❌ May include less relevant solutions
HNSW Search Speed
The retriever uses HNSW for fast approximate search:
class LeetCodeRetriever :
def __init__ (
self ,
ef_search : int = 32 # Adjust for speed/accuracy trade-off
):
self .index.hnsw.efSearch = ef_search
Higher ef_search:
✅ More accurate results
❌ Slower search
Lower ef_search:
✅ Faster search
❌ May miss some relevant results
Examples: Good vs Bad Queries
Scenario 1: Array Problems
Scenario 2: Tree Problems
Scenario 3: Dynamic Programming
Bad Query Why it’s bad: Too vague, thousands of problems use arraysConfidence: ~0.3-0.5Better Query find two numbers in array that sum to target
Why it’s better: Describes the specific problemConfidence: ~0.85Best Query Why it’s best: Exact title matchResult: Instant exact matchBad Query How do I traverse a tree?
Why it’s bad: General question, not a specific problemConfidence: ~0.4Better Query binary tree inorder traversal
Why it’s better: Specific traversal typeConfidence: ~0.75Best Query Binary Tree Inorder Traversal
Why it’s best: Exact LeetCode problem titleResult: Exact matchBad Query Why it’s bad: No problem descriptionConfidence: ~0.2Better Query minimum number of coins for change
Why it’s better: Describes the problem goalConfidence: ~0.80Best Query Why it’s best: Exact problem nameResult: Exact match
Mode-Specific Query Tips
General Mode
Reasoning Mode
Best for Quick Answers Use simple, direct queries: Two Sum solution
Reverse linked list
Valid parentheses
The general model (qwen2.5-coder:1.5b) excels at:
Code generation
Short explanations
Common patterns
Best for Complex Problems Use detailed queries that benefit from step-by-step reasoning: Explain the optimal approach for longest increasing subsequence
Walk through the dynamic programming solution for edit distance
What's the time complexity analysis for merge intervals?
The reasoning model (deepseek-r1:7b) excels at:
Algorithm analysis
Complexity proofs
Trade-off discussions
Contextual Queries with History
Quest maintains conversation history (last 3 turns by default):
def generate_enhanced_prompt ( self , query : str , context : List[Solution]) -> str :
# Retrieve the conversation history
history_context = self .conversation_history.get_context()
enhanced_prompt = (
f "Conversation History: \n { history_context } \n\n "
f "Query: { query } \n\n "
f "Context: { context } \n\n "
f "Instruction: { base_prompt } "
)
Example Conversation
First query
Explain the Two Sum problem
Quest retrieves the Two Sum solution and explains it.
Follow-up query
What's the space complexity?
Quest uses conversation history to understand “the” refers to Two Sum.
Another follow-up
Show me the Python implementation
Still in context of Two Sum from history.
Use follow-up questions for deeper exploration. Quest remembers the last 3 exchanges.
Advanced Techniques
Combining Keywords
Combine multiple relevant keywords for better semantic matching:
sliding window maximum subarray
backtracking permutations distinct numbers
two pointers sorted array target sum
Specifying Constraints
Mention important constraints:
find duplicate in array with O(1) space
linked list cycle detection without modifying nodes
sort array in O(n) time
Describe with example inputs:
problem where input [2,7,11,15] target 9 returns [0,1]
find if string s="racecar" is palindrome
Troubleshooting Poor Results
Symptom: Getting irrelevant solutionsSolutions:
Use more specific keywords from the problem domain
Mention the data structure explicitly
Try the exact LeetCode title if you know it
Use Reasoning mode for better analysis
Symptom: Low confidence scores (< 0.6)Solutions:
Rephrase using algorithm/data structure names
Break down your query into key concepts
Check for typos in technical terms
Try a simpler, more direct phrasing
Symptom: No results foundSolutions:
The problem might not be in the database
Try a more general query
Use semantic search instead of exact title
Check the metadata filtering guide for alternative search methods
Next Steps
Metadata Filtering Filter solutions by difficulty, topics, and companies
Using the Web Interface Master all features of the Quest interface