Skip to content

moroii69/rag-bash-a

Repository files navigation

bash-A: RAG Chatbot

Next.js TypeScript Drizzle ORM Neon Google Gemini

A Retrieval-Augmented Generation (RAG) chatbot powered by Next.js and Google Gemini. The application uses PDF documents, uploaded by an administrator, as a knowledge base to provide contextually aware, streaming responses to user queries.


Features

  • Role-Based Access: Differentiates between admin and user roles.
  • Admin-Only PDF Ingestion: Admins can upload and process PDF files to build the knowledge base.
  • RAG-Powered Chat: The LLM uses a vector search over the document knowledge base to generate relevant answers.
  • Streaming UI: Responses are streamed token-by-token for a fluid chat experience.
  • Vector Search: Uses Neon serverless Postgres with an HNSW index for efficient semantic search.

Tech Stack

  • Framework: Next.js 15 (App Router)
  • Language: TypeScript
  • Authentication: Clerk (handles user roles)
  • Database: Neon Serverless Postgres + pgvector
  • ORM: Drizzle ORM
  • AI & Embeddings: Google Gemini (gemini-2.5-flash-lite, text-embedding-004) via Vercel AI SDK
  • Styling: Tailwind CSS
  • UI: Shadcn UI & Vercel AI Elements

Local Setup

Prerequisites

  • Node.js (v18+)
  • Bun
  • Neon Account & Database URL
  • Clerk Account & Credentials
  • Google AI API Key

Installation

  1. Clone the repo:

    git clone https://github.com/moroii69/rag-bash-a.git
    cd rag-bash-a
  2. Install dependencies:

    bun install
  3. Configure environment:

    • Copy .env.example to .env.local.
    • Add your credentials for Neon, Clerk, and Google AI.
    cp .env.example .env.local
  4. Sync database schema:

    • Ensure the pgvector extension is enabled on your Neon database.
    • Push the schema.
    bun run db:push
  5. Run the dev server:

    bun run dev

    The application will be available at http://localhost:3000.


Environment Variables

Your .env.local must contain the following keys:

# Neon Database
NEON_DATABASE_URL="postgresql://..."

# Clerk Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY="..."
CLERK_SECRET_KEY="..."

# Google AI
GOOGLE_GENERATIVE_AI_API_KEY="..."

Project Structure

Key files and directories in the project.

src
├── app/
│   ├── api/chat/route.ts   # Chat streaming endpoint
│   ├── chat/page.tsx       # Main chat UI for users
│   ├── upload/page.tsx     # Admin UI for PDF uploads
│   ├── upload/actions.ts   # Server action for PDF processing (admin only)
│   └── layout.tsx          # Root layout with auth provider
├── components/             # Reusable UI components
└── lib/
├── db-config.ts        # Database connection
├── db-schema.ts        # documents table schema
├── embeddings.ts       # Embedding generation logic
└── search.ts           # Vector search implementation

CI Status & Tests

The project includes integration tests and CI checks for linting, database connectivity, and build steps.

  • Core Setup
  • DB Check
  • Lint

Scripts

  • bun run dev: Start the dev server.
  • bun run build: Create a production build.
  • bun run db:push: Push Drizzle schema to the database.
  • bun run lint: Run the Biome linter.

About

Resources

Stars

Watchers

Forks

Contributors 2

  •  
  •