Skip to content

temrjan/biotact_core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

24 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Biotact Production - AI-Powered RAG System

Intelligent knowledge base assistant for Biotact pharmaceutical company

๐Ÿš€ Live Demo: https://core.biotact.uz ๐Ÿ“ง Support: ruslan.biotact@gmail.com, x.temrjan@gmail.com


๐ŸŽฏ Overview

Production-ready RAG (Retrieval-Augmented Generation) system that provides intelligent responses based on Biotact's knowledge base using OpenAI embeddings and GPT-4o.

Key Features

  • โœ… Smart RAG Pipeline: Semantic search with GPT-4o responses
  • โœ… Multi-Department Support: Marketing, Sales, Medical, Support
  • โœ… File Upload: Web interface for uploading .md documents
  • โœ… Incremental Indexing: Only indexes new/changed documents
  • โœ… User Management: Admin approval workflow
  • โœ… Modern UI: React + TypeScript + Tailwind CSS
  • โœ… Production Ready: Deployed on Ubuntu with Nginx + SSL

๐Ÿ—๏ธ Current Architecture

Nginx (SSL/TLS)
  โ”œโ”€โ”€ Frontend (React SPA) โ†’ /frontend/dist
  โ””โ”€โ”€ API (FastAPI) โ†’ localhost:8000
        โ”œโ”€โ”€ Qdrant (Vector DB) โ†’ localhost:6333
        โ”œโ”€โ”€ OpenAI Embeddings (text-embedding-3-large)
        โ””โ”€โ”€ OpenAI GPT-4o (LLM)

Note: Simple single-server deployment. No Docker, no Kubernetes, no microservices overhead.


๐Ÿ”ง Technology Stack

Backend

  • Framework: FastAPI 0.115.0
  • Language: Python 3.11+
  • Vector DB: Qdrant 1.12
  • AI/ML:
    • OpenAI text-embedding-3-large (3072 dimensions)
    • OpenAI GPT-4o (LLM)
  • RAG Framework: LlamaIndex 0.11.20

Frontend

  • Framework: React 18 + TypeScript
  • Build Tool: Vite 6
  • UI Components: shadcn/ui + Tailwind CSS
  • State: React Context API
  • Icons: Lucide React

Infrastructure

  • Web Server: Nginx
  • SSL: Let's Encrypt
  • OS: Ubuntu 22.04 LTS
  • Deployment: systemd services

๐Ÿ“ฆ Quick Start

Prerequisites

# Required
- Ubuntu 20.04+ / Debian 11+
- Python 3.11+
- Node.js 18+
- 8GB+ RAM (for Qdrant)
- OpenAI API key

# Optional
- Nginx (for production)
- SSL certificate

Installation (Local Development)

1. Clone repository

git clone https://github.com/temrjan/biotact_core.git biotact-production
cd biotact-production

2. Setup environment

# Copy example .env
cp .env.example .env

# Edit .env and add your API keys
nano .env

Required environment variables:

# OpenAI
OPENAI_API_KEY=sk-proj-...
OPENAI_EMBEDDING_MODEL=text-embedding-3-large
OPENAI_EMBEDDING_DIMENSIONS=3072

# Qdrant
QDRANT_HOST=localhost
QDRANT_PORT=6333
QDRANT_COLLECTION_NAME=biotact_knowledge_v3

# URLs (for production)
API_URL=https://core.biotact.uz

3. Run setup script

chmod +x setup_local_simple.sh
./setup_local_simple.sh

This will:

  • Create Python virtual environment
  • Install backend dependencies
  • Install Qdrant
  • Setup directories

4. Install frontend

cd frontend
npm install
npm run dev  # Development mode
# OR
npm run build  # Production build

5. Prepare documents

# Copy your .md files to:
cp your-docs/*.md data/documents/

6. Index documents

# Activate venv
source venv/bin/activate

# Run incremental indexing
python scripts/incremental_index.py

7. Start backend

# Development
venv/bin/uvicorn backend.main:app --reload --host 0.0.0.0 --port 8000

# Production (with logs)
venv/bin/uvicorn backend.main:app --host 0.0.0.0 --port 8000 >> logs/backend.log 2>&1 &

8. Access the application

# Frontend (dev): http://localhost:5173
# Backend API: http://localhost:8000
# API Docs: http://localhost:8000/docs

๐Ÿ“š Usage

Admin Login

Email: <admin-email>
Password: <your-secure-password>

Upload Documents

  1. Login as admin
  2. Go to right sidebar
  3. Drag & drop .md files or click to select
  4. Wait for upload to complete
  5. Click "ะ—ะฐะฟัƒัั‚ะธั‚ัŒ ะธะฝะดะตะบัะฐั†ะธัŽ" button
  6. Wait 30-60 seconds for indexing

Query the System

  1. Select department (Marketing, Sales, Medical, Support)
  2. Type your question
  3. System will:
    • Search relevant documents (vector similarity)
    • Generate response using GPT-4o
    • Show sources used

๐Ÿ” API Endpoints

Public

  • GET / - Root endpoint
  • GET /health - System health check
  • GET /departments - List available departments
  • POST /auth/login - User authentication
  • POST /auth/register - User registration

Authenticated

  • POST /chat - RAG chat with AI
  • POST /query - RAG query
  • POST /search - Vector search only
  • GET /stats - System statistics
  • POST /upload - Upload .md files (admin only)
  • POST /index - Run incremental indexing (admin only)

Admin Only

  • GET /auth/admin/users/pending - Pending users
  • POST /auth/admin/users/{id}/approve - Approve user
  • POST /auth/admin/users/{id}/reject - Reject user

API Documentation: http://localhost:8000/docs


๐Ÿ—‚๏ธ Project Structure

biotact-production/
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ main.py              # FastAPI app + RAG system
โ”‚   โ”œโ”€โ”€ config/
โ”‚   โ”‚   โ””โ”€โ”€ departments.py   # Department configurations
โ”‚   โ””โ”€โ”€ prompts/
โ”‚       โ”œโ”€โ”€ marketing.txt    # Marketing prompt
โ”‚       โ”œโ”€โ”€ sales.txt        # Sales prompt
โ”‚       โ”œโ”€โ”€ medical.txt      # Medical prompt
โ”‚       โ””โ”€โ”€ support.txt      # Support prompt
โ”œโ”€โ”€ frontend/
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/      # React components
โ”‚   โ”‚   โ”œโ”€โ”€ contexts/        # React contexts
โ”‚   โ”‚   โ”œโ”€โ”€ api/            # API client
โ”‚   โ”‚   โ””โ”€โ”€ types/          # TypeScript types
โ”‚   โ”œโ”€โ”€ dist/               # Production build
โ”‚   โ””โ”€โ”€ package.json
โ”œโ”€โ”€ data/
โ”‚   โ”œโ”€โ”€ documents/          # ๐Ÿ“ Upload .md files here
โ”‚   โ”œโ”€โ”€ .index_state.json   # Indexing state tracker
โ”‚   โ””โ”€โ”€ qdrant/            # Qdrant data (ignored by git)
โ”œโ”€โ”€ scripts/
โ”‚   โ””โ”€โ”€ incremental_index.py # Incremental indexing script
โ”œโ”€โ”€ docs/
โ”‚   โ””โ”€โ”€ INDEXING_GUIDE.md   # Indexing documentation
โ”œโ”€โ”€ logs/                   # Application logs
โ”œโ”€โ”€ venv/                   # Python virtual environment
โ”œโ”€โ”€ .env                    # Environment variables (not in git)
โ”œโ”€โ”€ .env.example           # Example environment variables
โ””โ”€โ”€ requirements.txt        # Python dependencies

๐Ÿ“– Documentation


๐Ÿ”„ Incremental Indexing

The system uses hash-based incremental indexing to avoid reprocessing unchanged files.

How it works:

  1. Calculates MD5 hash of each file
  2. Compares with previous state (.index_state.json)
  3. Only indexes new/modified files
  4. Removes vectors for deleted files

Run indexing:

# Manual
venv/bin/python scripts/incremental_index.py

# Via API (admin only)
curl -X POST https://core.biotact.uz/index

See: INDEXING_GUIDE.md


๐Ÿš€ Production Deployment

1. Install Nginx

sudo apt update
sudo apt install nginx

2. Configure Nginx

# Copy nginx config
sudo cp infrastructure/nginx/core.biotact.uz.conf /etc/nginx/sites-available/core.biotact.uz
sudo ln -s /etc/nginx/sites-available/core.biotact.uz /etc/nginx/sites-enabled/

# Test config
sudo nginx -t

# Reload
sudo systemctl reload nginx

3. Setup SSL (Let's Encrypt)

sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d core.biotact.uz

4. Setup systemd service

# Create service file
sudo nano /etc/systemd/system/biotact-backend.service
[Unit]
Description=Biotact Backend API
After=network.target

[Service]
Type=simple
User=temrjan
WorkingDirectory=/home/temrjan/project/biotact-production
Environment="PATH=/home/temrjan/project/biotact-production/venv/bin"
ExecStart=/home/temrjan/project/biotact-production/venv/bin/uvicorn backend.main:app --host 0.0.0.0 --port 8000
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
# Enable and start
sudo systemctl daemon-reload
sudo systemctl enable biotact-backend
sudo systemctl start biotact-backend

๐Ÿงช Testing

Health Check

curl http://localhost:8000/health
# {"status":"healthy","postgres":true,"qdrant":true,"embeddings":true,"llm":true}

Test RAG Query

curl -X POST http://localhost:8000/chat \
  -H "Content-Type: application/json" \
  -d '{
    "message": "ะงั‚ะพ ั‚ะฐะบะพะต ะฑะธะพั‚ะฐะบั‚?",
    "department": "marketing"
  }'

Check Qdrant

curl http://localhost:6333/collections/biotact_knowledge_v3

๐Ÿ“Š System Requirements

Minimum (Development)

  • CPU: 2 cores
  • RAM: 4GB
  • Disk: 20GB
  • Bandwidth: 10 Mbps

Recommended (Production)

  • CPU: 4 cores
  • RAM: 8GB
  • Disk: 50GB SSD
  • Bandwidth: 100 Mbps

Current Deployment

  • Server: Ubuntu 22.04 LTS
  • CPU: 2 vCPU
  • RAM: 8GB
  • Disk: 80GB
  • Vectors in DB: 45
  • Documents: 5 .md files

๐Ÿ› ๏ธ Troubleshooting

Backend won't start

# Check logs
tail -50 logs/backend.log

# Check port
lsof -i :8000

# Check Qdrant
curl http://localhost:6333/health

Frontend build fails

cd frontend
rm -rf node_modules package-lock.json
npm install
npm run build

Indexing errors

# Check documents directory
ls -la data/documents/

# Check Qdrant connection
curl http://localhost:6333/collections

# Re-run indexing with verbose output
venv/bin/python scripts/incremental_index.py

Qdrant connection errors

# Check Qdrant process
ps aux | grep qdrant

# Restart Qdrant
pkill qdrant
# Start Qdrant (see setup script)

๐Ÿ”’ Security Notes

โš ๏ธ Current Implementation (Development):

  • User passwords in plain text (in-memory dictionary)
  • Simple token authentication (not JWT)
  • No rate limiting
  • No input validation

โœ… TODO for Production:

  • Implement PostgreSQL user storage
  • Hash passwords with bcrypt/argon2
  • Use JWT tokens with expiration
  • Add rate limiting
  • Add input sanitization
  • Enable CORS restrictions
  • Add request logging
  • Setup firewall rules

๐Ÿ“ˆ Performance

Current Metrics:

  • Response time: ~3-5 seconds (GPT-4o generation)
  • Concurrent users: ~10-20
  • Vector search: <100ms
  • Embedding generation: ~500ms
  • Total throughput: ~5-10 requests/minute

Optimization Tips:

  • Use GPT-4o-mini for faster/cheaper responses (17x cheaper)
  • Increase similarity_top_k for better context
  • Add Redis caching for frequent queries
  • Use streaming responses for better UX

๐Ÿค Contributing

This is a private production system. For authorized team members:

  1. Create feature branch: git checkout -b feature/your-feature
  2. Make changes and test locally
  3. Commit: git commit -m "feat: your feature"
  4. Push: git push origin feature/your-feature
  5. Create Pull Request

๐Ÿ“„ License

Proprietary - Biotact ยฉ 2024

Unauthorized copying, modification, or distribution is prohibited.


๐Ÿ‘ฅ Team


๐Ÿ“ž Support

Issues: Create issue on GitHub Email: support@biotact.com Telegram: @biotact_support


๐ŸŽฏ Roadmap

โœ… Completed (v1.0)

  • Basic RAG pipeline
  • Multi-department support
  • File upload interface
  • Incremental indexing
  • Admin user management
  • Production deployment
  • Migration to GPT-4o

๐Ÿšง In Progress (v1.1)

  • PostgreSQL user storage
  • Better error handling
  • Response caching
  • Analytics dashboard

๐Ÿ“‹ Planned (v2.0)

  • Chat history
  • Document versioning
  • Multi-language support (Uzbek)
  • Voice input/output
  • Mobile app
  • Advanced analytics

Version: 1.0.1 Last Updated: November 20, 2025 Status: โœ… Production Ready

About

AI-powered personalized recommendation system for Biotact supplements using RAG architecture with Claude Sonnet 4.5, LlamaIndex, and Qdrant vector database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors