UniSage – AI Academic Assistant (Agentic RAG)

Graduation thesis: an AI assistant that answers students' academic questions from the university documents they are allowed to read, built on an agentic RAG pipeline with guardrails, cost control and observability.

AI & Backend EngineerAug 2026 – Present

Overview

UniSage is an AI academic assistant for university students. Staff upload regulations, curricula and announcements; the system parses, chunks and embeds them into Qdrant. Students ask questions in Vietnamese and receive streamed answers grounded in the documents they are allowed to read, with citations. The AI service is a FastAPI app whose chat flow is an agent graph (intent routing, query rewriting, retrieval, reranking, tool calling and generation). It sits behind an API Gateway, next to a Spring Boot backend that owns users, roles and conversations, and a React web app for students, document ingesters and administrators. Token usage and cost are tracked per request, and requests fail over between LLM providers.

Architecture Design

Microservices: Spring Cloud Gateway in front of a Spring Boot backend and a Python FastAPI AI agent, with a React web app

React Web (Student chat · Ingester · Admin)
↓
API Gateway (Spring Cloud Gateway · JWT)
↓
Spring Boot Backend (users, RBAC, documents, conversations)
FastAPI AI Agent (RAG graph · ingestion)
↓
Qdrant · PostgreSQL · Redis · Celery · MinIO
↓
LLM providers (OpenAI · Gemini · Anthropic) · Tavily web search

Key Features

RAG pipeline for PDF, Word and Excel: parsing, cleaning, chunking, embedding, indexing
Multi-representation indexing: content, summary and sample-question vectors per chunk
AI agent graph: intent routing, query rewriting (HyDE), reranking, tool calling
Answers streamed over SSE with source citations
Document-level access control enforced inside vector search
Prompt injection detection and sensitive data redaction
Multi-LLM failover, rate limiting, token budgets and cost tracking
Structured tracing, logging and Slack alerting

Technical Implementation

Document Ingestion & ETL

  • Uploads PDF, DOCX, XLSX and TXT files to MinIO and previews the parsed result before indexing
  • Table-aware parser rebuilds merged and multi-level table headers so tables stay readable after chunking
  • Several chunking strategies (recursive, token, semantic, markdown, table-row, Excel-row) chosen per document type
  • Chunking and embedding run as background Celery jobs; progress is pushed to the web app over WebSocket

Indexing & Retrieval

  • Each chunk is stored in Qdrant with three named vectors: raw content, LLM summary and generated sample questions
  • Search runs on all three vectors and keeps the best score per chunk, raising recall for short factual questions
  • Permission filters built from the verified JWT are applied inside every vector query, so users never retrieve documents they cannot read
  • Chunk metadata is stored as Qdrant payload with indexes for filtered search

AI Agent Orchestration

  • Chat flow modelled as a Pydantic Graph: message classification → intent routing → query transformation → retrieval → rerank → generation
  • HyDE rewrites follow-up questions into standalone queries; comparison questions are split into sub-queries
  • LLM-as-judge rerank keeps only the chunks that actually answer each sub-query
  • Falls back to web search (Tavily) or a support ticket when no document answers the question
  • Asks a clarification question when required information is missing
  • System prompts are versioned YAML templates assembled by a prompt builder

Safety, Cost & Observability

  • JWT authentication at the API Gateway; the agent only trusts headers injected by the gateway
  • Vietnamese/English prompt injection detection and secret redaction shared by the Python and Java services
  • Model registry with multiple LLM providers, automatic failover, RPM and concurrency limits
  • Token budgets enforced with Redis Lua scripts; usage and cost are reported to the admin dashboard
  • Structured per-node tracing, health checks for every dependency and Slack alerts

Screenshots & Previews

UniSage – AI Academic Assistant (Agentic RAG) – Student chat: streamed answer with source citations
Student chat: streamed answer with source citations
UniSage – AI Academic Assistant (Agentic RAG) – Clarification question when information is missing
Clarification question when information is missing
UniSage – AI Academic Assistant (Agentic RAG) – Upload: category, department and minimum access level per document
Upload: category, department and minimum access level per document
UniSage – AI Academic Assistant (Agentic RAG) – Chunking: choose a strategy, tune token size and overlap, edit chunks
Chunking: choose a strategy, tune token size and overlap, edit chunks
UniSage – AI Academic Assistant (Agentic RAG) – Embedding: background job with real-time progress
Embedding: background job with real-time progress
UniSage – AI Academic Assistant (Agentic RAG) – Indexed chunks of a document
Indexed chunks of a document
UniSage – AI Academic Assistant (Agentic RAG) – Model registry: LLM providers and failover
Model registry: LLM providers and failover
UniSage – AI Academic Assistant (Agentic RAG) – Token usage and cost management
Token usage and cost management
UniSage – AI Academic Assistant (Agentic RAG) – Role management
Role management
UniSage – AI Academic Assistant (Agentic RAG) – Permission management
Permission management

Technologies Used

PythonFastAPIpydantic-aiPydantic GraphQdrantPostgreSQLRedisCeleryMinIOSpring BootSpring Cloud GatewayReactTypeScriptDocker

System Pattern

Microservices: Spring Cloud Gateway in front of a Spring Boot backend and a Python FastAPI AI agent, with a React web app