Skip to content

Latest commit

 

History

105 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NepseBot - AI-Powered NEPSE Chatbot with Hybrid RAG

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.

✨ Key Features

🤖 Hybrid RAG 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

💼 Finance Features

  • 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

⚡ Performance

  • Fast semantic search (~100-200ms)
  • Intelligent result reranking
  • Lightweight embedding model (90MB)
  • CPU-friendly (no GPU required)
  • Thread-safe operations

🚀 Quick Start

Prerequisites

Installation

  1. Clone and navigate:
cd nepse-chatbot
  1. Install dependencies:
pip install -r requirements.txt
  1. Configure environment: Create .env file with:
GROQ_API_KEY=your_api_key_here
SARVAM_API_KEY=your_sarvam_api_key_here
FLASK_SECRET_KEY=your_secret_key_here

Voice 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.

  1. Run the application:
uvicorn app.main:app --reload
  1. Access the chatbot: Open http://localhost:8000 in your browser

📖 Usage

Chat with the Bot

# 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?"

Use Advanced RAG API

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"

📚 Documentation

🏗️ Architecture

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

🔧 Configuration

RAG Parameters

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

📊 Performance

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%

🧪 Testing

Run the test suite:

python test_hybrid_rag.py

This tests:

  • Hybrid RAG retrieval
  • Chat service integration
  • Result quality and scoring
  • Performance metrics

📁 Project Structure

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 

🛠️ Technologies

Backend

  • FastAPI - Web framework
  • Groq API - LLM (Llama 3.3 70B)
  • Sentence Transformers - Embeddings
  • BM25 - Keyword search
  • Pandas - Data analysis
  • Python-dotenv - Configuration

Frontend

  • HTML5/CSS3 - User interface
  • Vanilla JavaScript - Interactivity
  • Jinja2 - Template engine

🔐 Safety & Disclaimers

⚠️ Important: This is an educational tool. Always:

  • 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

📝 License

Educational use only. See LICENSE file for details.

🤝 Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

Empowering NEPSE investors with AI-powered intelligence! 🚀

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages