Skip to content

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

83 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“š AskMyNotes

AI-powered study companion that turns your notes into an interactive, intelligent tutor.

Upload your PDFs and text notes, ask questions in natural language β€” through text, real-time streaming chat, or voice β€” and get grounded, citation-backed answers powered by Corrective RAG (CRAG) and Google Gemini. Generate quizzes to test your understanding. All answers are strictly limited to your uploaded material β€” no hallucinations.


🎯 Problem Statement

Students and learners drown in study material β€” PDFs, lecture notes, textbooks β€” yet struggle to quickly find specific answers, revise effectively, and self-test. Existing AI tools either hallucinate freely or require complex setups. AskMyNotes solves this by providing:

  1. Controlled, grounded Q&A β€” answers come exclusively from your uploaded notes with provenance citations.
  2. Multi-modal interaction β€” text chat, real-time streaming, and voice-in/voice-out.
  3. Active recall study mode β€” auto-generated MCQs and short-answer questions from your notes.
  4. Subject isolation β€” each subject gets its own namespace; cross-contamination of knowledge is impossible.

✨ Key Features

Feature Description
πŸ“„ PDF & TXT Ingestion Upload notes in PDF or plain text. Auto-chunked, embedded with text-embedding-004, and stored in Pinecone with per-subject namespace isolation.
πŸ” Corrective RAG Pipeline Retrieve β†’ Rerank (lexical + semantic blend) β†’ Threshold Gate β†’ Gemini 2.5 Flash β†’ Post-process. If top score is below threshold, the LLM isn't even called.
πŸ’¬ Chat with Citations Ask questions and get answers with exact file name, page number, chunk ID citations and confidence scores (High/Medium/Low).
🌊 Real-time Streaming Socket.IO streaming delivers token-by-token responses. SSE fallback for REST clients.
πŸŽ™οΈ Voice Mode Speak your question β†’ Gemini Live transcribes β†’ CRAG pipeline answers β†’ Gemini Live synthesizes speech β†’ audio response. Full voice-in/voice-out loop.
🧠 Thread Memory Conversation context is persisted via LangGraph Postgres Checkpointer. Follow-up questions understand prior context.
πŸ“ Study Mode (Quiz) Auto-generated MCQs and short-answer questions with model answers, explanations, and source citations.
πŸ” Authentication Email/password auth with email verification, password reset, and Google OAuth via Better Auth.
πŸ›‘οΈ Security Helmet, CORS, rate limiting (30 auth / 20 ask per window), per-user subject ownership validation.
🎨 Sketchy UI Hand-drawn notebook aesthetic with squiggle filters, graph paper backgrounds, sticky notes, and micro-animations.

πŸ—οΈ Architecture

graph TB
    subgraph Frontend["Frontend (Next.js 16)"]
        LP[Landing Page]
        Auth[Auth Pages<br/>Login / Register / Reset]
        Dashboard[Dashboard<br/>Notes Β· Chat Β· Voice Β· Study]
        Store[Zustand Store]
        Socket[Socket.IO Client]
    end

    subgraph Backend["Backend (Express 5 + TypeScript)"]
        API[REST API]
        WS[Socket.IO Server]
        BA[Better Auth]

        subgraph CRAG["CRAG Pipeline"]
            Retriever[Subject-Scoped<br/>Retriever]
            Reranker[Hybrid Reranker<br/>75% semantic + 25% lexical]
            Gate[Threshold Gate]
            PB[Prompt Builder]
            LLM[Gemini 2.5 Flash<br/>LangChain]
            PP[Post Processor]
        end

        subgraph Voice["Voice Pipeline"]
            VCtrl[Voice Controller]
            GLC[Gemini Live Client<br/>STT + TTS]
        end

        Ingest[Ingestion Service<br/>PDF Parse + Chunking]
        Memory[LangGraph Postgres<br/>Memory Service]
    end

    subgraph Storage["Storage Layer"]
        PG[(PostgreSQL<br/>Prisma ORM)]
        PC[(Pinecone<br/>Vector DB)]
    end

    Dashboard --> Socket --> WS
    Dashboard --> API
    Auth --> BA
    API --> CRAG
    WS --> CRAG
    VCtrl --> GLC
    VCtrl --> CRAG
    Retriever --> PC
    Ingest --> PC
    Ingest --> PG
    Memory --> PG
    BA --> PG
    Gate -->|Below threshold| PP
    Gate -->|Above threshold| PB --> LLM --> PP
Loading

CRAG Pipeline Flow

User Question
    β”‚
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  1. Embed query (text-embedding-004) β”‚
β”‚  2. Pinecone query (namespace=subjectId, topK=8) β”‚
β”‚  3. Rerank (0.75Γ—semantic + 0.25Γ—lexical, topN=5)  β”‚
β”‚  4. Threshold gate (score < 0.35?)                β”‚
β”‚     β”œβ”€ YES β†’ Return "Not found in your notes"    β”‚
β”‚     └─ NO  β†’ Continue                            β”‚
β”‚  5. Load thread memory (LangGraph Postgres)       β”‚
β”‚  6. Build prompt (system + context + memory)      β”‚
β”‚  7. Gemini 2.5 Flash invoke                       β”‚
β”‚  8. Post-process β†’ structured JSON response       β”‚
β”‚  9. Save turn to thread memory                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    β”‚
    β–Ό
{ answer, citations[], confidence, evidence[], found }

πŸ› οΈ Tech Stack

Backend

Technology Purpose
Express 5 HTTP server with typed routes
TypeScript (Strict) End-to-end type safety
Prisma 7 (PostgreSQL) ORM for Users, Subjects, NoteChunks, Threads
Pinecone Vector database with namespace-per-subject isolation
Google Gemini 2.5 Flash LLM for Q&A generation (via LangChain)
Google text-embedding-004 Embedding model for chunks and queries
Gemini Live API Native audio STT/TTS for voice mode
LangGraph Postgres-backed checkpointer for thread memory
Socket.IO Real-time streaming chat
Better Auth Authentication (email + Google OAuth)
Zod Runtime request validation
Helmet + express-rate-limit Security middleware

Frontend

Technology Purpose
Next.js 16 (App Router) React framework with server components
Tailwind CSS 4 Utility-first styling
Framer Motion Animations and transitions
Zustand Global state management
Socket.IO Client Real-time chat streaming
Lucide React Icon library
Better Auth Client Auth session management

πŸ“ Project Structure

ASKMYNOTES/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ prisma/
β”‚   β”‚   β”œβ”€β”€ schema.prisma          # Database schema (User, Subject, NoteChunk, Thread)
β”‚   β”‚   β”œβ”€β”€ checkpointer.sql       # LangGraph checkpointer setup SQL
β”‚   β”‚   └── migrations/            # Prisma migration history
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ server.ts              # Entry point β€” HTTP + Socket.IO
β”‚   β”‚   β”œβ”€β”€ app.ts                 # Express app bootstrap with DI
β”‚   β”‚   β”œβ”€β”€ config/                # Environment + CRAG config loaders
β”‚   β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”‚   β”œβ”€β”€ AskController.ts   # POST /api/ask + /api/ask/stream
β”‚   β”‚   β”‚   β”œβ”€β”€ IngestionController.ts
β”‚   β”‚   β”‚   └── SubjectController.ts
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   β”œβ”€β”€ crag/              # CragPipelineService + not-found logic
β”‚   β”‚   β”‚   β”œβ”€β”€ ingestion/         # PDF parsing + chunking + Pinecone upsert
β”‚   β”‚   β”‚   β”œβ”€β”€ llm/               # Gemini LangChain + Native SDK clients
β”‚   β”‚   β”‚   β”œβ”€β”€ memory/            # LangGraph Postgres memory service
β”‚   β”‚   β”‚   β”œβ”€β”€ pinecone/          # Pinecone client factory
β”‚   β”‚   β”‚   β”œβ”€β”€ postprocess/       # Response structuring
β”‚   β”‚   β”‚   β”œβ”€β”€ prompt/            # System + human prompt construction
β”‚   β”‚   β”‚   β”œβ”€β”€ prisma/            # PrismaClient + SubjectRepository
β”‚   β”‚   β”‚   β”œβ”€β”€ retrieval/         # SubjectScopedRetriever + Reranker
β”‚   β”‚   β”‚   └── auth/              # Better Auth + email templates
β”‚   β”‚   β”œβ”€β”€ socket/                # Socket.IO server for streaming chat
β”‚   β”‚   β”œβ”€β”€ voice/                 # Gemini Live STT/TTS + Voice controller
β”‚   β”‚   β”œβ”€β”€ interfaces/            # Abstractions (IRetriever, IReranker, etc.)
β”‚   β”‚   β”œβ”€β”€ types/                 # Shared TypeScript types
β”‚   β”‚   └── routes/                # Express route definitions
β”‚   └── package.json
β”‚
└── frontend/
    β”œβ”€β”€ app/
    β”‚   β”œβ”€β”€ page.tsx               # Landing page (sketchy notebook theme)
    β”‚   β”œβ”€β”€ login/page.tsx         # Login
    β”‚   β”œβ”€β”€ register/page.tsx      # Registration
    β”‚   β”œβ”€β”€ forgot-password/       # Forgot password flow
    β”‚   β”œβ”€β”€ reset-password/        # Reset password flow
    β”‚   └── study/page.tsx         # Main dashboard (Notes, Chat, Voice, Study)
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ components/
    β”‚   β”‚   β”œβ”€β”€ dashboard/         # Sidebar, NotesPanel, ChatPanel, VoicePanel,
    β”‚   β”‚   β”‚                      # StudyModePanel, McqCard, ShortAnswerCard, etc.
    β”‚   β”‚   └── CoreLandingPages/  # Landing page UI components
    β”‚   β”œβ”€β”€ lib/
    β”‚   β”‚   β”œβ”€β”€ actions.ts         # Backend API client functions
    β”‚   β”‚   β”œβ”€β”€ auth-client.ts     # Better Auth client
    β”‚   β”‚   β”œβ”€β”€ socket.ts          # Socket.IO client
    β”‚   β”‚   └── utils.ts           # Utilities (cn, etc.)
    β”‚   └── store/                 # Zustand stores (study, login, register, etc.)
    └── package.json

πŸš€ Getting Started

Prerequisites

  • Node.js 22.x
  • PostgreSQL (local or hosted)
  • Pinecone account (free tier works)
  • Google AI Studio API key (for Gemini + embeddings)

1. Clone the Repository

git clone https://github.com/GreenHacker420/ASKMYNOTES.git
cd ASKMYNOTES

2. Backend Setup

cd backend
cp .env.example .env
# Fill in all required values in .env (see Environment Variables below)

npm install
npm run prisma:generate
npm run prisma:migrate
npm run checkpointer:setup   # One-time LangGraph table setup
npm run dev                   # Starts on port 3001

3. Frontend Setup

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

4. Open the App

Navigate to http://localhost:3000, register an account, create a subject, upload your notes, and start asking!


βš™οΈ Environment Variables

Create a .env file in /backend with these values:

Variable Description Example
DATABASE_URL PostgreSQL connection string postgresql://user@localhost:5432/askmynotes
PINECONE_API_KEY Pinecone API key pc-...
PINECONE_ENV Pinecone environment us-east-1
PINECONE_INDEX Pinecone index name askmynotes
GOOGLE_API_KEY Google AI Studio key (Gemini + embeddings) AIza...
BETTER_AUTH_SECRET Auth signing secret Random 32+ char string
BETTER_AUTH_URL Backend URL for auth http://localhost:3001
BETTER_AUTH_TRUSTED_ORIGINS Allowed frontend origins http://localhost:3000
SMTP_HOST / SMTP_PORT / SMTP_USER / SMTP_PASS Email for verification/reset Gmail SMTP details
NOT_FOUND_THRESHOLD Min reranked score to call LLM 0.35
CHUNK_SIZE Characters per chunk 1200
CHUNK_OVERLAP Overlap between chunks 200
TOP_K Pinecone retrieval count 8
RERANK_TOP_N Chunks passed to LLM after reranking 5
GEMINI_MODEL Gemini model name gemini-2.5-flash
FRONTEND_URL Frontend URL for CORS http://localhost:3000

πŸ”Œ API Endpoints

Method Endpoint Auth Description
GET /api/health ❌ Health check
GET /api/subjects βœ… List user's subjects
POST /api/subjects βœ… Create a new subject
GET /api/subjects/:id/files βœ… List files for a subject
POST /api/subjects/:id/files βœ… Upload & ingest a file
POST /api/ask βœ… Ask a question (JSON response)
POST /api/ask/stream βœ… Ask a question (SSE stream)
POST /api/voice/query βœ… Voice-in β†’ answer β†’ voice-out
ALL /api/auth/* β€” Better Auth routes

Socket.IO Events:

Event Direction Payload
ask Client β†’ Server { question, subjectId, threadId, requestId?, subjectName? }
ask:chunk Server β†’ Client { requestId, delta }
ask:final Server β†’ Client { requestId, response: AskResponsePayload }
ask:error Server β†’ Client { requestId, error }

πŸ—ƒοΈ Database Schema

erDiagram
    User ||--o{ Subject : owns
    User ||--o{ Session : has
    User ||--o{ Account : has
    Subject ||--o{ NoteChunk : contains
    Subject ||--o{ Thread : has
    Thread ||--o{ ThreadTurn : contains

    User {
        string id PK
        string name
        string email UK
        boolean emailVerified
        datetime createdAt
    }

    Subject {
        string id PK
        string name
        string userId FK
        datetime createdAt
    }

    NoteChunk {
        string id PK
        string subjectId FK
        string pineconeId UK
        string fileName
        int page
        string chunkId
        text text
        json metadata
    }

    Thread {
        string id PK
        string subjectId FK
        datetime createdAt
    }

    ThreadTurn {
        string id PK
        string threadId FK
        string role
        text content
        datetime createdAt
    }
Loading

πŸ”’ Security & Guardrails

  • No hallucinations: If retrieval scores fall below the configured threshold (NOT_FOUND_THRESHOLD), the LLM is never called. The response is a deterministic "Not found in your notes for [Subject]".
  • Namespace isolation: Each subject uses its own Pinecone namespace (namespace = subjectId). Cross-subject knowledge leakage is impossible.
  • User ownership: Every subject query validates that the requesting user owns the subject.
  • Rate limiting: Auth routes: 30 req/15min. Ask routes: 20 req/min.
  • Input validation: All payloads validated with Zod schemas before processing.

πŸ‘₯ Team

Team Horizon


πŸ“„ License

This project was built for a hackathon. See the repository for license details.

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages