Skip to contenttriettran

Aderra

A self-hosted alternative to pasting internal documents into a hosted chatbot. It runs on servers we control.

  • Next.js
  • FastAPI
  • Kubernetes
  • Azure

In short

Aderra answers questions about a company's own documents and shows which one each answer came from. A company can have thousands of contracts and meeting notes, and people just want to ask in plain language. Sending that content to a hosted AI service wasn't an option for us, so it runs on servers we control.

What I did

Mostly I got it into production. That is three GitHub Actions workflows that build container images on self-hosted ARM machines and push them to Azure's registry, plus four Kubernetes config files.

On the backend I added search over audio: a new `audio_transcription.py` module, a database column for the transcript, and changes to the background worker and indexer so the text reaches the search index.

How it works

Aderra pulls documents from systems like Slack and Google Drive, splits them into passages, and turns each passage into a vector so a question matches on meaning rather than keywords.

Someone drops a file into a project and the upload returns immediately. In the background the text is extracted, split up and indexed. Later, a question finds the most relevant passages, passes them to a language model as context, and the answer streams back a few words at a time with links to the source files.

Four processes, one job each

A Next.js web app owns the interface. A FastAPI service owns requests and streams chat answers as server-sent events, a one-way flow of JSON chunks over a single HTTP connection. A worker pool takes anything slow, so a ten minute transcription never happens inside a web request. The embedding models run in a fourth process with their own container image.

Postgres holds metadata about users and files, Vespa holds the search index and its vectors, and MinIO, an S3-compatible store, holds the original uploads.

Turning audio into text

Azure's speech service has two ways to transcribe, and they behave differently. The quick endpoint answers in one request but handles only about 15 seconds of audio. The batch endpoint copes with long recordings but must fetch the audio from a public URL, and our files live in storage inside a private cluster.

So the code branches on file size at 256 KB, a conservative stand-in for 15 seconds that holds for both uncompressed WAV and 128 kbps MP3. Larger files are written under a temporary key and shared with Azure through a link that expires after 3600 seconds. The job is polled every 5 seconds and stopped at 600, so a job that never finishes can't hold a worker forever, and the temp file is cleaned up on every exit, failures included.

Keeping answers streaming

Every layer between the model and the browser would rather gather the whole response and send it in one lump, which turns a live answer into a blank screen and then a wall of text. Three separate layers did exactly that to us.

I switched buffering off explicitly at the cluster's entry point, raised the read timeout to 300 seconds so long answers aren't cut off mid-sentence, and tagged streaming responses with headers telling proxies not to hold them. The web app also stopped routing chat through its own server and now calls the API directly. Getting the CDN to cooperate took five commits.

What stuck with me

Neither audio nor streaming was hard inside a single service. They broke where systems met: a private cluster and a public endpoint, and three proxies each deciding to buffer. Small changes there, an expiring link and a buffering switch turned off, were what made the product usable.