Purpose
Thedocument-api is the knowledge backend for the Rapida platform. It ingests documents (PDF, Word, CSV, and others), splits them into chunks, generates vector embeddings, and indexes everything in OpenSearch. At call time, assistant-api queries this service to inject relevant context into the LLM prompt.
Port
9010 — HTTP (FastAPI / uvicorn)Language
Python 3.11+
FastAPI + Celery
Storage
PostgreSQL
assistant_db
Redis (Celery broker)
OpenSearch (vectors + text)Document processing is asynchronous. Upload returns immediately with
status: processing. Text extraction, chunking, and embedding generation run as Celery background tasks.Document Processing Pipeline
Supported File Formats
| Format | Library | What is Extracted |
|---|---|---|
| PyPDF2, pdfplumber | Text content + metadata | |
| Word (.docx) | python-docx | Text + paragraph structure |
| Excel (.xlsx) | openpyxl, pandas | Cell values as text |
| CSV | pandas | Row data as text |
| Markdown (.md) | built-in | Text preserving structure |
| HTML | BeautifulSoup | Cleaned text from HTML |
| Plain text (.txt) | built-in | Direct read |
| Images | pytesseract (OCR) | OCR-extracted text |
Semantic Search
At call time,assistant-api sends a text query to document-api. The service performs vector similarity search and returns the top-k most relevant chunks.
Request:
Embedding Models
Embeddings are generated using sentence-transformers. The model is configurable viaEMBEDDINGS_MODEL in config.yaml:
| Model | Dimensions | Notes |
|---|---|---|
all-MiniLM-L6-v2 | 384 | Default — ~80 MB, fast |
all-mpnet-base-v2 | 768 | Higher quality, larger |
all-MiniLM-L12-v2 | 384 | Lighter variant of L6 |
multilingual-e5-base | 768 | 100+ languages |
If you change
EMBEDDINGS_MODEL, you must also update EMBEDDINGS_DIMENSION to match and re-index all existing documents. Existing embeddings stored with a different dimension will not match.Running
- Docker Compose
- From Source
Health Endpoints
| Endpoint | Purpose |
|---|---|
GET /readiness/ | Service ready |
GET /healthz/ | Liveness probe |
Troubleshooting
Document stuck in 'processing' status
Document stuck in 'processing' status
The Celery worker is likely not running.
Embedding generation is slow
Embedding generation is slow
Adjust the Celery worker batch size:
OpenSearch index errors
OpenSearch index errors
High memory usage
High memory usage