Pouyan Mehdibeik
All projects

AI / ML

Django RAG Engine

A retrieval-augmented generation platform: users upload documents, the system chunks and embeds them, stores vectors in FAISS, and answers questions grounded in that content to reduce hallucination — with model switching across GPT-4o, Claude, Gemini, and Llama via OpenRouter.

PythonDjangoDjango REST FrameworkLangChainOpenAI EmbeddingsFAISSOpenRouterDocker

Overview

Most RAG demos are a LangChain quickstart wrapped around a single script. This one is built as an actual backend service: a Django application with a real data model for documents and interaction logs, a REST API in front of it, and a deployment story (Docker Compose) rather than a notebook that only runs on one machine. The goal was to answer questions grounded in uploaded documents while keeping the LLM provider swappable, so the system isn't locked into a single vendor's pricing or availability.

Architecture

  1. 1

    Client uploads a .docx document through the Django REST API

  2. 2

    Server extracts raw text from the document (python-docx)

  3. 3

    Text is split into semantic chunks sized for retrieval quality

  4. 4

    Each chunk is embedded via OpenAI's text-embedding-3-large

  5. 5

    Embeddings are indexed in a FAISS vector store

  6. 6

    An incoming question is embedded and matched against FAISS for the top-k relevant chunks

  7. 7

    Retrieved context plus the question are sent to an LLM via OpenRouter (GPT-4o, Claude, Gemini, or Llama)

  8. 8

    The grounded response is returned to the client and logged for debugging

Challenges

  • Chunking documents so retrieval stays precise without losing surrounding context
  • Abstracting the LLM call so GPT-4o, Claude, Gemini, and Llama are interchangeable behind one interface, avoiding vendor lock-in
  • Keeping embedding and inference cost predictable as the document set grows

Outcomes

  • Fully containerized with Docker and Docker Compose, so the whole stack (app, dependencies, config) reproduces on any machine
  • Swapping the underlying LLM is a config change, not a code change
  • An admin dashboard surfaces ingested documents and interaction logs for debugging retrieval quality