A FastAPI-based document ingestion and retrieval-augmented generation (RAG) app. It lets users upload documents, vectorizes them with Google Gemini embeddings, stores them in ChromaDB, and answers session-specific questions with Nemoguardrails safety checks.
- Upload documents via
/uploadand build a Chroma vector store - Query documents by
session_idusing/chat - Streams ingestion logs through
/logs/stream - Enforces input/output safety with Nemoguardrails
- Uses Google Generative AI via
langchain-google-genai
app.py— FastAPI server and endpointssrc/ingest.py— document ingestion, splitting, embedding, and Chroma persistencesrc/query.py— session-aware retrieval and Gemini-based answer generationsrc/query_guardrails.py— safety checks before and after answer generationsrc/loader.py— document loader abstraction for PDF, Word, text, and Excel filesguardrails/query_policy.yml— Nemoguardrails safety policyUI/index.html— front-end interface for the chat UI
Create a .env file in the repository root with:
GOOGLE_API_KEY=your-google-api-key
DATA_DIR=./data
.envis ignored by.gitignoreand should not be committed to git.
python -m pip install -r requirements.txtuvicorn app:app --reloadThen open UI/index.html in a browser or connect a client to the API.
POST /upload— upload a file and index it for a sessionPOST /chat— ask a question for a sessionGET /logs/stream— stream log events for a session
.envis not committed and should remain private. Replace.env.exampleto.envand update with your credentials.- The application requires a valid
GOOGLE_API_KEY.
Thanks !
@author - Sanjaykumar Venkatesan