A Django-based backend system that powers a Knowledge Assistant API using OpenAI LLM and FAISS for retrieval-augmented generation (RAG) from PDF, Markdown, or Text knowledge bases.
- Upload and ingest knowledge base documents (PDF, Markdown, Text)
- Parse, chunk, and embed content using OpenAI
- Store embeddings in FAISS for semantic search
- Ask questions via API, with answers grounded in uploaded knowledge
- Admin interface for document management
- Python 3.x
- Django + Django REST Framework
- OpenAI API (for embeddings and LLM)
- FAISS (vector search)
- PyPDF2, python-docx, markdown (parsing)
- Clone and install dependencies:
python3 -m venv venv source venv/bin/activate pip install -r requirements.txt - Set OpenAI API Key:
export OPENAI_API_KEY=your-openai-key - Run migrations:
python manage.py makemigrations python manage.py migrate
- Create superuser (for admin):
python manage.py createsuperuser
- Run the server:
python manage.py runserver
- POST
/api/upload-document/ - Form Data:
file(PDF, .md, .txt) - Response: Document metadata
- POST
/api/ask-question/ - JSON:
{ "question": "What is the use of mitochondria?" } - Response:
{ "answer": "The mitochondria is known as the powerhouse of the cell...", "sources": ["Document.pdf - Chunk 3"] }
- Visit
/admin/to manage documents and chunks.
- Only context from uploaded documents is used to answer questions (RAG).
- Caching and advanced prompt engineering can be added for optimization.
- Upload a Science Class IX PDF or Markdown file to test. # Final-LLm