Skip to content

888Greys/RAG-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸŽ“ KCA University AI Knowledge Base

A modern, AI-powered knowledge management system specifically built for KCA University students. Get instant answers about admission requirements, library services, APA formatting, and everything related to KCA University life. Built with Next.js 15, Groq AI, PostgreSQL, and RAG (Retrieval Augmented Generation).

KCA University AI Next.js TypeScript Groq PostgreSQL Preview

🚧 Preview Version - Developer Message

Hey KCA Students! This app is currently in preview and we're working hard to upload all KCA University documents. Soon, it will know everything about KCA University. The developer is quite busy, but if you're willing to contribute documents or help improve the system, you're very welcome!

πŸ“ž Get In Touch

🎯 Our Vision

To create the most comprehensive, AI-powered knowledge base for KCA University students. A single place where any student can get instant, accurate answers about university life, academics, services, and procedures. Together, we can make studying at KCA easier for everyone!

✨ Features

πŸ€– Lightning Fast AI Responses

  • Groq-powered responses with Llama 4 Scout (1-3 second responses)
  • RAG (Retrieval Augmented Generation) for accurate, context-aware answers
  • HyDE (Hypothetical Document Embeddings) for improved document retrieval
  • Smart classification - determines when to use knowledge base vs general chat

πŸ“š KCA University Knowledge

  • Admission Information - Requirements, deadlines, and processes
  • Library & E-Library Help - Access guides and research resources
  • APA Formatting Assistant - APA 7th edition citations and guidelines
  • Student Services - Information about university services and procedures
  • Academic Resources - Course information and academic support

πŸ” Secure Authentication

  • NextAuth.js integration with secure user sessions
  • PostgreSQL user management with encrypted passwords
  • Protected routes and personalized chat history
  • Session persistence across devices

🎨 Mobile-First Design

  • Responsive interface - Perfect for smartphones and tablets
  • Modern UI/UX with gradients and smooth animations
  • Dark/Light mode support
  • Optimized for students on the go

⚑ Performance & Reliability

  • Ultra-fast responses with Groq's inference engine
  • Efficient vector search in PostgreSQL
  • Edge deployment on Vercel for global access
  • Optimized for mobile networks

πŸš€ Live Demo

Try it now: KCA University AI Assistant

Sample Questions to Try:

  • "How do I access the KCA University e-library?"
  • "What are the admission requirements for KCA University?"
  • "How do I format citations in APA 7th edition?"
  • "What student services are available at KCA University?"
  • "How do I apply for accommodation at KCA?"
  • "What are the library opening hours?"

πŸ› οΈ Complete Technology Stack

Frontend & UI

Technology Purpose Category
Next.js 15 React Framework Frontend
React 19 UI Library Frontend
TypeScript Type Safety Language
Tailwind CSS Styling Styling
Framer Motion Animations UI/UX

AI & Machine Learning

Technology Purpose Category
Groq AI Ultra-fast LLM AI
Google AI Embeddings AI
OpenAI GPT Models AI
Vercel AI SDK AI Integration AI

Backend & Database

Technology Purpose Category
PostgreSQL Database Backend
Drizzle ORM Database ORM Backend
NextAuth.js Authentication Auth
bcrypt-ts Password Hashing Security

Infrastructure & Storage

Technology Purpose Category
Vercel Deployment Infrastructure
Vercel Blob File Storage Storage
Vercel KV Redis Cache Cache

Processing & Data

Technology Purpose Category
PDF Parse Document Processing Processing
Langchain Text Splitting Processing
React Markdown Markdown Rendering UI
Sonner Toast Notifications UI
Zod Schema Validation Validation
SWR Data Fetching Data
D3 Scale Data Visualization Visualization

Development Tools

Technology Purpose Category
ESLint Code Linting DevTools

πŸ—οΈ Architecture Highlights

  • RAG (Retrieval Augmented Generation) for accurate, context-aware responses
  • HyDE (Hypothetical Document Embeddings) for improved document retrieval
  • Vector embeddings with Google AI for semantic search
  • Edge runtime deployment for global low-latency access
  • Server-side rendering with dynamic authentication
  • Mobile-first responsive design optimized for all devices

πŸ“‹ Prerequisites

Before you begin, ensure you have:

  • Node.js 18+ installed
  • npm/yarn/pnpm package manager
  • Groq API key (get from console.groq.com)
  • Google AI API key (get from aistudio.google.com)
  • PostgreSQL database (Supabase recommended)

πŸš€ Quick Start

1. Clone the Repository

git clone https://github.com/888Greys/RAG-AI.git
cd RAG-AI

2. Install Dependencies

npm install
# or
yarn install
# or
pnpm install

3. Set Up Environment Variables

Create a .env file in the root directory:

# Groq API key for fast AI inference
GROQ_API_KEY=your-groq-api-key

# Google AI API key for embeddings
GOOGLE_GENERATIVE_AI_API_KEY=your-google-api-key

# NextAuth secret (generate with: openssl rand -base64 32)
AUTH_SECRET=your-auth-secret

# PostgreSQL connection string
POSTGRES_URL=your-postgres-url

# Optional: Vercel Blob for file uploads
BLOB_READ_WRITE_TOKEN=your-vercel-blob-token

# Optional: Vercel KV for caching
KV_REST_API_URL=your-kv-url
KV_REST_API_TOKEN=your-kv-token

4. Set Up Database

The application uses PostgreSQL with the following schema:

-- Users table
CREATE TABLE "User" (
  email VARCHAR(64) PRIMARY KEY NOT NULL,
  password VARCHAR(64)
);

-- Chat history
CREATE TABLE "Chat" (
  id TEXT PRIMARY KEY NOT NULL,
  "createdAt" TIMESTAMP NOT NULL,
  messages JSON NOT NULL,
  author VARCHAR(64) NOT NULL REFERENCES "User"(email)
);

-- Document chunks with vector embeddings
CREATE TABLE "Chunk" (
  id TEXT PRIMARY KEY NOT NULL,
  "filePath" TEXT NOT NULL,
  content TEXT NOT NULL,
  embedding REAL[] NOT NULL
);

5. Upload KCA University Documents

Run the document upload script to populate your knowledge base:

# Upload general documents
npx tsx upload-documents.ts

# Upload KCA-specific documents
npx tsx upload-kca-documents.ts

# Upload PDF documents
npx tsx upload-pdfs.ts

6. Start Development Server

npm run dev

Visit http://localhost:3000 to see your KCA University AI Assistant!

πŸ“– How It Works

RAG Pipeline for KCA University

  1. Document Processing: KCA University documents are split into chunks and embedded using Google's text-embedding-004
  2. Storage: Chunks and embeddings are stored in PostgreSQL with vector search capabilities
  3. Query Processing: Student questions are classified and processed through HyDE
  4. Retrieval: Relevant KCA document chunks are found using cosine similarity
  5. Generation: Groq's Llama 4 Scout generates responses with KCA-specific context

Architecture Flow

Student Question β†’ Classification β†’ HyDE β†’ Vector Search β†’ KCA Context β†’ AI Response

Key Components

  • RAG Middleware: Handles retrieval and context injection for KCA documents
  • Chat Interface: Mobile-optimized UI for students
  • Authentication: Secure student account management
  • Vector Database: Efficient search through KCA University documents

πŸ”§ Configuration

AI Models

  • Main Chat: meta-llama/llama-4-scout-17b-16e-instruct (Groq)
  • Classification: llama-3.1-8b-instant (Groq)
  • Embeddings: text-embedding-004 (Google)

Customization for KCA

You can customize the knowledge base by:

  1. Adding KCA Documents: Use upload scripts with official KCA content
  2. Modifying UI: Update branding in /components for KCA colors/logos
  3. Changing Models: Update model configurations in /ai/index.ts
  4. Styling: Modify Tailwind classes for KCA University branding

πŸ“ Project Structure

β”œβ”€β”€ ai/                     # AI configuration and RAG middleware
β”œβ”€β”€ app/                    # Next.js app router
β”‚   β”œβ”€β”€ (auth)/            # Authentication pages (login/register)
β”‚   β”œβ”€β”€ (chat)/            # Chat interface and API routes
β”‚   β”œβ”€β”€ landing/           # Landing page with developer info
β”‚   └── db.ts              # Database functions
β”œβ”€β”€ components/            # React components (chat, forms, etc.)
β”œβ”€β”€ drizzle/              # Database migrations
β”œβ”€β”€ utils/                # Utility functions
β”œβ”€β”€ pdfs/                 # KCA University PDF documents
β”œβ”€β”€ schema.ts             # Database schema
β”œβ”€β”€ upload-documents.ts   # General document upload
β”œβ”€β”€ upload-kca-documents.ts # KCA-specific document upload
└── upload-pdfs.ts        # PDF document upload

πŸš€ Deployment

Deploy to Vercel (Recommended)

  1. Fork the Repository:

  2. Connect to Vercel:

    • Go to vercel.com
    • Import your forked repository
    • Add environment variables
    • Deploy!
  3. Set Environment Variables in Vercel dashboard:

    • GROQ_API_KEY
    • GOOGLE_GENERATIVE_AI_API_KEY
    • AUTH_SECRET
    • POSTGRES_URL

🀝 Contributing

We welcome contributions from KCA University students and developers! Here's how you can help:

πŸŽ“ For KCA Students

  • Share Documents: Help us upload official KCA University documents
  • Report Issues: Let us know if information is missing or incorrect
  • Suggest Features: What would make this more useful for students?
  • Test & Feedback: Use the app and share your experience

πŸ’» For Developers

  • Code Contributions: Improve features, fix bugs, add functionality
  • Documentation: Help improve this README and other docs
  • UI/UX: Make the interface even better for students
  • Performance: Optimize for mobile and slow connections

Development Workflow

  1. Fork the repository from github.com/888Greys/RAG-AI
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes
  4. Test thoroughly: npm run build and npm run dev
  5. Commit changes: git commit -m 'Add amazing feature'
  6. Push to branch: git push origin feature/amazing-feature
  7. Open a Pull Request

πŸ“ž Contact for Contributions

🎯 Roadmap

Phase 1 (Current - Preview)

  • βœ… Basic chat functionality with RAG
  • βœ… User authentication and registration
  • βœ… Mobile-responsive design
  • βœ… Core KCA University documents
  • πŸ”„ Uploading comprehensive KCA document library

Phase 2 (Coming Soon)

  • πŸ“‹ Complete KCA University document coverage
  • πŸ” Advanced search and filtering
  • πŸ“± Progressive Web App (PWA) support
  • 🌍 Offline functionality for key information
  • πŸ“Š Usage analytics and popular questions

Phase 3 (Future)

  • πŸ€– Voice interaction support
  • πŸ“… Integration with KCA University systems
  • πŸŽ“ Personalized student recommendations
  • πŸ“š Study group and collaboration features
  • πŸ† Gamification for knowledge sharing

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • KCA University for being an amazing institution worth building for
  • KCA Students for inspiration and feedback
  • Vercel for the AI SDK and hosting platform
  • Groq for ultra-fast AI inference
  • Google for high-quality embeddings
  • Next.js team for the amazing framework
  • Open Source Community for all the incredible tools

οΏ½οΏ½οΏ½οΏ½ Support & Contact

For Students

For Developers


Built with ❀️ for KCA University students using the Vercel AI SDK

Making university life easier, one question at a time. πŸŽ“βœ¨

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published