ALL PROJECTS/UOH AI CHATBOT

Overview

The University of Haripur wanted an assistant that could answer student and staff questions about its own material — prospectuses, policies, notices, academic documents — without a person having to answer the same question a hundred times a week. The requirement that shaped everything was that it must answer from the documents, and be able to say where an answer came from.

The result is a retrieval-augmented service built as an API rather than a chat app. Documents are uploaded, split, embedded and indexed; a question retrieves the passages that actually bear on it and a language model composes the answer from those passages alone, carrying the source reference back with it. Around that sits the part that makes it operable: eighteen endpoints for managing the corpus, an admin key on every mutation, a request limiter, and — unusually — the ability to list, edit and delete an individual chunk, so a bad passage can be corrected without re-ingesting the whole document.

It was built in a one-week window in February 2025, with a co-developer, at the request of the university.

Problem

A retrieval assistant over institutional documents has three problems that a demo never surfaces.

The answer has to be traceable. A student told the wrong fee deadline by a confident chatbot is a real institutional problem. It is not enough for the model to be grounded — the answer has to carry the reference back with it, which means the reference has to survive the whole pipeline: the chunk has to remember which document and which section it came from, and that memory has to still be there at generation time.

A vector store alone is not enough to run this. Embeddings are excellent at finding relevant text and useless at answering the operational questions an administrator actually has — what has been uploaded, when, how many chunks did it produce, has this file already been ingested. Those are relational questions. Using one store for both jobs means doing at least one of them badly.

Corpora go stale, and re-ingesting is a blunt instrument. A single wrong or outdated paragraph in a long prospectus should not require deleting and rebuilding the entire document's index — but chunk-level surgery is exactly the thing a naive RAG pipeline makes impossible, because it treats the index as write-once.

System Design

How It Works

01/04
01

A document becomes a searchable corpus

The ingestion path — and the two places it refuses to do the wrong thing.

  1. 1An uploaded document is hashed whole and per page, and rejected if that content is already indexed
  2. 2Text is extracted block by block with page numbers preserved, then normalised
  3. 3The text is split into overlapping windows that end on sentence boundaries
  4. 4Each chunk is embedded and written to the vector collection, with retries so a transient failure does not leave a hole
  5. 5Document identity, chunk count and hashes are recorded on the relational side for operators to reason about
02

A question becomes a grounded answer

The per-request path, and how the reference survives it.

  1. 1The question is embedded and matched against the collection, optionally narrowed to a single document
  2. 2The top five passages are returned with their metadata, and their references collected and deduplicated
  3. 3The passages are combined into a context block and handed to the model with a prompt that fences it to that context
  4. 4The answer is composed at a low temperature and returned with the source reference appended
03

A wrong passage gets fixed

The capability a write-once index cannot offer.

  1. 1An operator lists the chunks for the document in question
  2. 2The offending chunk is edited in place or deleted on its own
  3. 3The rest of the document's index is left untouched — no re-ingestion
  4. 4Reconciliation pushes the declared label vocabulary from the relational store back onto the vector-side chunks
04

The corpus stays administrable

How curating the corpus stays an operational task rather than an engineering one.

  1. 1Every mutating call carries the administrator key, checked before anything is written
  2. 2Documents, categories and chunk metadata are managed through the same API surface
  3. 3A rolling per-minute limiter sits in front of the query path so volume cannot run away
  4. 4The interactive API documentation exposes the authorisation control, so the surface is usable without a separate client

Key Features

  • Document-grounded answers — the model composes from retrieved passages only, at a deliberately low temperature
  • Source references carried end to end, deduplicated and appended to the answer so it can be checked
  • Eighteen endpoints across seven route groups — upload, listing, chunk CRUD, categories, metadata, reconciliation and query
  • Chunk-level editing and deletion, so a wrong passage is a one-call fix rather than a full re-ingestion
  • Duplicate-proof ingestion — whole-file and per-page content hashes under a uniqueness constraint
  • Sentence-aware overlapping chunking, with page numbers preserved through structured extraction
  • Two-store design — a vector collection for retrieval, a relational store for operational metadata — with reconciliation endpoints that realign the vector side to the labels the relational store declares
  • Administrator key on every mutation plus a rolling per-minute request limiter, with the authorisation control surfaced in the API's own interactive docs

Outcomes

  • Delivered a working retrieval assistant for the university in a one-week build, as an API rather than a single chat page, so it could be embedded anywhere
  • Made answers checkable rather than merely grounded — the source reference survives ingestion, retrieval and generation and comes back attached to the answer
  • Made the corpus maintainable: an individual chunk can be listed, corrected or removed without re-ingesting its document
  • Made re-uploading safe by design — content hashing under a uniqueness constraint means the same document cannot be indexed twice
  • Separated retrieval storage from operational storage so neither does the other's job badly, and shipped reconciliation endpoints for the drift that design implies
  • Put an administrator key on every mutation and a rolling limiter in front of the query path, with the authorisation control surfaced in the API's own interactive documentation

More work

MVP100Hours preview
AI GROWTH PLATFORM

MVP100Hours

An AI-powered lead-to-close platform — silent visitor intelligence to autonomous AI voice outreach

VIEW PROJECT