Skip to content

AlexCo888/ai-thesis

Repository files navigation

🧠 Thesis RAG

Next.js 15 + Vercel AI SDK 5 + AI Elements + Pinecone

A polished RAG (Retrieval-Augmented Generation) app with streaming chat, citations, explore, summarize-range, and flashcards.
Optimized for performance, clarity, and modern Vercel AI workflows. Powered by Google Gemini with 12 languages supported: English, Spanish, Portuguese, French, German, Italian, Chinese, Japanese, Korean, Arabic, Russian, and Hindi.


⚙️ 1. Install & Setup

pnpm i
cp .env.example .env.local
# Add your environment variables:
# GOOGLE_GENERATIVE_AI_API_KEY=your-api-key
# PINECONE_API_KEY=your-pinecone-key
# PINECONE_INDEX=your-index-name
# GENERATION_MODEL=gemini-2.5-flash-preview-09-2025 (or your preferred Gemini model)
# EMBEDDING_MODEL=text-embedding-004 (Google's embedding model)

🧩 Install AI Elements Components

npx ai-elements@latest init
npx ai-elements@latest add conversation message prompt-input sources inline-citation response

📄 Add Your Thesis PDF

Place your thesis file at:

public/thesis.pdf

🗃️ 2. Prepare Pinecone Vector Database

This project uses Pinecone for vector storage and similarity search.

  1. Create a Pinecone index with 1536 dimensions (for Google's text-embedding-004)
  2. Add your API key and index name to .env.local
  3. Run the ingestion script (see next step)

🧠 3. Ingest the Thesis

pnpm ingest

This script:

  • Parses public/thesis.pdf with pdfjs-dist
  • Splits content per-page into semantic chunks
  • Embeds chunks using Google's text-embedding-004 via Vercel AI SDK
  • Stores vectors in Pinecone for fast similarity search

💻 4. Develop Locally

pnpm dev

Then open: 👉 http://localhost:3000 (English - default)

🌍 Language Support (12 Languages)

Access the app in any of these languages by changing the URL prefix:

  • 🇺🇸 English: / or /en
  • 🇪🇸 Spanish: /es
  • 🇵🇹 Portuguese: /pt
  • 🇫🇷 French: /fr
  • 🇩🇪 German: /de
  • 🇮🇹 Italian: /it
  • 🇨🇳 Chinese: /zh
  • 🇯🇵 Japanese: /ja
  • 🇰🇷 Korean: /ko
  • 🇸🇦 Arabic: /ar
  • 🇷🇺 Russian: /ru
  • 🇮🇳 Hindi: /hi

The app includes a LocaleSwitcher in the top-right corner with a scrollable dropdown for seamless language switching.


☁️ 5. Deploy to Vercel

  1. Add the following as Vercel Project Environment Variables:
    • GOOGLE_GENERATIVE_AI_API_KEY
    • PINECONE_API_KEY
    • PINECONE_INDEX
    • GENERATION_MODEL (optional)
    • EMBEDDING_MODEL (optional)
  2. Deploy your app (the /api/chat route streams UI responses in real time).

🧩 Key Features

  • 🤖 Google Gemini AI - Uses gemini-2.5-flash-preview for fast, high-quality responses
  • 🌍 12 Languages - Full i18n support via next-intl v4 (EN, ES, PT, FR, DE, IT, ZH, JA, KO, AR, RU, HI)
  • 🎯 Pinecone Vector Search - Fast, scalable semantic search
  • 🎨 AI Elements - Beautiful UI components: Conversation, Message, PromptInput, InlineCitation
  • 📚 Multiple Modes - Chat, Explore, Summarize, and Flashcards
  • 🔗 Citations - Inline citations with page references
  • Streaming - Real-time AI responses with streaming support
  • 🎓 Flashcard Generator - AI-powered flashcards with contextual chat
  • 📱 Responsive Design - Mobile-first approach with Tailwind CSS

🏗️ Why This Architecture

Component Purpose
Vercel AI SDK 5 Unified text generation & streaming (streamText) with typed tool & embedding APIs — perfect for route handlers or server actions.
Google Gemini Latest multimodal AI with excellent performance, cost-effectiveness, and long context windows.
AI Elements Real AI-native UI built on shadcn/ui — plug-and-play components for beyond-chat interactions.
Pinecone Managed vector database with fast similarity search, automatic scaling, and production-ready infrastructure.
next-intl v4 Type-safe internationalization with automatic locale routing and SEO optimization.

🧭 Final Tips

AI Model Configuration

  • Change GENERATION_MODEL in .env.local to use different Gemini models:
    • gemini-2.5-flash-preview-09-2025 (fast, recommended)
    • gemini-2.0-flash (quicker)
    • gemini-2.5-pro (more capable)
  • Adjust temperature and other parameters in /api/chat/route.ts

Retrieval Optimization

  • Tune chunk size / overlap in lib/chunk.ts for best retrieval accuracy
  • Adjust the number of retrieved chunks in searchSimilar() (default: 6)
  • Pinecone automatically handles index optimization

Internationalization (12 Languages)

The app supports 12 languages out of the box:

  • European: English, Spanish, Portuguese, French, German, Italian
  • Asian: Chinese (Simplified), Japanese, Korean, Hindi
  • Middle Eastern: Arabic
  • Eastern European: Russian

To add more languages:

  1. Add locale code to src/i18n/routing.ts locales array
  2. Create messages/{locale}.json with all translation keys
  3. Add locale to middleware matcher in src/middleware.ts
  4. Update LocaleSwitcher component with locale display code

All translation files are in the messages/ directory with consistent JSON structure.

UI Customization

  • For inline hover citations (Perplexity-style), wire token-level data into InlineCitation
  • AI Elements includes patterns for advanced interactions

🧰 Features Included

Chat Interface - Streaming responses with inline citations
Explore Tab - Semantic search across your thesis
Summarize Tab - Page-range summarization
Flashcards Tab - AI-generated study cards with contextual chat
PDF Viewer - Integrated thesis viewer with page jumping
12 Language Support - Full internationalization with next-intl v4
Responsive Design - Mobile-optimized layout
Type-Safe - Complete TypeScript coverage

🔧 Scripts

pnpm dev          # Start development server
pnpm build        # Build for production
pnpm start        # Start production server
pnpm lint         # Run ESLint
pnpm ingest       # Ingest PDF into Pinecone
pnpm migrate      # (Legacy) Pinecone migration if needed

📚 Documentation


Author: Alejandro Comi | Koffe AI | El Café de los Sentidos Tech stack: Next.js 15 • TypeScript • React 19 • Vercel AI SDK 5 • Google Gemini • AI Elements • Pinecone • next-intl v4 • Shadcn UI • Tailwind CSS
License: MIT

About

AI-Powered Thesis RAG App

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published