AI system for Bhagavad Gita queries with semantic search and grounded generation.
An AI-powered Q&A application that retrieves relevant passages from the Bhagavad Gita and generates grounded responses through a Flask API backed by PostgreSQL.
General-purpose models answer scriptural questions without reliable source grounding. The goal was a focused AI system that retrieves relevant text first, then generates answers from that context.
I built a RAG pipeline using SentenceTransformers for semantic search and LLaMA 3.1 for response generation. Flask APIs expose query and retrieval endpoints, with PostgreSQL storing documents and supporting efficient lookup.
Text is embedded with SentenceTransformers and stored in PostgreSQL. At query time, the question is embedded, similar passages are retrieved, and LLaMA 3.1 generates a response from the selected context. Flask handles routing, request validation, and API responses.
Architecture Preview
Flask API
REST
SentenceTransformers
Embeddings
PostgreSQL
Documents
Semantic Retrieval
Vector search
LLaMA 3.1
Generation
Retrieval quality for verse-level text
Passages needed to stay semantically complete when chunked. I tuned embedding and retrieval to return coherent context for generation.
Connecting retrieval and generation cleanly
The API had to pass retrieved context into LLaMA 3.1 in a consistent format so responses stayed tied to source material.
PostgreSQL-backed document flow
Indexed documents and retrieval results needed a reliable storage layer. PostgreSQL kept document data and API access in one place.
SentenceTransformers for semantic search
Used embedding-based retrieval to match natural-language questions to relevant Gita passages.
LLaMA 3.1 for grounded generation
Generation runs on retrieved context rather than open-ended prompting alone.
Flask + PostgreSQL API layer
Flask exposed retrieval and generation endpoints with PostgreSQL handling document storage and lookup.
Image placeholder
Dharma RAG query interface showing a question and cited answer
Image placeholder
Ingestion and retrieval pipeline diagram
Image placeholder
Source citation panel alongside generated response