Work
AI Knowledge Base & Sandboxed Document Agent
An on-premise AI knowledge base and writing platform built on LightRAG, featuring a Docker-sandboxed Document Agent, AI-marked template library, and ONLYOFFICE editing.
Overview
An on-premise AI knowledge base and intelligent document platform delivered through deep customization of LightRAG. Beyond document ingestion, knowledge graph exploration, document categorization, and persistent multi-session retrieval, it provides an end-to-end writing workflow for enterprise documents: the assistant searches the knowledge base, streams drafts, generates Word/Excel/PPT/PDF/Markdown files, and runs a durable Document Agent inside isolated Docker containers with structural, semantic, and VLM visual verification before delivery. It also includes an AI-marked Word template library and LAN ONLYOFFICE preview and editing with conflict detection and immutable version snapshots.
System architecture
On-premise knowledge base and Document Agent architecture built on LightRAG, uniting Docker-sandboxed execution, three-layer verification, the AI template library, and ONLYOFFICE editing.
Problem
Open-source knowledge bases usually stop at document Q&A and cannot directly support drafting or revising formal enterprise documents such as policies, contracts, and reports. Earlier fixed-tool writing agents struggled with rich Word layouts—breaking headers, images, and tables—and tied long-running jobs to a single HTTP stream that broke on page refresh.
My role
I owned the full-stack design and implementation: on the frontend (React 19, Vite 8, TypeScript, Tailwind CSS 4), I delivered the AI Knowledge Base rebrand, server-backed retrieval history, document categories, writing workspace, live activity stream, AI template marking review screen, and ONLYOFFICE integration; on the backend (Python FastAPI), I built the writing agent, SQLite durable run runtime, Docker sandbox executor, feature-flagged format registry, three-layer verification pipeline, and atomic file stores.
Solution
Built on LightRAG's hybrid graph-and-vector retrieval, the system pairs a streaming writing assistant with a durable Document Agent and an AI Word template library. Routine drafting uses NDJSON streaming with interactive choice cards. Complex document tasks enter the Document Agent, where SQLite persists runs and sequenced events while the model loads versioned Word, Excel, or PDF skills and executes scripts inside a non-root, network-disabled, read-only Docker container. Before publishing, candidates pass OOXML structural checks, read-back semantic checks, and VLM visual inspection of rendered PDF pages bound to SHA-256 hashes (up to three repair rounds), followed by ONLYOFFICE baseline verification that saves conflict copies instead of overwriting human edits. For templates, the LLM suggests variable spans across windowed text, humans confirm them, and a plain single-pass run-level filler substitutes {{key}} placeholders while preserving formatting byte for byte.
Outcome
Turned an open-source RAG engine into a complete enterprise knowledge and document workbench—spanning ingestion, graph search, AI drafting, sandboxed revision, template filling, and collaborative editing—cutting layout rework while preserving on-premise security and auditability.
Technical highlights
- Docker-sandboxed Document Agent: non-root, no network, read-only rootfs, and strict resource caps with zero host fallback
- Durable run runtime: SQLite-persisted tasks, leases, sequenced event replay, and idempotent creation across disconnects
- Three-layer verification gate: structural OOXML, read-back semantic, and per-page VLM visual checks bound to SHA-256 with bounded auto-repair
- ONLYOFFICE conflict protection: forced pre-edit baseline capture, pre-publish comparison, conflict copies, and immutable snapshots
- AI Word template library: windowed LLM field detection, human review UI, and evaluation-free single-pass run-level substitution
- Feature-flagged format registry: Word enabled by default, Excel (with LibreOffice formula recalculation) and PDF gated by env flags and mirrored to the UI
- Resilient storage contracts: atomic file writes, corruption refusal, killable PDF worker processes, and race-safe conditional orphan cleanup
- Automated test discipline: 2,000+ backend and frontend tests pinning contracts, concurrency edge cases, and regressions
Lessons
Production document agents depend on separating model judgment from deterministic infrastructure: let the model pick what to read and how to edit, while the service enforces sandbox boundaries, durable events, evidence-backed checks, and immutable snapshots instead of trusting a model that claims a task is done.