Skip to main content
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:
  1. Exact match search - Checks for direct title matches using a hash map
  2. Semantic search - Uses FAISS HNSW index with sentence embeddings
rag_engine3.py
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:
rag_engine3.py
def _normalize_title(self, title: str) -> str:
    """Normalize a title for exact match search."""
    return title.strip().lower()

Examples

Two Sum
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:
retriever2.py
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

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.

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

rag_engine3.py
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 RangeQualityAction
0.9 - 1.0Excellent matchDirect answer
0.7 - 0.9Good matchHigh confidence answer
0.6 - 0.7Moderate matchAnswer with lower confidence
< 0.6Poor matchAutomatic retry with relaxed threshold

Automatic Fallback

If no solutions meet the confidence threshold, Quest automatically retries:
rag_engine3.py
# 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:
  1. Retrieves more results (k + 2)
  2. Lowers the threshold (min_confidence - 0.1)
  3. 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:
retriever2.py
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

Bad Query

arrays
Why it’s bad: Too vague, thousands of problems use arraysConfidence: ~0.3-0.5

Better Query

find two numbers in array that sum to target
Why it’s better: Describes the specific problemConfidence: ~0.85

Best Query

Two Sum
Why it’s best: Exact title matchResult: Instant exact match

Mode-Specific Query Tips

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

Contextual Queries with History

Quest maintains conversation history (last 3 turns by default):
rag_engine3.py
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

1

First query

Explain the Two Sum problem
Quest retrieves the Two Sum solution and explains it.
2

Follow-up query

What's the space complexity?
Quest uses conversation history to understand “the” refers to Two Sum.
3

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

Using Example Inputs

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:
  1. Use more specific keywords from the problem domain
  2. Mention the data structure explicitly
  3. Try the exact LeetCode title if you know it
  4. Use Reasoning mode for better analysis
Symptom: Low confidence scores (< 0.6)Solutions:
  1. Rephrase using algorithm/data structure names
  2. Break down your query into key concepts
  3. Check for typos in technical terms
  4. Try a simpler, more direct phrasing
Symptom: No results foundSolutions:
  1. The problem might not be in the database
  2. Try a more general query
  3. Use semantic search instead of exact title
  4. 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

Build docs developers (and LLMs) love