Skip to content

About

AIAssistantWithRAG is a production-ready AI assistant platform designed for multi-tenant environments. It leverages Retrieval-Augmented Generation (RAG) to provide accurate, context-aware responses based on company-specific documents and knowledge bases.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

AIAssistantWithRAG

Python FastAPI LangChain Qdrant Ollama Docker License

A powerful Multi-Company AI Assistant with RAG (Retrieval-Augmented Generation)

Features • Installation • Usage • API • Contributing


Description

AIAssistantWithRAG is a production-ready AI assistant platform designed for multi-tenant environments. It leverages Retrieval-Augmented Generation (RAG) to provide accurate, context-aware responses based on company-specific documents and knowledge bases.

Key Highlights

  • Multi-Company Architecture: Complete data isolation between companies
  • RAG-Powered Intelligence: Answers grounded in your actual documents
  • Multilingual Support: Understands French, English, and Moroccan Darija
  • Privacy-First: Local LLM with Ollama - your data stays on your servers
  • Product Catalog Integration: Smart product recommendations with images and pricing
  • High Performance: Qdrant vector database for lightning-fast semantic search
  • Docker Ready: Complete containerization with Docker Compose
  • Cross-Platform: Supports Windows, Linux, and macOS deployment

Architecture

AIAssistantWithRAG/
│
├── main.py                    # FastAPI application entry point
├── config.py                  # Configuration & environment settings
│
├── api/
│   ├── upload.py                 # Document upload & processing endpoints
│   └── chat.py                   # Conversational AI endpoints
│
├── rag/
│   ├── embeddings.py             # BGE-M3 multilingual embeddings
│   ├── qdrant.py                 # Vector database operations
│   └── chain.py                  # LangChain RAG orchestration
│
├── docker/
│   ├── Dockerfile                # Application container
│   ├── docker-compose.yml       # Multi-service orchestration
│   ├── .dockerignore            # Docker build context
│   └── .env.docker              # Docker environment template
│
├── prompts/
│   └── master_prompt.txt         # AI behavior & response templates
│
├── services/
│   ├── document_loader.py        # Multi-format document processing
│   └── product_service.py        # Product search & recommendations
│
├── scripts/
│   ├── start.sh                  # Unix/Linux startup script
│   └── start.bat                 # Windows startup script
│
└── storage/
    └── company_{id}/             # Isolated company document storage

Features

Core Capabilities

Feature Description
Multi-Tenancy Complete data isolation per company with unique collections
Document Processing Support for PDF, TXT, DOCX, CSV, JSON formats
Semantic Search BGE-M3 embeddings for accurate multilingual retrieval
Conversational AI Context-aware chat with conversation history
Product Intelligence Smart product recommendations with pricing
Multilingual Darija, French, English understanding & responses

Technical Stack

  • Backend Framework: FastAPI (async, high-performance)
  • LLM Orchestration: LangChain
  • Vector Database: Qdrant
  • Embeddings: BAAI/bge-m3 (1024 dimensions)
  • Local LLM: Ollama (llama3.2)
  • Document Processing: LangChain Document Loaders

Prerequisites

Choose your deployment method:

Docker Deployment (Recommended)

  • Docker and Docker Compose installed
  • 8GB+ RAM recommended
  • 5GB free disk space for models

Manual Installation

  • Python 3.11+ installed
  • Docker (for Qdrant) or Qdrant Cloud account
  • Ollama installed and running
  • 8GB+ RAM recommended for embeddings model

Installation

Option 1: Docker Deployment (Recommended)

Step 1: Clone the Repository

git clone https://github.com/ISTIFANO/AIAssistantWithRAG.git
cd AIAssistantWithRAG

Step 2: Configure Environment

# Copy Docker environment template
cp .env.docker .env

# Edit if needed (optional)
nano .env

Step 3: Start with Docker Compose

# Build and start all services
docker-compose up -d --build

# Or use the startup scripts:
# Windows:
start.bat

# Unix/Linux/macOS:
./start.sh

Step 4: Verify Installation

# Check all containers are running
docker ps

# Check API health
curl http://localhost:8000/health

Your AI Assistant is ready at: http://localhost:8000

Option 2: Manual Installation

Step 1: Clone the Repository

git clone https://github.com/ISTIFANO/AIAssistantWithRAG.git
cd AIAssistantWithRAG

Step 2: Create Virtual Environment

# Create environment
python -m venv venv

# Activate (Windows)
venv\Scripts\activate

# Activate (Linux/Mac)
source venv/bin/activate

Step 3: Install Dependencies

pip install -r requirements.txt

Step 4: Configure Environment

# Copy example configuration
cp .env.docker .env

# Edit with your settings
nano .env  # or use your preferred editor

Step 5: Start Qdrant Vector Database

# Using Docker
docker run -p 6333:6333 -p 6334:6334 qdrant/qdrant

# Or use Qdrant Cloud (update .env accordingly)

Step 6: Setup Ollama LLM

# Install Ollama from https://ollama.ai

# Pull the model
ollama pull llama3.2

# Verify it's running
ollama list

Step 7: Run the Application

# Development mode with auto-reload
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

# Production mode
uvicorn app.main:app --workers 4 --host 0.0.0.0 --port 8000

Access the API at: http://localhost:8000

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


Docker Services

The Docker setup includes 4 services:

Service Description Port
ai-assistant-app FastAPI application 8000
ai-assistant-qdrant Vector database 6333, 6334
ai-assistant-ollama Local LLM server 11434
ai-assistant-ollama-init Model downloader -

Docker Commands

# Start all services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop all services
docker-compose down

# Rebuild and restart
docker-compose up -d --build

# Check service status
docker ps

API Endpoints

Health Check

GET /health

Upload Documents

Upload company documents for RAG processing.

POST /api/v1/upload
Content-Type: multipart/form-data
Parameter Type Required Description
company_id string Yes Unique company identifier
company_name string Yes Company display name
files File[] Yes Documents to upload

Example Response:

{
  "success": true,
  "message": "Successfully processed 3 files",
  "company_id": "cmp_001",
  "files_processed": 3,
  "chunks_created": 127
}

Chat

Conversational endpoint with RAG-powered responses.

POST /api/v1/chat
Content-Type: application/json

Request Body:

{
  "company_id": "cmp_001",
  "company_name": "My Company",
  "message": "شنو العروض اللي عندكم دابا؟",
  "conversation_history": []
}

Response:

{
  "success": true,
  "reply_text": "عندنا عروض مزيانين هاد الشهر! كاين تخفيضات على...",
  "products": [
    {
      "name": "Premium Package",
      "description": "باقة متكاملة للشركات",
      "price": "999 DH",
      "image_url": "https://example.com/image.jpg"
    }
  ],
  "sources": ["offers_2024.pdf", "catalog.pdf"]
}

Delete Company Data

DELETE /api/v1/documents/{company_id}

Configuration

Environment Variables

Variable Description Default
APP_NAME Application name AI Assistant with RAG
DEBUG Debug mode True
QDRANT_HOST Qdrant server host localhost
QDRANT_PORT Qdrant server port 6333
QDRANT_API_KEY Qdrant API key (optional) -
OLLAMA_BASE_URL Ollama API URL http://localhost:11434
OLLAMA_MODEL LLM model name llama3.2
EMBEDDING_MODEL Embedding model BAAI/bge-m3
EMBEDDING_DIMENSION Vector dimensions 1024
CHUNK_SIZE Document chunk size 1000
CHUNK_OVERLAP Chunk overlap 200
TOP_K_RESULTS RAG retrieval count 5

Usage Examples

Python Client

import requests

# Upload documents
files = [
    ('files', open('catalog.pdf', 'rb')),
    ('files', open('pricing.csv', 'rb'))
]
data = {
    'company_id': 'cmp_001',
    'company_name': 'My Company'
}
response = requests.post(
    'http://localhost:8000/api/v1/upload',
    files=files,
    data=data
)

# Chat
response = requests.post(
    'http://localhost:8000/api/v1/chat',
    json={
        'company_id': 'cmp_001',
        'company_name': 'My Company',
        'message': 'What products do you have?'
    }
)
print(response.json())

cURL

# Upload
curl -X POST http://localhost:8000/api/v1/upload \
  -F "company_id=cmp_001" \
  -F "company_name=My Company" \
  -F "files=@catalog.pdf"

# Chat
curl -X POST http://localhost:8000/api/v1/chat \
  -H "Content-Type: application/json" \
  -d '{"company_id":"cmp_001","company_name":"My Company","message":"Hello!"}'

Testing

# Run tests
pytest tests/ -v

# With coverage
pytest tests/ --cov=app --cov-report=html

Supported File Formats

Format Extension Description
PDF .pdf Product catalogs, manuals
Text .txt Plain text documents
Word .docx Microsoft Word documents
CSV .csv Product lists, pricing tables
JSON .json Structured data, configs

Security Features

  • Data Isolation: Each company's data stored in separate Qdrant collections
  • Local Processing: LLM runs locally with Ollama
  • No Data Leakage: Strict company-based filtering in all queries
  • Input Validation: Pydantic models for request validation

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.


Author

ISTIFANO


Acknowledgments

  • FastAPI - Modern Python web framework
  • LangChain - LLM application framework
  • Qdrant - Vector similarity search engine
  • Ollama - Local LLM runner
  • BAAI - BGE embedding models

Star this repo if you find it helpful!

Made with love in Morocco

About

AIAssistantWithRAG is a production-ready AI assistant platform designed for multi-tenant environments. It leverages Retrieval-Augmented Generation (RAG) to provide accurate, context-aware responses based on company-specific documents and knowledge bases.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages