Overview
Anar Docs AI is a document intelligence platform for processing Arabic and English documents. It provides OCR text extraction, LLM-powered document classification, structured data extraction, and field validation — designed for government document workflows where accuracy and Arabic language support are essential.
Government agencies process thousands of documents daily: Emirates IDs, visa applications, trade licenses, medical records, and legal contracts. Docs AI automates the intake pipeline — extracting text from scanned documents, classifying the document type, pulling out structured fields, and validating completeness.
Processing Pipeline
Documents flow through a five-stage pipeline, each stage building on the output of the previous:
1. Upload
Upload a PDF, image, or DOCX file. The system accepts files up to 50 MB and stores them for processing.
2. OCR
Extract text using the appropriate engine for the file type:
- Images (PNG, JPG, TIFF, BMP) — EasyOCR with Arabic and English language support
- PDFs with native text — PyPDF2 extracts embedded text directly
- DOCX files — python-docx parses document content
- Scanned PDFs — Fallback chain: Azure OCR, EasyOCR, then Tesseract
3. Classify
An LLM analyzes the extracted text and classifies the document into one of five categories: legal, medical, financial, government, or identity. The classifier also identifies a sub-type (e.g., emirates_id, trade_license) and relevant keywords.
4. Extract
An LLM extracts structured data from the document text: key-value fields (names, dates, IDs), tables, and dates. Each extracted field includes a confidence score.
5. Validate
Extracted fields are checked for completeness and format correctness. Missing required fields and format issues are flagged with severity levels.
6. Chat RAG Ingest
Processed documents can be pushed directly to Anar Chat's RAG pipeline. The Docs-to-Chat ingest pipeline sends OCR text as pre-chunked segments to Chat's /rag/ingest endpoint, making scanned documents immediately searchable via Chat's knowledge bases.
OCR Failover Chain
For scanned documents, Docs AI uses a three-tier failover chain: Azure OCR (highest accuracy) then EasyOCR (good Arabic support) then Tesseract (universal fallback). If one engine fails, the next is tried automatically.
Supported Document Types
| Type | Description | Examples |
|---|---|---|
legal | Legal documents | Contracts, agreements, court orders |
medical | Medical records | Prescriptions, lab reports, medical certificates |
financial | Financial documents | Invoices, receipts, financial statements |
government | Government forms | Official letters, permits, applications |
identity | Identity documents | Emirates ID, passports, visas, driving licenses |
Supported File Formats
PDF, PNG, JPG, JPEG, TIFF, BMP, DOCX — maximum 50 MB per file.
Architecture
Docs AI uses a FastAPI backend on port 8008 with a Next.js dashboard on port 3008. The backend consists of four processing engines:
- OCR Engine — EasyOCR for images, PyPDF2 for PDFs, python-docx for DOCX, with LRU caching
- Classifier — LLM-based document type classification via Groq
- Extractor — LLM-based structured data extraction via Groq
- Validator — Rule-based field validation for completeness and format
Quick Start
cd docs-ai/backend
uv sync
uv run uvicorn anar_docs.main:app --reload --port 8008
Process a document:
# Upload
curl -X POST http://localhost:8008/api/v1/docs/upload -F "file=@emirates_id.pdf"
# Run OCR
curl -X POST "http://localhost:8008/api/v1/docs/ocr?document_id=DOC_ID"
# Classify
curl -X POST "http://localhost:8008/api/v1/docs/classify?document_id=DOC_ID"
# Extract fields
curl -X POST "http://localhost:8008/api/v1/docs/extract?document_id=DOC_ID"
# Validate
curl -X POST "http://localhost:8008/api/v1/docs/validate?document_id=DOC_ID"
Dashboard
The Docs AI dashboard provides six views:
- Overview — Upload stats, recent documents, pipeline status
- Documents — Browse and search all processed documents with detail view
- Document Detail — Full document view with OCR pipeline status, extracted fields, and validation results
- OCR — OCR results viewer with text blocks, confidence scores, and pipeline visualization
- Extraction — Extracted fields, tables, and validation results
- Analytics — Document type distribution and processing metrics
Observability
Docs AI is instrumented with OpenTelemetry via anar_shared.setup_otel(). When OTEL_EXPORTER_OTLP_ENDPOINT is set, traces, logs, and metrics are exported to the OTel Collector.
MCP Server
Docs AI exposes a Model Context Protocol server at /mcp via FastApiMCP, enabling AI assistants to upload documents, trigger OCR, classification, and extraction programmatically.
Gateway Integration
When GATEWAY_URL is set, Docs AI routes LLM calls (classification, extraction) through Anar Gateway for unified cost tracking and safety scanning.
Test Suite
210 tests cover OCR engines, classification, extraction, validation, document upload, document detail/delete, Chat RAG ingest pipeline, and API endpoints.
cd docs-ai/backend && uv run pytest
Next Steps
- OCR Pipeline — How the three-tier OCR failover chain works
- Classification — LLM-powered document categorization
- Extraction — Structured data extraction from unstructured documents
- API Reference — Full endpoint documentation