Minimal RAG NextJS is a proof-of-concept demonstrating that you can implement Retrieval-Augmented Generation (RAG) without relying on expensive vector database subscriptions. This project leverages the power of pgvector, a simple PostgreSQL extension, combined with OpenAI embeddings to create a cost-effective, local vector search solution.
- Uses pgvector extension for PostgreSQL
- Integrates OpenAI embeddings for vector creation
- Implements a NextJS web application for file upload and search
- Chunks and stores vectors in a local database
- Provides a simple, intuitive user interface
- Node.js (v14 or later)
- Docker and Docker Compose
- OpenAI API key
-
Clone the repository:
git clone https://github.com/MartinKondor/minimal-rag-nextjs.git cd minimal-rag-nextjs
-
Install dependencies:
npm install
-
Set up the database:
docker-compose up -d npx prisma generate npx prisma db push --force-reset
-
Modify the given
.env
file in the root directory (if you wish):SKIP_ENV_VALIDATION=0 NODE_ENV="development" POSTGRES_URL="postgres://postgresuser:postgrespassword@localhost:54322" POSTGRES_URL_NON_POOLING="postgres://postgresuser:postgrespassword@localhost:54322?pool=false"
-
Start the development server:
npm run dev
-
Open your browser and navigate to
http://localhost:3000
. -
Follow the on-screen instructions:
- Enter your OpenAI API key (this is used client-side and not stored)
- Upload a text file (max 20,000 characters)
- Enter a search query
- View the most relevant chunks from your uploaded file
- File Upload: The app chunks your uploaded text file and creates embeddings using OpenAI's API.
- Vector Storage: These embeddings are stored in the local PostgreSQL database using pgvector.
- Search: When you enter a query, it's converted to an embedding and compared against the stored vectors.
- Results: The most similar text chunks are retrieved and displayed, ranked by relevance.
Contributions are welcome! Please feel free to submit a Pull Request.
- Implement user authentication
- Add support for multiple file types
- Optimize vector search for larger datasets
- Implement more advanced RAG techniques
- OpenAI for their embedding API
- pgvector for enabling vector operations in PostgreSQL
- Next.js for the React framework
Martin Kondor - https://martinkondor.github.io/
Project Link: https://github.com/MartinKondor/minimal-rag-nextjs
Copyright © Martin Kondor
MIT License. See the LICENSE file for more details.