Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Merlin

An AI study assistant for online courses. Teachers upload their course material, and students get a tutor that answers from those documents and turns them into flashcards, practice exams, and summaries.

Why I built it

Most course platforms hand students a pile of PDFs and stop there. The useful parts, a clear definition or the one paragraph that actually answers your question, stay buried, and a generic chatbot is worse than nothing because it invents answers it never read.

Merlin is scoped to a single course's documents. When a student asks something, the answer comes from the uploaded material, and it can show which passages it used. When it generates a practice exam or a set of flashcards, it pulls the real details straight from the source.

What it does

  • Directors and teachers create courses, upload documents, and invite students with a link
  • Students chat with an assistant that only knows the course material
  • Automatic study artifacts: flashcards, practice exams, summaries
  • A PDF viewer that highlights the passage an answer came from
  • Role-based access for directors, teachers, and students

How it works

Every document goes through a pipeline before anyone can ask about it:

flowchart LR
  U[Upload] --> C[Chunk] --> E[Embed on Modal] --> P[(Pinecone)]
  Q[Question] --> R[Retrieve chunks]
  P -. retrieval .-> R
  R --> N[Enrich context] --> G[Gemma on Modal] --> A[Answer or artifact]
Loading

Both the language model and the embedding model run on Modal as on-demand GPU functions (Gemma for generation and for embeddings). That keeps inference off the API server and lets it scale to zero when nobody is studying.

Retrieval

Retrieval runs in a few stages. First it pulls key terms with TF-IDF, which needs no LLM call and keeps things fast. Then it builds several queries per topic, the topic name plus the topic paired with each key term, embeds them in one Modal call, and runs them against Pinecone in parallel. Reciprocal rank fusion merges the ranked lists with a k of 60, so chunks that surface across queries rise to the top and only those go to the model. For artifact generation this enrichment adds about 300 to 600 ms. The model writes from the actual passages, so it keeps the specific details and examples a plain summary would flatten.

flowchart LR
  S[Topic summary] --> KT[Key terms via TF-IDF]
  KT --> Q[Multi-query: topic and topic-plus-term]
  Q --> EM[Batch embed on Modal]
  EM --> VS[Parallel vector search on Pinecone]
  VS --> RRF[Reciprocal rank fusion, k=60]
  RRF --> TK[Top-k chunks per topic]
Loading

Tech stack

  • Frontend: Next.js 16, React 19, TypeScript, Tailwind v4, shadcn/ui, React Query
  • Backend: Bun, deployed on Railway
  • Data: Supabase (Postgres and auth), Pinecone (vectors)
  • AI: Modal-hosted Gemma for generation and embeddings, RAG with multi-query retrieval and RRF

The product UI is written in Argentinean Spanish.

Layout

merlin/
  frontend/    Next.js app: dashboard, courses, chat, PDF viewer
  backend/     Bun API, Supabase migrations, and the Modal AI functions in src/ai

Running it

You need Bun, Node, and accounts for Supabase, Pinecone, and Modal.

# backend
cd backend
bun install
bun run index.ts        # port 3001

# frontend
cd frontend
npm install
npm run dev             # port 3000

Each package reads its own .env (Supabase keys, Pinecone key, Modal endpoints). The database schema lives in backend/supabase/migrations.

Status

Working prototype. The retrieval and enrichment layer is the part I spent the most time on, and it is documented in more detail in backend/docs/RAG-ENRICHMENT.md. The AI functions under backend/src/ai are Python and deploy to Modal separately from the Bun API.

About

A course-scoped RAG assistant, so students get answers they can trust from their own material. Multi-query retrieval with TF-IDF and rank fusion on Modal.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages