Production-ready Telegram bot + modular RAG API for personal knowledge retrieval. This project lets you upload documents/audio, process them through a RAG pipeline, and ask grounded questions from Telegram or API clients.
- Telegram bot interface (
bot.py) - FastAPI backend (
app/) - Document/audio ingestion and processing pipeline
- Retrieval + grounded answer generation
- Optional GitHub workflow templates in
.github/workflow-templates/
- Telegram commands and keyboard workflow for querying and uploads
- File upload support (PDF, images, text, audio)
- Voice query flow: speech input -> RAG answer -> optional audio reply
- Citation-aware responses (
query_docmode) - Config-driven provider selection for storage, OCR, embeddings, and LLM
- Upload document/audio
- Validate size, type, and extension
- Persist file to storage
- Save document metadata to MongoDB
- Run async ingestion pipeline
- Extract text (OCR fallback when needed)
- Clean and normalize text
- Chunk content semantically
- Generate embeddings
- Save chunks + vectors
- Query with layered retrieval
- Return grounded answer with optional citations
GET /healthGET /readyPOST /api/v1/documents/uploadPOST /api/v1/documents/audioPOST /api/v1/documents/textGET /api/v1/documents/{document_id}POST /api/v1/queryPOST /api/v1/query/audio
/startand/help: show usage/query <question>: standard answer flow/query_doc <question>: answer with citations and downloadable summary/text <note>: save text into the knowledge base/stats: bot status placeholder/reset: reset local conversation state/id: show Telegram numeric user ID
Supported Telegram interactions:
- Send a document file to ingest knowledge
- Send an audio file to ingest/query
- Send a voice message to query via speech
- Python 3.10+
- MongoDB (local or Atlas)
- Telegram Bot token
- API keys based on chosen providers
git clone <your-repo-url> knowledge-rag-bot
cd knowledge-rag-bot
python -m venv .venvWindows PowerShell:
.\.venv\Scripts\Activate.ps1macOS/Linux:
source .venv/bin/activateInstall dependencies:
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r app/requirements.txtCreate environment file:
cp .env.example .envOn Windows cmd:
copy .env.example .envFill .env with your real values before running.
For Telegram bot:
TELEGRAM_TOKENRAG_API_KEYCORTEX_BASE_URL(for hosted API) or local API URLALLOWED_USERS(comma-separated Telegram user IDs)
For API runtime:
MONGODB_URIDATABASE_NAMEAPI_KEYS(comma-separated API keys accepted by backend)GEMINI_API_KEYand/or other provider keys based on configuration
uvicorn app.main:app --reloadDefault URL: http://127.0.0.1:8000
python bot.pyThe bot sends requests to ${CORTEX_BASE_URL}/api/v1.
- Never commit
.env, tokens, or credentials - Keep production keys in secret managers or platform secrets
- Restrict bot access with
ALLOWED_USERS - Rotate API keys regularly
This repository ships workflow templates only.
No GitHub Actions run until templates are copied into .github/workflows/.
See .github/README.md and .github/workflow-templates/README.md for activation steps.