Quest is a Retrieval-Augmented Generation (RAG) engine designed to assist with solving and explaining Data Structures and Algorithms (DSA) problems. It leverages a combination of retrieval-based methods and generative models to provide accurate and context-aware solutions to coding problems, explanations of concepts, and metadata about LeetCode-style questions.
- Exact Matching Retrieval: Quickly retrieves solutions for exact matches of problem titles from a curated dataset.
- Context-Aware Generation: Generates detailed explanations and solutions for general queries using a generative model.
- Metadata Integration: Provides metadata such as problem difficulty, related topics, and edge cases for retrieved solutions.
- Efficient Search: Uses FAISS and HNSW for fast and accurate similarity search in high-dimensional spaces.
- Customizable: Supports different models and configurations for retrieval and generation.
- Pre-Generated Solutions: Includes 1800+ solutions in JSON format, created using the
qwen2.5-coder:1.5bmodel on a local machine. - Optimized Inference Speed: Reduced query retrieval time from 1 minute to 15 seconds and reasoning model time from 20 minutes to under 4 minutes.
- Dynamic Prompt Switching: Implements dynamic prompt switching for Qwen and Deepseek models to prevent infinite reasoning loops.
- Unknown Query Handling: Switches to model’s own inference for queries with confidence below 0.6 for better accuracy.
- HNSW Indexing: Fine-tuned HNSW parameters for faster and more relevant query retrieval.
- Memory Buffer: Retains past interactions for more contextually accurate responses over multiple queries.
- Dataset Generation: Created an on-device dataset of over 1850 coding questions JSON, enriched with metadata.
- Reasoning Model Integration: Integrated Deepseekr1 7B for complex problem-solving with optimized prompt templates.
- Frontend Interface: Built with Flask and Bootstrap, featuring a clean and responsive design with interactive elements.
- Search and Query Optimization: Optimized query engine with efficient indexing and metadata-based retrieval.
- Code Quality: Well-structured code, easy to understand, extend, and deploy, hosted on GitHub for public access.
-
Clone the repository:
git clone https://github.com/udit-rawat/Quest.git cd Quest -
Install the required dependencies:
pip install -r requirements.txt
-
Unzip the
leetcode_solutions.zipfile to access the solutions in JSON format:unzip leetcode_solutions.zip -d src/DSAAssistant/components/
To use the generative models (qwen2.5-coder:1.5b and deepseek-r1:1.5b), you need to install Ollama and pull the required models.
-
macOS: Download and install Ollama from the official website:
Ollama for macOS -
Windows: Download and install Ollama from the official website:
Ollama for Windows
Once Ollama is installed, pull the required models using the following commands:
# Pull qwen2.5-coder:1.5b
ollama pull qwen2.5-coder:1.5b
# Pull deepseek-r1:1.5b
ollama pull deepseek-r1:1.5b-
Start the RAG engine:
python app.py
-
Use the engine to query solutions or explanations. Example:
Query: "Explain the concept of dynamic programming."
Quest/
├── app.py # Main application entry point
├── requirements.txt # List of dependencies
├── .gitignore # Files and directories to ignore
├── README.md # Project documentation
├── src/
│ ├── DSAAssistant/ # Core components of the RAG engine
│ │ ├── components/
│ │ │ ├── retriever2.py # LeetCode retriever implementation
│ │ │ ├── rag_engine.py # RAG engine implementation
│ │ │ ├── leetcode_hnsw.index # Pre-built HNSW index
│ │ │ ├── leetcode_metadata.pkl # Metadata for LeetCode problems
│ │ │ ├── leetcode_solutions.zip # Zipped JSON solutions
│ │ │ └── ... # Other components
│ │ └── ... # Additional modules
│ └── ... # Other source files
└── ... # Configuration and other files
The RAG engine can be configured using the following parameters:
-
Retriever:
index_path: Path to the HNSW index file.metadata_path: Path to the metadata file.model_name: Name of the sentence transformer model for encoding.
-
Generation:
ollama_url: URL for the Ollama API (if using a remote model).model_name: Name of the generative model.temperature: Controls the randomness of the generated output.top_p: Controls the diversity of the generated output.
Example configuration:
retriever = LeetCodeRetriever(
index_path="path/to/leetcode_hnsw.index",
metadata_path="path/to/leetcode_metadata.pkl",
model_name="all-MiniLM-L6-v2"
)
rag_engine = RAGEngine(
retriever=retriever,
ollama_url="http://localhost:11434/api/generate",
model_name="qwen2.5-coder:1.5b",
temperature=0.4,
top_p=0.9
)Contributions are welcome! If you'd like to contribute to Quest, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix:
git checkout -b feature/your-feature-name
- Commit your changes:
git commit -m "Add your feature or fix" - Push your branch:
git push origin feature/your-feature-name
- Open a pull request and describe your changes.
- FAISS and HNSW for efficient similarity search.
- Sentence Transformers for encoding text into embeddings.
- Ollama for providing the generative model API.
For questions or feedback, feel free to reach out:
- Udit Rawat
- GitHub: udit-rawat
- Email: [email protected]
