Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PDF QA System with Vector Search and Knowledge Graph

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.

Architecture

  • 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

Prerequisites

  • Docker and Docker Compose
  • OpenAI API key

Setup

  1. Clone or navigate to the project directory:
cd /Users/chinmay_shringi/Desktop/rag-vectors
  1. Create a .env file with your OpenAI API key:
cp .env.example .env
  1. Edit .env and add your OpenAI API key:
OPENAI_API_KEY=sk-your-actual-api-key-here

Running the Application

Start all services with Docker Compose:

docker compose up --build

This 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

Usage

  1. 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
  2. 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

System Features

  • 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

Development

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

Stopping the Application

docker compose down

To also remove volumes (database data):

docker compose down -v

Technical Details

  • 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

Troubleshooting

If services fail to start:

  1. Check Docker logs: docker compose logs
  2. Ensure ports 3000, 5432, 7474, and 7687 are available
  3. Verify OpenAI API key is set in .env
  4. Check Docker has sufficient resources allocated

License

This project is provided as-is for educational and demonstration purposes.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages