João GabrielSoftware engineer
Backend engineering & applied AI
All work

Applied AI · Research tool

Pensieve

A research archive that compares retrieval-augmented generation with full-context prompting, with every answer linked to its sources.

Scope
Full-stack engineering & interaction
Built with
Next.js, FastAPI, pgvector, Gemini
See verified results & limits
Pensieve’s candlelit archive with a stone basin, books, and the entrance to the research desk.
Applied AI · Research tool / Independent project
Open full-size image

The problem

An AI-generated answer is only useful if you can check it. Pensieve makes two approaches to asking questions of a literary corpus visible: retrieving relevant passages, or sending a larger context directly to the model.

The interface is an archive. A question opens two reading tomes, one for each method. Citations bring the reader back to the exact supplied passage, while a quiet reading mode keeps the evidence in focus.

Engineering decisions

01

Keep the source attached

PostgreSQL and pgvector connect indexed passages to persisted runs. Citation ranges are checked against the supplied text, followed by a second semantic review.

02

Make the comparison inspectable

RAG and Full Context have separate results, latency, token usage, and estimated costs. Accounting estimates stay distinct from proof of an actual charge.

03

Keep the theatre optional

A WebGL archive introduces the work. The research desk stays in the DOM, with keyboard access, reduced motion, and a path to skip the animation.

What shipped

A working Next.js, FastAPI, and pgvector stack with live Gemini integration and a separately labelled demonstration mode. Corpus access and provider quotas limit the live experiments; the repository records those boundaries.

Read the source

What the experiment actually showed.

A real Gemini run exposed citation failures and provider limits. Those findings changed how the application retrieves evidence, reviews answers, and handles large requests.

chapters in the corpus
57
pages of source text
914
indexed passages
738

Exact quotations need more than a prompt

The model changed or combined free-form quotations. It now selects passage IDs, and the backend resolves the exact source text and position. A second semantic review checks each factual claim against its cited passages.

Large Full Context requests hit a real boundary

Six attempts across one-, two-, and three-book scopes all failed with HTTP 503 or 429. The current interface counts input tokens before generation and rejects Full Context requests above 30,000 tokens without silently truncating the source.

RAG retrieval needed balance across books

Early summaries overrepresented some books. Retrieval now combines candidates per book and expands neighbouring passages. The report records both the failures and the resulting corrections.

This run does not establish that RAG is better than Full Context: all six large Full Context attempts failed before producing an answer. Model-based review is a check, not a guarantee of correctness. Private source texts and session records are not published.

Next projectObservador de Concursos