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

Generate a grounded answer

Describe one real situation. The system will trace it to one supporting verse.

0 / 2000

Try an example

⌘/Ctrl + Enter to ask

A passage to consider

Grounded reflection

Grounded answer

Original Sanskrit

Transliteration

English translation

Latency for this response

Query generation
Retrieval
Reranking
Verse selection
Final answer generation
Total pipeline

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.

01

Corpus preparation

Loads 700 Bhagavad Gita records, validates structured theme output, and enriches every English translation before indexing.

load_records() enrich() validate()
02

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
03

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
04

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
05

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
06

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
07

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
08

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()