This repository contains a Django-based retrieval-augmented generation (RAG) app using pgvector extension.
POST /retrieval/upload/accepts a file.- The app hashes the file and reuses an existing document ID if the same file was already indexed.
- Text is extracted from PDFs, DOCX files, or plain text files.
- OCR text is collected from PDF image regions when available.
- The app chunks extracted content, generates embeddings, and stores them in PostgreSQL with
pgvector. POST /retrieval/query/retrieves the most relevant chunks for a given document and asks OpenAI to answer from that context only.GET /retrieval/prev-docs/returns previously indexed documents.
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
python manage.py migrate
python manage.py test
python manage.py runserverThe database must be PostgreSQL with the pgvector extension available. The repository includes a migration that creates the documents and chunks tables used by the app.
DJANGO_SECRET_KEYDJANGO_DEBUGDJANGO_ALLOWED_HOSTSDB_ENGINEDB_NAMEDB_USERDB_PASSWORDDB_HOSTDB_PORTOPENAI_API_KEYOPENAI_CHAT_MODELEMBEDDING_MODEL