Skip to content

MEghlima8/Django-RAG-Docs

Repository files navigation

Django RAG Docs

A Retrieval-Augmented Generation (RAG) system built with Django, PostgreSQL (pgvector), and LangChain. This system allows users to upload documents, search them using vector embeddings, and ask questions to receive AI-generated answers based on the document context.

Features

  • Document Management: Upload and manage text documents via Django Admin.
  • Vector Search: Automatically generates embeddings (using all-MiniLM-L6-v2) and performs semantic search using PostgreSQL pgvector.
  • RAG QA System: Uses LangChain and zephyr-7b-beta (via Hugging Face API) to answer user questions based on stored documents.
  • Dockerized: Fully containerized setup for easy deployment.

Prerequisites

  • Docker and Docker Compose installed on your machine.
  • A Hugging Face Access Token (for the LLM feature).

Installation & Setup

  1. Clone the project: Extract the project files to your local machine.

  2. Configure Environment: Rename .env.sample file to .env and find the variables and change its values to the desire value.

  3. Build and Run:

docker compose up -d --build
  1. Apply Migrations:
docker compose run web python manage.py migrate
  1. Create Superuser (Admin):
docker compose run web python manage.py createsuperuser

Importing Sample Data

You can import documents from a CSV file (e.g., data.csv):

docker compose run web python manage.py import_documents data.csv

Usage

1. Admin Panel

Access the admin panel at http://localhost:8000/admin to manage documents and view query logs.

2. API Endpoints

Search Documents (Vector Search):

  • URL: POST /api/search/
  • Body:
{
    "query": "What is reinforcement learning?",
    "top_k": 3
}

Ask a Question (RAG):

  • URL: POST /api/ask/
  • Body:
{
    "question": "How does Git help developers?"
}
  • Response: Returns the AI-generated answer and the source documents used.

About

An AI-powered RAG (Retrieval-Augmented Generation) system built with Django REST Framework, PostgreSQL (pgvector), and LangChain.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors