A scalable AI Support Assistant built with Laravel 12 with 29 production-ready API endpoints.
- Multi-Format Document Processing: PDF, DOCX, TXT with parallel batch processing
- Intelligent Vector Search: OpenAI embeddings with automatic storage optimization (JSON/pgvector/Qdrant)
- Conversation Memory: Context-aware follow-up questions with streaming responses (SSE)
- Quota Management: Track usage, messages, and token consumption
- Multi-Tenant Workspaces: Isolated environments with filtering
- Production Ready: Laravel Sanctum auth, Redis queues, rate limiting
- Framework: Laravel 12 (PHP 8.4)
- AI Model: GPT-4o-mini (chat completions)
- Embeddings: text-embedding-3-small (1536 dimensions)
- Database: MariaDB/MySQL (JSON vector storage) or PostgreSQL (pgvector support)
- Cache & Queue: Redis (Required for batch processing)
- Authentication: Laravel Sanctum with API tokens
- Vector Storage: Auto-detecting (JSON/pgvector/Qdrant)
-
Clone & Install
git clone https://github.com/3idey/ai-support-bot.git cd ai-support-bot composer install -
Environment Setup
cp .env.example .env php artisan key:generate
Configure your
.envfile:OPENAI_API_KEY=sk-... DB_CONNECTION=mariadb QUEUE_CONNECTION=redis CACHE_DRIVER=redis
-
Database & Migration
touch database/database.sqlite # If using SQLite php artisan migrate -
Start Services Ensure Redis is running:
redis-server
Start the queue worker (Critical for batch processing):
php artisan queue:work
Start the dev server:
php artisan serve
All API endpoints require a Bearer token:
Authorization: Bearer <your-token>Generate a token: php artisan tinker β User::first()->createToken('dev')->plainTextToken
Monitor and track user usage limits.
curl http://localhost:8000/api/quota \
-H "Authorization: Bearer <token>"Response:
{
"message_quota": { "total": 50, "used": 15, "remaining": 35, "percentage": 30 },
"token_quota": { "total": 100000, "used": 12450, "remaining": 87550, "percentage": 12.45 },
"document_quota": { "total": 100, "used": 5, "remaining": 95, "percentage": 5 }
}GET /api/quota/check- Simple boolean checkGET /api/quota/remaining- Get remaining messagesGET /api/quota/tokens- Get remaining tokensGET /api/quota/usage- Detailed usage breakdownPOST /api/quota/track- Manually track token usageGET /api/quota/documents- Check document quotaPOST /api/quota/documents/validate- Validate document size
Multi-tenant workspace isolation and filtering.
curl http://localhost:8000/api/workspaces \
-H "Authorization: Bearer <token>"curl -X POST http://localhost:8000/api/workspaces \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"name": "Customer Support", "description": "Support documentation"}'GET /api/workspaces/{id}- Show workspace detailsPUT /api/workspaces/{id}- Update workspaceDELETE /api/workspaces/{id}- Delete workspaceGET /api/workspaces/{id}/documents- List workspace documentsGET /api/workspaces/{id}/conversations- List workspace conversations
Manage chat history and conversations.
curl http://localhost:8000/api/conversations?workspace_id=1 \
-H "Authorization: Bearer <token>"curl http://localhost:8000/api/conversations/1/messages \
-H "Authorization: Bearer <token>"GET /api/conversations/{id}- Show conversation detailsDELETE /api/conversations/{id}- Delete conversation
Upload and manage knowledge base documents with filtering.
curl http://localhost:8000/api/documents?workspace_id=1 \
-H "Authorization: Bearer <token>"curl -X POST http://localhost:8000/api/documents \
-H "Authorization: Bearer <token>" \
-F "[email protected]" \
-F "workspace_id=1"GET /api/documents/{id}- Show document detailsDELETE /api/documents/{id}- Delete document
curl -X POST http://localhost:8000/api/ask \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{
"question": "How do I reset my password?",
"workspace_id": 1
}'curl -N -X POST http://localhost:8000/api/ask \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{
"question": "Tell me more about that.",
"conversation_id": 1,
"stream": true
}'Stream Events:
event: sources- Related document chunksevent: conversation_id- ID for follow-upsdata: {"content": "..."}- Answer tokensdata: [DONE]- Stream complete
Intelligent vector storage with automatic optimization recommendations.
curl http://localhost:8000/api/vectors/status \
-H "Authorization: Bearer <token>"Response:
{
"system": "mariadb_json",
"status": "active",
"total_embeddings": 150,
"avg_dimensions": 1536,
"database": "MariaDB 11.6.2",
"storage_method": "JSON columns with PHP cosine similarity"
}curl http://localhost:8000/api/vectors/recommendations \
-H "Authorization: Bearer <token>"curl -X POST http://localhost:8000/api/vectors/benchmark \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"sample_size": 10}'curl -X POST http://localhost:8000/api/vectors/migrate \
-H "Authorization: Bearer <token>"curl http://localhost:8000/api/health- Vector Search: ~30ms (JSON), ~5ms (pgvector), ~1ms (Qdrant)
- API Response: <100ms average
- Scaling: Stateless design with horizontal scaling support
MIT License