π A production-ready RAG-based AI system that enables users to store, retrieve, and query personal knowledge using semantic search and LLMs.
π Live Demo: https://ai-second-brain-beige.vercel.app/
| Feature | Description |
|---|---|
| π Authentication | Email/password sign-up & login via Supabase Auth |
| π Add + Edit Memories | Create, update, and delete memories with automatic re-embedding |
| π·οΈ Tagging | Add tags to memories and filter your notes by tag/search |
| π Vector Search | Semantic retrieval using HuggingFace embeddings + pgvector cosine similarity |
| π€ RAG Q&A | Ask questions and get answers constrained to your stored notes |
| π Source Evidence | Answers include source notes and evidence snippets with term highlighting |
| π Question History | Recent queries are saved locally with one-click rerun |
| π€ Multi-user Isolation | RLS policies ensure each user only accesses their own memories |
| π‘οΈ Provider Resilience | OpenRouter model fallback + graceful provider-down response behavior |
User -> Next.js Frontend (React)
|
+-- POST /api/memories
| -> HuggingFace embedding (BAAI/bge-small-en-v1.5)
| -> Supabase insert/update (content + tags + vector)
|
+-- POST /api/query
-> Question embedding (HuggingFace)
-> Supabase RPC: match_memories
-> Prompt assembly with retrieved notes
-> OpenRouter LLM completion (fallback model order)
-> Answer + cited sources + evidence snippets
| Layer | Technology |
|---|---|
| Frontend | Next.js 14 (App Router), React 18, Tailwind CSS |
| Backend | Next.js API Routes |
| Auth | Supabase Auth (email/password) |
| Database | Supabase PostgreSQL |
| Vector Store | Supabase pgvector (cosine similarity) |
| Embeddings | HuggingFace BAAI/bge-small-en-v1.5 (384 dims) |
| LLM Gateway | OpenRouter |
| Deployment | Vercel |
Table: public.memories
βββββββββββββββ¬βββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββ
β Column β Type β Notes β
βββββββββββββββΌβββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββ€
β id β uuid β Primary key (gen_random_uuid) β
β user_id β uuid β FK -> auth.users (CASCADE DELETE) β
β title β text β Optional memory title β
β content β text β Full note content β
β tags β text[] β Optional tags (default '{}') β
β embedding β vector(384) β HuggingFace embedding output β
β created_at β timestamptz β Auto-set on insert β
βββββββββββββββ΄βββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββ- Node.js 18+ and npm
- A Supabase project (free tier works)
- An OpenRouter API key
- A HuggingFace API token
git clone https://github.com/kudala-bharani/ai-second-brain.git
cd ai-second-brain
npm installCopy .env.local.example to .env.local and set:
NEXT_PUBLIC_SUPABASE_URL=https://your-project-ref.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-supabase-anon-key
OPENROUTER_API_KEY=sk-or-v1-your-openrouter-key
HUGGINGFACE_API_KEY=hf_your_token
NEXT_PUBLIC_APP_URL=http://localhost:3000Where to get them:
| Variable | Location |
|---|---|
NEXT_PUBLIC_SUPABASE_URL |
Supabase Dashboard -> Project Settings -> API |
NEXT_PUBLIC_SUPABASE_ANON_KEY |
Supabase Dashboard -> Project Settings -> API (anon key) |
OPENROUTER_API_KEY |
openrouter.ai/keys |
HUGGINGFACE_API_KEY |
huggingface.co/settings/tokens |
In Supabase SQL editor, run:
supabase/schema.sqlsupabase/migration_feature_upgrade.sql(required for latest memory editing/tags/security updates)
migration_feature_upgrade.sql includes:
tagscolumn onmemoriesUPDATERLS policy for own memories- Hardened
match_memories(bound toauth.uid())
npm run dev1. User enters title/content/tags
2. API embeds title+content with HuggingFace model
3. API writes memory + embedding + tags to Supabase
4. UI refreshes memory list
1. User submits question
2. API embeds the question
3. Supabase RPC returns top semantic matches
4. API builds grounded prompt from matched notes
5. OpenRouter generates answer (with fallback model order)
6. API returns answer + related source notes + evidence snippets
- Embedding dimension must remain 384 unless you migrate schema + RPC.
- Query history/settings are currently stored in browser localStorage.
- Free model availability can vary; fallback behavior is built in.
| Route | Purpose |
|---|---|
GET /api/test-embedding |
Quick provider diagnostics in development |
GET /api/memories |
Fetch user memories |
POST /api/memories |
Create memory (title/content/tags) |
PATCH /api/memories/:id |
Edit memory + re-embed |
DELETE /api/memories/:id |
Delete memory |
POST /api/query |
Ask grounded question |
Set these environment variables in Vercel project settings:
NEXT_PUBLIC_SUPABASE_URLNEXT_PUBLIC_SUPABASE_ANON_KEYOPENROUTER_API_KEYHUGGINGFACE_API_KEYNEXT_PUBLIC_APP_URL
After deploying to Vercel, you need to configure Supabase email verification to work with your production domain.
-
Get your Vercel URL (e.g.,
https://your-app-name.vercel.app) -
Update Supabase Dashboard:
- Go to Authentication β URL Configuration
- Set Site URL to your production URL
- Add to Redirect URLs:
http://localhost:3000/auth/callback https://your-app-name.vercel.app/auth/callback
-
Update Vercel Environment Variable:
- Add
NEXT_PUBLIC_APP_URL=https://your-app-name.vercel.app
- Add
-
Test: Sign up with a new email and verify the link redirects correctly
π Detailed guide: See SUPABASE_EMAIL_SETUP.md for complete instructions, troubleshooting, and multi-environment setup.
- RLS on
memoriesenforces per-user data isolation - Server-side user checks in API routes via
supabase.auth.getUser() - Provider keys remain server-side
.env.localis gitignored and should never be committed
MIT