A Competitive Programming assistant powered by Retrieval-Augmented Generation (RAG) with local LLM capabilities. This project provides intelligent assistance for CP problems using VNOI/USACO documentation.
This is a full-stack application with two main components:
- Backend (api-rag): FastAPI-based RAG engine with local LLM processing
- Frontend (frontend): Next.js web interface using assistant-ui
- Semantic Chunking: Context-aware document splitting using Semantic Router
- Local LLM: Meta Llama 3 running via Ollama for privacy and cost efficiency
- Vector Search: Pinecone serverless vector database with high-quality embeddings
- Real-time Chat: Streaming responses with modern React UI
- Multi-language Support: Optimized for Vietnamese CP documentation
- Framework: FastAPI (Python 3.10+)
- LLM: Meta Llama 3 (local via Ollama)
- Vector DB: Pinecone Serverless Index
- Embeddings: nomic-ai/nomic-embed-text-v1.5 (768 dim)
- Chunking: Semantic Router with rolling window splitting
- Processing: LangChain integration
- Framework: Next.js 16 with React 19
- UI Components: assistant-ui, Radix UI
- Styling: Tailwind CSS
- AI Integration: Vercel AI SDK
- TypeScript: Full type safety
- Python 3.10+
- Node.js 18+
- Ollama installed and running
- Pinecone account and API key
- Navigate to the backend directory:
cd api-rag- Create a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Set up environment variables:
cp .env.example .env
# Edit .env with your Pinecone API key and other configurations- Start Ollama and pull Llama 3:
ollama serve
ollama pull llama3- Run the backend server:
python server.py- Navigate to the frontend directory:
cd frontend- Install dependencies:
npm install
# or
pnpm install- Set up environment variables:
cp .env.example .env.local
# Edit with your API keys if needed- Run the development server:
npm run dev
# or
pnpm dev- Open http://localhost:3000 in your browser.
CP-Helper/
βββ api-rag/ # Backend RAG engine
β βββ server.py # FastAPI server with chat endpoints
β βββ indexing.py # Document indexing and chunking
β βββ multiquery.py # RAG query processing
β βββ requirements.txt # Python dependencies
β βββ .env.example # Environment variables template
βββ frontend/ # Next.js frontend
β βββ app/ # App router pages
β βββ components/ # React components
β βββ package.json # Node.js dependencies
β βββ tsconfig.json # TypeScript configuration
β βββ tailwind.config.js # Tailwind CSS config
βββ .gitignore # Git ignore file
βββ README.md # This file
PINECONE_API_KEY: Your Pinecone API keyPINECONE_INDEX_NAME: Name of your Pinecone indexOLLAMA_BASE_URL: Ollama server URL (default: http://localhost:11434)
NEXT_PUBLIC_API_URL: Backend API URL (default: http://localhost:8000)
- Start both backend and frontend servers
- Open the web interface at http://localhost:3000
- Ask questions about competitive programming concepts
- Get intelligent responses based on VNOI/USACO documentation
The system is designed to work with competitive programming documentation from:
- VNOI (Vietnam Olympiad in Informatics)
- USACO (USA Computing Olympiad)
- CP-Algorithms
- Other CP learning resources
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
Main chat endpoint for querying the RAG system.
Request:
{
"question": "How does binary search work?"
}Response: Streaming response with RAG-enhanced answers.
# Backend
cd api-rag
pytest
# Frontend
cd frontend
npm test# Backend
cd api-rag
black .
isort .
# Frontend
cd frontend
npm run prettier:fix
npm run lint- Ollama connection failed: Make sure Ollama is running and Llama 3 is downloaded
- Pinecone connection error: Verify your API key and index configuration
- CORS issues: Check the CORS settings in
server.py
- Check the logs in both backend and frontend
- Ensure all environment variables are properly set
- Verify that Ollama and Pinecone services are accessible
Built with β€οΈ for the Competitive Programming community