A powerful Multi-Company AI Assistant with RAG (Retrieval-Augmented Generation)
Features • Installation • Usage • API • Contributing
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.
- 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
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
| 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 |
- 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
Choose your deployment method:
- Docker and Docker Compose installed
- 8GB+ RAM recommended
- 5GB free disk space for models
- Python 3.11+ installed
- Docker (for Qdrant) or Qdrant Cloud account
- Ollama installed and running
- 8GB+ RAM recommended for embeddings model
git clone https://github.com/ISTIFANO/AIAssistantWithRAG.git
cd AIAssistantWithRAG# Copy Docker environment template
cp .env.docker .env
# Edit if needed (optional)
nano .env# Build and start all services
docker-compose up -d --build
# Or use the startup scripts:
# Windows:
start.bat
# Unix/Linux/macOS:
./start.sh# Check all containers are running
docker ps
# Check API health
curl http://localhost:8000/healthYour AI Assistant is ready at: http://localhost:8000
git clone https://github.com/ISTIFANO/AIAssistantWithRAG.git
cd AIAssistantWithRAG# Create environment
python -m venv venv
# Activate (Windows)
venv\Scripts\activate
# Activate (Linux/Mac)
source venv/bin/activatepip install -r requirements.txt# Copy example configuration
cp .env.docker .env
# Edit with your settings
nano .env # or use your preferred editor# Using Docker
docker run -p 6333:6333 -p 6334:6334 qdrant/qdrant
# Or use Qdrant Cloud (update .env accordingly)# Install Ollama from https://ollama.ai
# Pull the model
ollama pull llama3.2
# Verify it's running
ollama list# 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 8000Access the API at: http://localhost:8000
API Documentation: http://localhost:8000/docs
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 | - |
# 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 psGET /healthUpload 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
}Conversational endpoint with RAG-powered responses.
POST /api/v1/chat
Content-Type: application/jsonRequest 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 /api/v1/documents/{company_id}| 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 |
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())# 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!"}'# Run tests
pytest tests/ -v
# With coverage
pytest tests/ --cov=app --cov-report=html| Format | Extension | Description |
|---|---|---|
.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 |
- 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
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
ISTIFANO
- GitHub: @ISTIFANO
- 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