A Retrieval-Augmented Generation (RAG) system that enables users to upload PDFs and ask questions about their content using a hybrid approach combining vector search and knowledge graphs.
- Vector Database: PostgreSQL with pgvector for semantic text search
- Knowledge Graph: Neo4j for relational knowledge and entity relationships
- LLM: OpenAI GPT-3.5-turbo for answer generation
- Embeddings: OpenAI text-embedding-ada-002
- Backend: Node.js with Express
- Frontend: Minimal HTML/CSS/JavaScript interface
- Docker and Docker Compose
- OpenAI API key
- Clone or navigate to the project directory:
cd /Users/chinmay_shringi/Desktop/rag-vectors- Create a
.envfile with your OpenAI API key:
cp .env.example .env- Edit
.envand add your OpenAI API key:
OPENAI_API_KEY=sk-your-actual-api-key-here
Start all services with Docker Compose:
docker compose up --buildThis will start:
- PostgreSQL with pgvector (port 5432)
- Neo4j (ports 7474, 7687)
- Node.js backend serving the frontend (port 3000)
Access the application at: http://localhost:3000
-
Upload PDFs: Click or drag PDF files to upload. The system will:
- Extract text from the PDF
- Split into chunks with overlap
- Generate embeddings using OpenAI
- Store chunks in PostgreSQL with vector embeddings
- Extract entities and create knowledge graph in Neo4j
-
Ask Questions: Enter a question about the uploaded PDFs. The system will:
- Generate embedding for the question
- Perform vector similarity search in PostgreSQL
- Query Neo4j for related entities and relationships
- Combine context and send to GPT for answer generation
- Display answer with sources and graph insights
- Semantic Search: Uses vector embeddings to find relevant text passages
- Knowledge Graph: Extracts entities and relationships for structured reasoning
- Hybrid RAG: Combines both approaches for accurate, context-rich answers
- Source Citations: Shows which PDFs and chunks were used for the answer
- Graph Insights: Displays related entities and relationships from the knowledge graph
The project structure:
rag-vectors/
├── backend/
│ ├── src/
│ │ ├── server.js
│ │ ├── services/
│ │ │ ├── openai-service.js
│ │ │ ├── vector-store.js
│ │ │ ├── graph-store.js
│ │ │ └── pdf-processor.js
│ │ └── utils/
│ │ └── chunking.js
│ ├── package.json
│ └── Dockerfile
├── frontend/
│ └── public/
│ └── index.html
├── db/
│ └── init-postgres.sql
├── docker-compose.yml
└── .env
docker compose downTo also remove volumes (database data):
docker compose down -v- Chunking: Text is split into ~1500 character chunks with 200 character overlap
- Entity Extraction: Simple heuristic based on capitalized word sequences
- Vector Index: HNSW index for fast approximate nearest neighbor search
- Graph Relations: Entities co-occurring in the same chunk are linked
- RAG Prompt: Combines top 5 similar chunks with graph facts for context
If services fail to start:
- Check Docker logs:
docker compose logs - Ensure ports 3000, 5432, 7474, and 7687 are available
- Verify OpenAI API key is set in
.env - Check Docker has sufficient resources allocated
This project is provided as-is for educational and demonstration purposes.