This project implements your workflow:
- Intent lookup from
CustomerIntent - Ask for contract number and resolve balance from
CustomerBalance - RAG fallback over PDF chunks stored in Postgres pgvector
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtollama run qwen2.5:7b
ollama pull nomic-embed-textdocker run --name pgvector-local \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_USER=postgres \
-e POSTGRES_DB=postgres \
-p 5432:5432 \
-d pgvector/pgvector:pg16Enable extension:
docker exec -it pgvector-local psql -U postgres -d postgres -c "CREATE EXTENSION IF NOT EXISTS vector;"export POSTGRES_DB=postgres
export POSTGRES_USER=postgres
export POSTGRES_PASSWORD=postgres
export POSTGRES_HOST=localhost
export POSTGRES_PORT=5432
export OLLAMA_TEXT_MODEL=qwen
export OLLAMA_EMBED_MODEL=nomic-embed-text
export PGVECTOR_CONNECTION="postgresql+psycopg://postgres:postgres@localhost:5432/postgres"
export PGVECTOR_COLLECTION="pdf_knowledge_base"python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
python manage.py runserverOpen:
- Chat UI: http://127.0.0.1:8000/
- Admin: http://127.0.0.1:8000/admin/
Use admin to create:
CustomerIntentrows (intent + answer)CustomerBalancerows (contract number + contract balance)
python ingest_pdf.py "/absolute/path/to/your_qa.pdf"- If intent lookup misses, the API falls back to RAG.
session_idfrom frontend local storage is used to trackawaiting_contract.- Main endpoint:
POST /api/chatwith body:
{
"session_id": "abc123",
"message": "What is my renewal policy?"
}