A personal project built to learn RAG end-to-end. The knowledge base is distilled directly from two books — The Psychology of Money by Morgan Housel and Four Thousand Weeks by Oliver Burkeman — and every AI response is grounded in those sources before gpt-4o-mini elaborates. Seven coaching modes, goal-aware context, a daily brief, and a Supabase-backed journal.
This is a personal testing project. The goal was to learn how RAG (Retrieval-Augmented Generation) actually works in practice — not just the concept, but the full pipeline: chunking content, generating embeddings, storing them in a vector database, doing semantic retrieval at query time, and assembling it all into a prompt before the LLM responds.
To make it worth building, I wanted a knowledge base that was specific and meaningful rather than generic filler. I chose two books I'd already read and found genuinely useful: The Psychology of Money by Morgan Housel and Four Thousand Weeks by Oliver Burkeman. The markdown files in the knowledge base are distilled from the ideas in those books — not copied verbatim, but summarized and structured in a way that the retrieval pipeline can surface them as relevant context when a user asks a question.
The coaching framing — money mindset, time management, intentional living — comes naturally from those two books. Housel's work is about how people actually think and behave around money, not just how they should. Burkeman's is about the finitude of time and why most productivity advice misses the point. Together they cover the two things most people want to think more clearly about.
A RAG-powered coaching app where every response flows through the same pipeline:
User selects a coach mode that shapes how the AI frames its response
User's active goals are pulled from localStorage and injected as conversation context
The question is embedded via OpenAI text-embedding-3-small (768 dimensions)
pgvector cosine similarity retrieves the top 5 semantically matched knowledge chunks from Supabase
Matched chunks are merged into the system prompt alongside the selected mode instructions
gpt-4o-mini generates a structured response grounded in the retrieved context
Source citations are returned alongside the answer for transparency
Conversation is stored in Supabase for optional journal summarization later
The pipeline runs on every message. Embeddings are computed with text-embedding-3-small at 768 dimensions, and retrieval uses a pgvector cosine similarity RPC in Supabase.
Select a coach mode, then submit a sample question to see how the AI response changes. This uses static pre-generated output — no API calls are made.
“I feel like I'm always busy but never making progress.”
Switch modes to see how the same knowledge base produces a different style of response. Real responses include citations from actual knowledge base chunks.
Each mode reshapes the system prompt — from Socratic reframing to concrete action plans — without changing the underlying knowledge base.
Every response is anchored in a private markdown knowledge base before the LLM elaborates, keeping answers focused and purposeful.
User goals (money + time) are stored in localStorage and injected into every coaching session automatically.
A morning check-in that generates one insight, one reflection question, and one action step — personalized to active goals and cached for the day.
Session summaries are saved to Supabase with key insights, commitments, and reflection themes extracted automatically.
Retrieval uses cosine similarity over 768-dimensional embeddings stored in Supabase, returning the most contextually relevant knowledge chunks.
Each AI response includes the knowledge base files it drew from, so users can trace the reasoning back to the source material.
Markdown content is chunked (≤800 chars), embedded, and stored via a CLI script — making the knowledge base easy to extend.
The coach explicitly declines to give investment, legal, medical, or therapy advice — keeping interactions safe and purposeful.
The app runs on Next.js 16 App Router. Each API route handles one concern — chat, conversations, daily brief, journal, and summarization. Here's how each stage of the pipeline is implemented:
Knowledge base content lives as markdown files organized by topic prefix (money-*, time-*) in /content/. Authors write in plain markdown; the pipeline handles the rest.
npm run ingest runs scripts/ingest.ts, which reads each markdown file, splits it into paragraph-level chunks of ≤800 characters, embeds each chunk with text-embedding-3-small (768 dims), and upserts them into the Supabase documents table.
When a user sends a message, the /api/chat route embeds the query with the same embedding model, producing a 768-dimensional vector.
The embedded query is passed to a match_documents Supabase RPC that runs a pgvector cosine similarity search, returning the top 5 most relevant chunks.
Retrieved chunks, the selected coach mode instructions, active user goals, and conversation history are assembled into a structured system prompt.
gpt-4o-mini generates a structured response using the assembled prompt. The mode controls response format — prose, journal exercise, bullet steps, or Socratic questions.
The API returns the AI response alongside source citations (file titles and topics) so the UI can display which knowledge base files informed the answer.
Optionally, conversations can be sent to /api/summarize, which extracts key insights, commitments, and reflection themes and saves a structured entry to Supabase.
Four tables in Supabase handle all persistent state — conversations, messages, journal entries, and the embedded knowledge base documents.
The documents table stores 768-dimensional embedding vectors alongside each chunk. Retrieval is handled by a Supabase RPC (match_documents) using pgvector's <=> cosine distance operator.
All six knowledge base files are distilled from two books. The content is not copied — it's restructured into markdown summaries that the retrieval pipeline can chunk and index effectively.
The Psychology of Money
Morgan Housel
How people actually think and behave around money — not how they should. Housel argues that financial success is less about intelligence and more about behavior, patience, and understanding your own relationship with money.
Four Thousand Weeks
Oliver Burkeman
A reckoning with human finitude. The average life is about 4,000 weeks. Burkeman argues that most productivity advice avoids this reality, and that confronting it directly is the only way to make intentional choices about time.
Each file is split into paragraph-level chunks of ≤800 characters by the ingestion script, embedded with text-embedding-3-small, and stored in Supabase. At query time, the top 5 most semantically similar chunks are retrieved and injected into the prompt as grounding context.
Coaching stays grounded — RAG prevents the LLM from drifting into generic self-help platitudes
Responses feel tailored — goals context makes every conversation aware of what the user is actually working toward
Seven distinct interaction styles from one knowledge base — coach modes eliminate the need for multiple specialized tools
Daily brief creates a consistent touchpoint — one insight, one question, one action step every morning
Journal entries surface patterns over time — themes and commitments accumulate into a personal reflection record
Source citations build trust — users can see exactly which knowledge base content informed each response
I build production AI features — RAG pipelines, chat interfaces, knowledge base tooling, and agent workflows. Get in touch to discuss your project.