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.
- Role-Based Access: Differentiates between
adminanduserroles. - 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.
- 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
- Node.js (v18+)
- Bun
- Neon Account & Database URL
- Clerk Account & Credentials
- Google AI API Key
-
Clone the repo:
git clone https://github.com/moroii69/rag-bash-a.git cd rag-bash-a -
Install dependencies:
bun install
-
Configure environment:
- Copy
.env.exampleto.env.local. - Add your credentials for Neon, Clerk, and Google AI.
cp .env.example .env.local
- Copy
-
Sync database schema:
- Ensure the
pgvectorextension is enabled on your Neon database. - Push the schema.
bun run db:push
- Ensure the
-
Run the dev server:
bun run dev
The application will be available at
http://localhost:3000.
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="..."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
The project includes integration tests and CI checks for linting, database connectivity, and build steps.
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.