All success stories
AI Knowledge Base · Retrieval with Citations

A Google Drive folder that answers questions, with a citation on every claim

Small teams keep what they know in a Drive that grew by accident: proposals, contracts, SOPs and spreadsheets in folders named by whoever made them, often in two or three versions of the same document. Generic AI chat cannot see any of it, invents an answer when it is unsure, never says where the answer came from, and has no idea the 2025 policy was replaced by the 2026 one.

In-house build · empty repo to deployed system in one day

The challenge

The problem

Everyone wants to “chat with our documents.” The hard part is not getting an answer, it is trusting one. Before writing any code we read 51 premium Upwork build jobs for exactly this system, and the four things clients complained about were always the same four. Each one became a feature.

  • Hallucination

    A confident answer with no basis in the documents. Every claim now carries a citation, and the application checks it in code before the answer is displayed.

  • No provenance

    “Your holiday allowance is 25 days,” with no source. Each citation now resolves to a chunk, a document, a heading, a page and a Drive link you can open.

  • Stale versions

    Quoting the superseded 2025 policy. The classifier labels documents current or obsolete from their dates and filenames, and the agent has to say which one it used.

  • Silent failure

    A scanned PDF with no text layer gets skipped, or worse, indexed as empty. It now goes to a human review queue with the reason attached.

Two of those requirements were named more often than citations were: a human approval gate, and a way to measure accuracy. So the review queue and the eval set are core to this build, not extras bolted on at the end.

How we built it

The build

Share one folder with a service account, read-only. Within an hour you can browse a map of what is inside it and ask it questions from three different places. The design rule was that every layer has one job and never does another layer’s.

  • Citations checked in code: the model is asked to cite; the application decides whether the citation is real. Every marker must resolve to a retrieved chunk, and every number in the answer must appear in a cited passage or be the sum of two that do.
  • One answer function: the web chat, the Slack command and the MCP server all call the same entry point, so retrieval, validation and logging can never drift between surfaces.
  • Hybrid search in one SQL function: keyword ranking and vector ranking over the same candidates, fused by rank position rather than by blending incompatible scores. One index, one round trip, filters applied before ranking.
  • A human gate that suspends the pipeline: an unreadable file or a low-confidence classification pauses the workflow in the database. A person approves or declines, and that decision resumes the exact run.
  • Thirty golden questions in the repo: recall, faithfulness and refusal accuracy measured on every change and stored per commit, so a regression shows up as a number rather than as a complaint.
  • Automation kept replaceable: the scheduler triggers and delivers. It never parses a document or writes a prompt, so all the judgment stays in version-controlled code that can be tested.

See it in action

A walk through six screens of the running system. It advances on its own, or step through it yourself. SpaceShelf is our own build, indexed against a synthetic 44-file corpus for a fictional studio, which is why every number on this page can be published as measured.

spaceshelf.vercel.app

One Drive folder.
Every answer cited.

Share a folder with SpaceShelf and browse a map of what is in it, ask questions here, in Slack, or from Claude, and get answers that point at the file and section they came from. When the documents do not cover a question, it says so.

Ask a questionBrowse the atlas

The system

Left to right. n8n triggers, the app on Vercel owns the routes and the human step, Mastra owns the workflows and the agent, and three surfaces share one knowledge base.

Google Drive

One shared folder

Docs, Sheets, Slides, PDF, Word, Excel. Shared read-only with a service account.

Drive API v3

n8n

W1 Nightly sync

Schedule trigger. Calls POST /api/sync with the shared secret.

W2 Slack /ask

Slash command trigger. Posts the cited answer back.

W4 Error sentinel

Error workflow of every other workflow.

Slack alerts

App on Vercel

POST /api/sync

Checks X-Run-Secret, starts the ingest workflow, records a run.

Review queue

human

Uncertain classifications wait for a person.

POST /api/chat

Streams the validated answer with citations resolved to Drive links.

POST /api/mcp

The same tools over MCP, bearer token.

Mastra

ingest workflow

List, fetch, parse, classify, chunk, embed, index. Idempotent by file id and version.

Haiku: doc cardOpenAI embeddings

taxonomy workflow

suspends

Builds the tree from the doc cards.

shelf agent

browse_tree, search_chunks, read_document. Refuses when the shelf does not cover it.

Sonnet: answerhybrid_search()

Surfaces

Web chat and Atlas

This app.

Slack /ask

n8n forwards the question, posts the cited answer.

Claude Code, MCP clients

Add the server URL, ask about the folder.

Step 01 / 06

Five layers, and none of them do each other's job

  • n8n is the hands, not the brain: it triggers the nightly sync and delivers Slack answers, and never parses a document or writes a prompt
  • The app owns auth, the routes machines call, and the citation check that runs before anything renders
  • Mastra owns the ingest and taxonomy workflows, the answering agent and its three tools
  • Web chat, Slack and MCP are three doors into one answer function, so they cannot drift apart

Results

100% faithful

Every answer in the 30-question golden set passed the citation check with the entailment judge on

95.8% recall@5

The expected file appears among the documents of the top five retrieved chunks

$0.026 / question

Median cost with the judge running; a full re-index of the corpus costs under $0.20

3 surfaces, 1 path

Web chat, Slack and MCP all call one validated answer function, so a fix lands everywhere at once

44 files, 43 indexed and one held for review. 220 chunks. A full ingest takes 200 seconds; a nightly sync with nothing changed makes zero model calls. Median question latency 6.2 seconds.

Why it matters

Anyone can wire a chatbot to a folder in an afternoon. The work is in the parts that decide whether you can act on the answer: a citation the software has verified, a refusal when the documents are silent, a human gate on the files a classifier cannot read, and a score that tells you whether last week’s change made it worse. We build systems like this one, and you own the source code.

If your answers live in a folder nobody can search

Drive, SharePoint, a shared network folder, a decade of PDFs. We can turn it into something your team can ask, with a source on every answer.