Overview
The Olis API Server is a FastAPI-based backend service that provides the core intelligence behind Olis. It includes a sophisticated RAG (Retrieval-Augmented Generation) pipeline for document understanding and intelligent responses.Technology Stack
FastAPI
Modern, fast Python web framework
Uvicorn
Lightning-fast ASGI server
RAG Pipeline
Document retrieval and generation system
Vector Database
Semantic search capabilities
Project Structure
Development Setup
Prerequisites
- Python 3.9+
- pip or poetry
- Redis (optional, for caching)
- Vector database (optional, for RAG)
Installation
API Endpoints
Core Endpoints
GET /health
GET /health
Health check endpointResponse:
POST /api/chat
POST /api/chat
Send a chat message and receive AI responseRequest:Response:
POST /api/search
POST /api/search
Search documents semanticallyRequest:Response:
POST /api/ingest
POST /api/ingest
Ingest documents into the RAG systemRequest: Multipart form data with file uploadsResponse:
Interactive API Documentation
FastAPI automatically generates interactive API documentation:- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
RAG Pipeline
Architecture
Components
- Document Ingestion
- Retrieval
- Reranking
- Generation
Process:
- Document upload via API
- Text extraction (PDF, DOCX, etc.)
- Chunking into manageable pieces
- Embedding generation
- Storage in vector database
- DOCX
- TXT
- MD (Markdown)
- JSON
- CSV
RAG Preflight Testing
Before deploying, run the RAG preflight check to catch issues early:Environment Overrides
What It Tests
Import Checks
Import Checks
- All Python modules import successfully
- No missing dependencies
- Correct Python version
Runtime Checks
Runtime Checks
- API server starts without errors
- Database connections work
- Redis cache is accessible
- Vector database is reachable
Integration Tests
Integration Tests
- Document ingestion pipeline
- Query retrieval
- Reranking functionality
- End-to-end RAG flow
Docker Deployment
Local Development
Use Docker Compose for local development:Production Build
Testing
Running Tests
Test Structure
Configuration
Environment Variables
API Settings
API Settings
Database Settings
Database Settings
Redis Settings
Redis Settings
RAG Settings
RAG Settings
Performance Optimization
Caching
- Redis for query results
- Embedding cache
- Response caching
- Connection pooling
Async Operations
- Async/await throughout
- Non-blocking I/O
- Background tasks
- Parallel processing
Database Optimization
- Connection pooling
- Query optimization
- Index management
- Batch operations
Monitoring
- Prometheus metrics
- Request logging
- Error tracking
- Performance profiling
Troubleshooting
Server Won't Start
Server Won't Start
Problem:
uvicorn fails to startSolution:Import Errors
Import Errors
Problem: Module import failuresSolution:
Database Connection Issues
Database Connection Issues
Problem: Cannot connect to databaseSolution:
RAG Pipeline Failures
RAG Pipeline Failures
Problem: Document ingestion or retrieval failsSolution:
- Run preflight check:
./scripts/preflight_rag.sh - Check vector database is running
- Verify embedding model is downloaded
- Check logs for specific errors
- Test with simple document first