NepseBot is an advanced AI-powered trading assistant designed specifically for Nepal Stock Exchange (NEPSE) investors. It provides instant access to domain-specific knowledge on SEBON regulations, tax structures, and market data through an intelligent hybrid RAG (Retrieval-Augmented Generation) system.
- Dense Retrieval: Semantic search using AI embeddings
- Sparse Retrieval: Keyword matching using BM25 algorithm
- Intelligent Combination: 70% semantic + 30% keyword (customizable)
- Smart Optimization: Query expansion, intent detection, deduplication
- High Accuracy: 90%+ relevance for financial queries
- NEPSE regulations and SEBON compliance information
- Capital gains and dividend tax calculations
- Settlement cycle explanations (T+2)
- Technical analysis indicators (RSI, SMA, Trend)
- Circuit breaker limits and trading rules
- Live market data integration
- Fast semantic search (~100-200ms)
- Intelligent result reranking
- Lightweight embedding model (90MB)
- CPU-friendly (no GPU required)
- Thread-safe operations
- Python 3.11+
- pip package manager
- GROQ API key (free at https://console.groq.com)
- Clone and navigate:
cd nepse-chatbot- Install dependencies:
pip install -r requirements.txt- Configure environment:
Create
.envfile with:
GROQ_API_KEY=your_api_key_here
SARVAM_API_KEY=your_sarvam_api_key_here
FLASK_SECRET_KEY=your_secret_key_hereVoice input and spoken replies use Sarvam AI. The browser microphone requires permission; SARVAM_STT_MODEL, SARVAM_TTS_MODEL, and SARVAM_TTS_SPEAKER can optionally override the defaults.
- Run the application:
uvicorn app.main:app --reload- Access the chatbot:
Open
http://localhost:8000in your browser
# Ask about trading rules
"What are the trading hours?"
# Ask about taxes
"What's the capital gains tax on NABIL shares?"
# Ask about technical analysis
"Explain RSI and what RSI > 70 means"
# Ask about regulations
"What is T+2 settlement?"Retrieve documents:
curl -X POST "http://localhost:8000/api/rag/retrieve" \
-H "Content-Type: application/json" \
-d '{
"query": "capital gains tax",
"top_k": 5,
"dense_weight": 0.7,
"sparse_weight": 0.3,
"optimize": true
}'Analyze query intent:
curl -X POST "http://localhost:8000/api/rag/analyze-intent?query=Should%20I%20buy%20stocks"Check service health:
curl "http://localhost:8000/api/rag/health"- HYBRID_RAG_GUIDE.md - Complete Hybrid RAG documentation
- IMPROVEMENTS.md - Fixes and improvements summary
- MIGRATION.md - Code structure migration guide
User Query
↓
├─ Market Data Analysis
├─ Hybrid RAG Retrieval
│ ├─ Dense Retrieval (Semantic Search)
│ ├─ Sparse Retrieval (BM25 Keyword Match)
│ ├─ Score Combination (70% semantic + 30% keyword)
│ └─ Result Optimization
├─ Context Enrichment
└─ LLM Response (Groq Llama 3.3)
↓
High-Quality Financial Guidance
Customize in .env:
RAG_EMBEDDING_MODEL=all-MiniLM-L6-v2
RAG_CACHE_EMBEDDINGS=true
RAG_TOP_K_RESULTS=5
RAG_DEFAULT_DENSE_WEIGHT=0.7
RAG_DEFAULT_SPARSE_WEIGHT=0.3
RAG_RELEVANCE_THRESHOLD=0.3| Metric | Value |
|---|---|
| Model Size | 90MB |
| First Query | 2-3 seconds |
| Subsequent Queries | 100-200ms |
| Memory Usage | ~500MB |
| CPU Required | Standard |
| GPU Required | Optional (not needed) |
| Accuracy | ~90% |
Run the test suite:
python test_hybrid_rag.pyThis tests:
- Hybrid RAG retrieval
- Chat service integration
- Result quality and scoring
- Performance metrics
nepse-chatbot/
├── app/
│ ├── api/
│ │ ├── __init__.py
│ │ ├── chat.py # Chat endpoints
│ │ ├── market.py # Market endpoints
│ │ └── rag.py # RAG endpoints
│ ├── core/
│ │ ├── config.py
│ │ └── rag_config.py # RAG configuration
│ ├── services/
│ │ ├── ai_service.py
│ │ ├── analysis_service.py
│ │ ├── chat_service.py
│ │ ├── knowledge_service.py
│ │ ├── hybrid_rag_service.py
│ │ └── rag_optimizer.py
│ └── main.py
├── static/
│ ├── css/
│ └── js/
├── templates/
│ ├── chat.html
│ └── index.html
├── tests/
│ └── test_chat.py
├── requirements.txt
├── HYBRID_RAG_GUIDE.md # RAG documentation
└── IMPROVEMENTS.md # Changes summary
- FastAPI - Web framework
- Groq API - LLM (Llama 3.3 70B)
- Sentence Transformers - Embeddings
- BM25 - Keyword search
- Pandas - Data analysis
- Python-dotenv - Configuration
- HTML5/CSS3 - User interface
- Vanilla JavaScript - Interactivity
- Jinja2 - Template engine
- Verify information with certified brokers
- Consult a financial advisor
- Don't make investment decisions solely based on chatbot recommendations
- Check current SEBON regulations before trading
Educational use only. See LICENSE file for details.
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Submit a pull request
Empowering NEPSE investors with AI-powered intelligence! 🚀