Document AI Assistant is a phase-based Flask API for document-grounded Q&A using retrieval-augmented generation.
It accepts PDF uploads, chunks content, stores embeddings in Pinecone, retrieves relevant chunks with Vertex AI embeddings, and answers with evidence-backed responses through LangGraph orchestration.
- Upload and validate PDFs
- Page-aware chunking with deterministic metadata
- Embedding generation with Vertex AI abstraction
- Pinecone vector store for indexing and retrieval
- LangGraph orchestration for validation/retrieval/generation control flow
- Grounded responses with citations (
document_id,filename,page) - Rejection when evidence is insufficient
- Structured errors and request-id propagation
- CI/lint/test pipeline and Docker image
- RAG evaluation runner with persisted results
flowchart TD
A[POST /api/v1/documents] --> B[PDF validation]
B --> C[Text extraction]
C --> D[Chunking]
D --> E[Vertex AI Embeddings]
E --> F[Pinecone upsert]
Q[POST /api/v1/questions] --> R[LangGraph validate]
R --> S[Retriever]
S --> P[Pinecone query]
P --> G[Answer generator]
G --> H[Structured response]
M[GET /health] --> I[Health JSON]
- Python 3.11+
- Flask
- LangGraph
- Google Vertex AI (Gemini embeddings + generation)
- Pinecone
- Pytest + Ruff + Black
document-ai-assistant/
├── src/
│ ├── api/
│ ├── agent/
│ ├── config.py
│ ├── evaluation/
│ ├── generation/
│ ├── ingestion/
│ ├── logging_config.py
│ ├── retrieval/
│ └── services/
├── tests/
├── docs/
├── evaluation/
├── .github/workflows/
├── Dockerfile
├── requirements.txt
└── requirements-dev.txt
python -m venv .venv
. .venv/Scripts/activate
make installCopy .env.example to .env and fill required values:
GOOGLE_CLOUD_PROJECTGOOGLE_CLOUD_LOCATIONVERTEX_CHAT_MODELVERTEX_EMBEDDING_MODELPINECONE_API_KEYPINECONE_INDEX_NAMERATE_LIMIT_ENABLEDRATE_LIMIT_REQUESTS_PER_WINDOWRATE_LIMIT_WINDOW_SECONDS
make runGET /healthPOST /api/v1/documentsGET /api/v1/documentsDELETE /api/v1/documents/{document_id}POST /api/v1/questions
curl -X POST http://localhost:8080/api/v1/documents \
-F "file=@./sample.pdf"
curl -X POST http://localhost:8080/api/v1/questions \
-H "Content-Type: application/json" \
-d '{"question": "How many vacation days are provided?", "document_ids": []}'make test
make lint
make typecheck
make coveragemake evaluateThe report is written under evaluation/results/ as timestamped JSON.
make docker-build
make docker-runA Cloud Run deployment workflow is available in .github/workflows/deploy.yml.
See:
docs/deployment.mddocs/architecture.mddocs/decisions.mddocs/security.mddocs/api.md
- In development, auth is optional; in production,
APP_ENV=productionrequiresAPI_KEYand authenticated requests viaX-API-Key. - Pinecone namespace and index must be created in advance.
application/x-pdfmay vary by browser/clients.
MIT.