Personal Project — Learning RAG

AI Life & Money Coach
— RAG-Powered Coaching App

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.

TypePersonal Project
PurposeLearning RAG
RoleFull-Stack Developer
StatusCompleted
Next.js 16TypeScriptOpenAISupabasepgvectorTailwind CSS

/context

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.

/solution

A RAG-powered coaching app where every response flows through the same pipeline:

  • 01

    User selects a coach mode that shapes how the AI frames its response

  • 02

    User's active goals are pulled from localStorage and injected as conversation context

  • 03

    The question is embedded via OpenAI text-embedding-3-small (768 dimensions)

  • 04

    pgvector cosine similarity retrieves the top 5 semantically matched knowledge chunks from Supabase

  • 05

    Matched chunks are merged into the system prompt alongside the selected mode instructions

  • 06

    gpt-4o-mini generates a structured response grounded in the retrieved context

  • 07

    Source citations are returned alongside the answer for transparency

  • 08

    Conversation is stored in Supabase for optional journal summarization later

/rag pipeline

01User question
02Embed query
03pgvector search
04Top 5 chunks
05Mode prompt
06gpt-4o-mini
07Structured response

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.

/interactive demo

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.

SELECT COACH MODE
Sample Question

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.

/key features

01

7 Coach Modes

Each mode reshapes the system prompt — from Socratic reframing to concrete action plans — without changing the underlying knowledge base.

02

RAG-Grounded Answers

Every response is anchored in a private markdown knowledge base before the LLM elaborates, keeping answers focused and purposeful.

03

Goal-Aware Context

User goals (money + time) are stored in localStorage and injected into every coaching session automatically.

04

Daily Brief

A morning check-in that generates one insight, one reflection question, and one action step — personalized to active goals and cached for the day.

05

Coaching Journal

Session summaries are saved to Supabase with key insights, commitments, and reflection themes extracted automatically.

06

pgvector Semantic Search

Retrieval uses cosine similarity over 768-dimensional embeddings stored in Supabase, returning the most contextually relevant knowledge chunks.

07

Source Citations

Each AI response includes the knowledge base files it drew from, so users can trace the reasoning back to the source material.

08

Knowledge Base Ingestion

Markdown content is chunked (≤800 chars), embedded, and stored via a CLI script — making the knowledge base easy to extend.

09

Scoped Advice

The coach explicitly declines to give investment, legal, medical, or therapy advice — keeping interactions safe and purposeful.

/technical implementation

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:

01 — Content Authoring

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.

02 — Ingestion (CLI)

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.

03 — Query Embedding

When a user sends a message, the /api/chat route embeds the query with the same embedding model, producing a 768-dimensional vector.

04 — Semantic Retrieval

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.

05 — Prompt Assembly

Retrieved chunks, the selected coach mode instructions, active user goals, and conversation history are assembled into a structured system prompt.

06 — LLM Generation

gpt-4o-mini generates a structured response using the assembled prompt. The mode controls response format — prose, journal exercise, bullet steps, or Socratic questions.

07 — Response + Sources

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.

08 — Journal Summarization

Optionally, conversations can be sent to /api/summarize, which extracts key insights, commitments, and reflection themes and saves a structured entry to Supabase.

/database schema

Four tables in Supabase handle all persistent state — conversations, messages, journal entries, and the embedded knowledge base documents.

conversations
id, title, mode, created_at, updated_at
messages
id, conversation_id, role, content, sources (jsonb), created_at
journal_entries
id, conversation_id, key_insights[], commitments[], reflection_themes[], summary_prose, created_at
documents
id, title, source, topic, content, embedding (vector 768d)

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.

/knowledge base

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.

money/

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.

  • Comparison trapsWhy we benchmark our wealth against others and how that distorts financial decisions
  • The concept of enoughThe hardest financial skill: knowing when to stop chasing more
  • Risk mindsetHow our history with money shapes our risk tolerance in ways we rarely examine
time/

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.

  • Focus and deep workWhy distraction isn't just inefficiency — it's a way of avoiding the difficulty of real work
  • Limits and constraintsWhy accepting what you can't do is more powerful than pretending you can do everything
  • Productivity frameworksWhat conventional time management gets wrong and what actually helps

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.

/outcomes & reflections

  • 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

Want to build something
with RAG or AI?

I build production AI features — RAG pipelines, chat interfaces, knowledge base tooling, and agent workflows. Get in touch to discuss your project.