- AI
- Web
- App
- AI Automation
A private AI knowledge platform where every book is its own isolated brain, every citation is checked in code, and an ungrounded answer is refused outright.
- Services
- Artificial Intelligence
- SaaS Development
- Automation
- Technologies
- Next.js
- React
- TypeScript
- Tailwind CSS
- PWA
- Node.js
- +13 more

- What the client needed
- Tools that promise to chat with a folder of documents blend every source into one index and let a language model improvise over the top. An assistant used to make real business decisions needs the opposite behaviour: answer only from a named shelf, show the page the answer came from, and stop when the shelf does not cover the question. The same content also had to work fully in English, Spanish and Portuguese, properly translated and narrated rather than machine-translated on the fly.
- What we built
- Cuaba is a private AI knowledge platform built as a Next.js progressive web app on PostgreSQL and pgvector. Every book in the library is treated as its own isolated retrieval scope, so a question reaches each relevant book separately, each answers from its own pages, and the system synthesises those independent answers into a single recommendation. On the same corpus sits a full reading and listening layer: 30 books, readable and narratable in three languages, alongside personal notes, folders, dossiers and a governed set of approved documents.
- Why it mattered
- A confident fabrication is more damaging than no answer at all when the output informs a decision, so refusal had to be an architectural guarantee rather than an instruction in a prompt. Pooling thirty business books into one index would also have averaged away the contradictions between authors that make a shelf of thirty worth owning. And narrating a corpus of roughly 35 million characters in three languages at commercial API rates prices a single full regeneration between $420 and $5,250 — a figure that recurs, because regeneration is not a one-off event.
At a glance
- 30 books, each independently retrievable
- Citations validated in code, not requested in prompts
- Reading and narration in English, Spanish and Portuguese
- 68 full-book narrations at zero marginal cost
Grounding is usually treated as a prompting problem: ask a model to cite its sources and hope. Cuaba needed grounding to be a property of the architecture, because a knowledge product only has value if it can be trusted to stop. The source material made that harder still, since the books arrived as scanned PDFs carrying the structural damage OCR leaves behind.
- 04
Business constraints
- A confident but fabricated answer is actively dangerous when it is being used to make a real business decision.
- Pooling thirty business books into one vector index produces a bland average and destroys the distinct, often contradictory perspectives that justify owning them.
- The audience reads and listens in three languages, so an English-first product with on-the-fly translation was not acceptable.
- Narration across the corpus at premium voice-provider rates runs comfortably into five figures per full regeneration.
- 04
Technical constraints
- Source books arrived as scanned PDFs with running headers dropped mid-paragraph, page numbers glued to words, broken ligatures and letter-spaced headings.
- Translated editions silently lost their paragraph structure, which then broke chapter detection downstream and fell back to generic part numbers.
- Passages are stored with deliberate overlap, so editing one copy of an overlapping region breaks reassembly and duplicates content.
- A hung vector search would hold a serverless request open until the platform timeout.
- 04
What the old system could not do
- A generic chatbot will always produce something, so none of the available options could be relied on to say that a question is not covered by the library.
- Off-the-shelf retrieval blends every document into one undifferentiated index, which leaves an answer unattributable to the book it came from.
- Commercial narration APIs priced a single full pass between $420 and $5,250, which ruled out regenerating audio as the text improved.
- On-the-fly machine translation produces no cached, readable, narratable Spanish or Portuguese edition of a book.
- 01Discovery
Framing it as knowledge integrity
The work was treated as a knowledge-integrity problem first and an AI problem second. Reviewing how existing document assistants behaved showed that each failed on at least one of five counts: invention, blending, language coverage, dirty source data and narration cost. Those five failures became the constraints the architecture had to satisfy.
- Five failure constraints
- Refusal as a required outcome
- Trilingual scope definition
- 02Technical planning
Isolate rather than blend
Three decisions were fixed before implementation began. Each book keeps its own retrieval scope so answers stay attributable; refusal becomes a first-class outcome enforced by a structured answer format rather than by prompt tuning; and every capability is benchmarked at zero marginal cost before defaulting to the best-known paid vendor for it.
- Per-book retrieval scope
- Structured answer contract
- Zero-cost provider benchmarks
- 03Architecture
One deployment, one type system
Cuaba is a Next.js App Router application deployed serverless, with PostgreSQL and pgvector as the system of record. There is no separate backend service — route handlers are the backend, which keeps one deployment, one language and one type system end to end. Every unit of knowledge, book passage and personal note alike, is stored as a row carrying a 1536-dimension embedding and a JSONB metadata envelope, so one semantic search serves books, notes, folders and dossiers.
- Serverless route-handler backend
- Single-table knowledge model
- HNSW and GIN index plan
- 04Design
A private study, not a dashboard
The visual direction is editorial rather than dashboard-like: a warm, dark, book-lover's palette with serif display type, a generous reading measure and restrained accent colour. The workspace is organised as ten modules behind a persistent left rail, each stating in one line what it is for, with an inline explainer on every screen so the product teaches itself instead of requiring documentation. Both dark and light themes are implemented in full, and the workspace is responsive down to mobile.
- Ten-module workspace
- Editorial reading typography
- Full dark and light theme sets
- 05Build
Pipeline, validator and audio
The knowledge and audio layers were written as pure functions so the risky logic could be unit-tested without infrastructure, with test seams in the retrieval layer to exercise the pipeline without live model calls. The audio pipeline runs text through readability normalisation, SSML sanitisation, sentence-aware chunking, per-chunk synthesis, MP3 assembly and private storage. 206 automated tests across 22 files cover citation validation, grounding rules, verification policy, retrieval routing, chapter detection, text normalisation and audio reassembly.
- Citation validator
- Audio synthesis pipeline
- 206-test suite
- 06Launch & scale
Cleaning a corpus in production
Narration was generated across the library, reaching 68 full-book narrations to date. Corpus repairs ran dry-run first and wrote a rollback file before applying, with automated duplicate detection verifying each run against the overlapping-chunk storage. Delivery was then extended past the browser to an installable PWA with offline reading and offline audio, plus Telegram and WhatsApp interfaces and scheduled email digests.
- 68 generated narrations
- Dry-run and rollback discipline
- Offline and messaging delivery
The grounded answer pipeline
An answer has to survive every stage of a multi-stage retrieval and verification pipeline or it never reaches the reader. Citations are treated as a machine-checkable contract rather than a request made in a prompt.
- Query routing
Each question is classified — canonical policy questions route to the approved-document spine, ordinary questions to the book corpus — and the reply language is detected from the question itself.
- Structured drafting
The model must return discrete answer segments, each carrying explicit source IDs, because free-form prose cannot be checked and is not accepted.
- Whole-draft rejection
A pure, unit-tested validator checks every citation against the sources actually retrieved, and a single unknown or missing citation rejects the entire draft rather than being patched locally.
- Selective verification
A second model call re-checks grounding only where it earns its cost, on high-stakes questions and on retrieved book evidence, while answers resting purely on the approved spine skip it.
Per-book isolation and the OKF layer
Thirty books stay separate instead of being pooled into one index, and a governed document tier sits beside them under different verification rules.
- Isolated retrieval
Vector search retrieves passages per book rather than globally, so each book answers from its own pages and the answer stays attributable to its source.
- Synthesis and vote
With several books answering independently, the system synthesises one recommendation across their competing perspectives instead of averaging those perspectives away beforehand.
- Open Knowledge Format
A governed set of Markdown documents carries structured metadata — authority level, review date, version, language, aliases, keywords and a high-stakes flag — giving the system a tier it can treat as approved truth rather than retrieved text.
- Deterministic spine first
The governed documents are searched lexically before anything else, and a strong match answers immediately without spending an expensive retrieval pass.
Multilingual reading and narration
Every book is readable and listenable in English, Spanish and Portuguese. Each language edition is produced once and stored rather than translated on demand.
- Cached translations
A language edition is generated once, cached and resumable, so a language tab that has been opened before opens instantly.
- Paragraph-preserving chunking
Translation chunks pack whole paragraphs up to a size budget and fall back to sentence splitting only for a single oversized paragraph, which keeps blank lines intact all the way to the model.
- Chapter detection
Longer books are split into navigable chapters using real chapter titles detected from the text in all three languages rather than arbitrary page breaks.
- Composable narration slugs
A slug scheme of the form voice-male__booklang-es__title lets one pipeline serve every combination of book, chapter, passage, language and voice, each cached, shareable and independently addressable.
Cost and reliability engineering
The most expensive component of the platform runs at zero marginal cost, and the failure modes that fail silently were designed for explicitly.
- Zero-cost narration
Narration runs through Microsoft's neural voices over the msedge-tts protocol, the same Azure Neural voice family commercial APIs bill for, so the 68 audiobooks generated to date cost nothing.
- Queue, retry and length checks
Because the free endpoint throttles bursts and drops sockets, synthesis is serialised through a queue, retried up to six times with exponential backoff and validated as non-empty, since a dropped socket produces truncated audio that would otherwise be cached and shared as complete.
- Provider fallback chain
Narration sits behind a provider-agnostic interface with an Edge, Gemini, OpenAI and ElevenLabs chain, so a long generation job survives the primary engine failing mid-run and the platform degrades rather than breaks.
- Fail-closed retrieval
Vector RPC calls carry an explicit 15-second timeout and return fewer or zero passages, a case every caller already handles, rather than hanging a serverless request until platform timeout.
A question passes through routing, the governed spine and per-book retrieval before a validator decides whether it can be answered at all.
- question flows from Browser PWA to Next.js route handlers.
- Data flows from Next.js route handlers to Query router.
- Data flows from Next.js route handlers to Audio pipeline and storage.
- Data flows from Query router to OKF canonical spine.
- per-book search flows from Query router to Per-book vector retrieval.
- Data flows from OKF canonical spine to Drafting and citation validator.
- passages flows from Per-book vector retrieval to Drafting and citation validator.
- Data flows from Drafting and citation validator to Second-pass verification.
- cited answer returns from Second-pass verification to Browser PWA.
- not in library returns from Drafting and citation validator to Browser PWA.
- The response returns from Audio pipeline and storage to Browser PWA.









Narration cost per full regeneration
- Narration cost per full regeneration
- $0
- Against a $420-$5,250 commercial equivalent
- Full-book narrations generated
- 68
- Across English, Spanish and Portuguese
- Automated tests passing
- 206
- Across 22 test files
- Books independently retrievable
- 30
- Each isolated to its own retrieval scope
Alongside the numbers
- The system can decline: when the shelf does not cover a question, the refusal state is enforced in code rather than requested of the model.
- Every citation in an answer is checked against the retrieved sources by a unit-tested validator before the answer is shown.
- Every book can be read and heard in English, Spanish and Portuguese from one corpus.
- The library travels as an installable PWA with offline reading and audio, and answers also arrive through Telegram and WhatsApp.
Frontend
- Next.js
- React
- TypeScript
- Tailwind CSS
- PWA
Backend
- Node.js
- Zod
- Telegram Bot API
- Twilio
AI
- OpenRouter
- OpenAI
- RAG
- Edge Neural TTS
- ElevenLabs
Data
- PostgreSQL
- pgvector
- Supabase
Infrastructure
- Vercel
- Vitest
Tell us the constraint you are trying to remove. A senior engineer reads every enquiry and replies within one business day.