Grounded answer
Bhagavad Gita • AWS-backed RAG system
700 verses.
One grounded answer.
I built an AWS-backed retrieval-augmented generation system over the Bhagavad Gita using Amazon Bedrock, OpenSearch Serverless, and a local reranker. It turns a real situation into focused semantic searches, retrieves and reranks the strongest verse candidate, then returns a grounded answer with the original Sanskrit and English.
- 700 Bhagavad Gita verses enriched for semantic retrieval
- Bedrock query intelligence, Titan embeddings, OpenSearch retrieval, and BGE reranking
- Structured verse selection plus grounded answer generation on Bedrock
A passage to consider
Grounded reflection
Original Sanskrit
Transliteration
English translation
Latency for this response
Inside the system
Every stage of the RAG pipeline
The production path combines Amazon Bedrock, OpenSearch Serverless, deterministic retrieval controls, and a local BGE reranker. Each stage does one narrow job well, from translating the question into search concepts to validating the final evidence-backed answer.
Corpus preparation
Loads 700 Bhagavad Gita records, validates structured theme output, and enriches every English translation before indexing.
load_records()
enrich()
validate()
Query intelligence
Amazon Nova Lite decomposes the scenario into four semantic facets while a controlled domain map adds source-language concepts and synonyms.
generate_search_queries()
expand_domain_concepts()
Amazon Nova Lite
Vector retrieval
Titan embeddings search the OpenSearch Serverless vector index across the original question, generated facets, and deterministic domain expansions.
retrieve_candidates()
Titan Embed v2
OpenSearch Serverless
Rank fusion
Reciprocal Rank Fusion merges results from every search, rewards repeated evidence, removes duplicate verses, and keeps the top 20 candidates.
RRF_CONSTANT = 60
RESULTS_PER_QUERY = 5
MAX_RERANK_CANDIDATES = 20
Neural reranking
A cached local BGE cross-encoder scores every candidate against the original question and its strongest auxiliary search, then returns the best four passages.
load_reranker()
rerank_globally()
bge-reranker-v2-m3
Evidence selection
A structured Bedrock call selects exactly one allowed verse ID. Python validation rejects missing, duplicated, or unsupported references.
select_verse_ids()
validate_selection()
Amazon Nova Lite
Grounded generation
A second Bedrock call receives only the selected translation, separating retrieval from response writing to reduce unsupported invention.
build_context()
generate_passage_message()
validate_message()
Amazon Nova Lite
Orchestration and API
The final orchestration composes the grounded answer and exposes it through a validated FastAPI endpoint for the web experience and API consumers.
generate_grounded_answer()
answer_question()
create_answer()