Technical Architecture
Aceh Agentic RAG + OCR is a self-hosted backend platform for Pemerintah Aceh. It retrieves and answers questions in Bahasa Indonesia and English over government sources from JDIH, OpenData, PPID, SatuData and BPS — 44,443 catalogued, of which 35,271 are documents queued for ingestion (the catalogue, not the index; production holds 260 documents — firstmate production audit 2026-10-07) — and is built to the TOR's requirement of indexing and searching 100,000+ documents. Data and inference stay inside Huawei Cloud.
System Goals
- Serve 10-50 internal concurrent users through HTTP JSON APIs and Server-Sent Events streaming.
- Support Agentic RAG over PDFs, Word files, spreadsheets, scanned images, TXT, and related government document formats.
- Keep all data sovereignty requirements intact by using self-hosted components only.
- Attach source citations to every query answer and run a faithfulness check before returning it.
- Apply the Government Policy Guard on every query-answer output; authenticated raw
/generateis the explicit exception.
Core Stack
| Layer | Technology | Purpose |
|---|---|---|
| API | FastAPI | Async HTTP JSON API, SSE query streaming, auth, rate limiting, sessions, validation |
| Model client | LiteLLM | OpenAI-compatible model calls, retries, fallback routing, tracing hooks |
| Orchestration | Custom Python + Pydantic | Router, Planner, Executor, Synthesizer pipeline |
| Model serving | vLLM | Self-hosted LLM, embedding, and reranker endpoints |
| Retrieval store | PostgreSQL + pgvector + full-text search | HNSW semantic retrieval plus lexical keyword retrieval |
| Prompt and observability | Langfuse | Prompt versioning, traces, eval datasets, LLM-as-judge workflows |
| Async ingestion | Kafka | Document-processing event queue |
| Cache | Redis | Session and LLM response cache |
| Cloud platform | Huawei Cloud | APIG, CCE/ECS, RDS, OBS, DCS, DMS, VPC, SWR |
Request Flow
The Router classifies intent, the Planner decomposes complex questions, the Executor calls retrieval and analysis tools, and the Synthesizer returns a cited answer after faithfulness and policy checks.
Retrieval Architecture
Hybrid retrieval is the default path. Semantic retrieval uses pgvector HNSW over chunk embeddings, lexical keyword retrieval uses PostgreSQL full-text search, and RRF fuses both rankings before the reranker re-scores top candidates.
Every final answer must cite the source chunks it uses. Unsupported claims are hallucinations and fail the faithfulness gate.
OCR and Ingestion Architecture
Documents enter through the ingestion pipeline, are stored in OBS, parsed by type, chunked, embedded, and indexed in PostgreSQL. Scanned or image-heavy documents route through OCR before indexing.
OCR confidence is mandatory metadata. Below-threshold extraction must route to human review rather than being silently accepted into the index.
Deployment Footprint
Production separates application, RAG data, model serving, cache, queue, and object storage concerns:
The production topology owns the deployed host and service allocation. The procurement baseline records the required capacity, separately from deployed state.
See the audited production snapshot for the deployed ref, runtime settings, corpus inventory, and pending deployments.
Operational Guardrails
- No external SaaS or data egress for delivered inference and document handling.
- OSI-licensed open-source components only.
- Prompt contracts remain in reviewed files/code and require a deploy. Only
agent-editorialmay be Langfuse-managed under ADR-0006; production prompt management remains off, independently of tracing being on. - OCR model/version changes require revalidation because confidence scores can drift.
- Context-window overflow must be handled explicitly; silent truncation is not acceptable.
- Ingested documents are untrusted input, so prompt hygiene and the Government Policy Guard are mandatory.