Overview
Beyond semantic search, GitaChat provides a complete browsing experience for all 703 verses of the Bhagavad Gita. Navigate by chapter and verse, read traditional scholarly commentary, and discover related teachings—all in a modern, accessible interface.Complete Text
All 703 verses across 18 chapters, fully searchable and browsable
Dual Commentary
Both AI-generated summaries and traditional scholarly commentary
Chapter Organization
Navigate by chapter (1-18) and verse number for structured reading
Related Verses
Discover semantically similar verses for deeper understanding
The Complete Bhagavad Gita
Chapter and Verse Structure
The Bhagavad Gita contains 18 chapters with varying verse counts:- Shortest: Chapter 13 (35 verses)
- Longest: Chapter 18 (78 verses)
- Total: 703 verses
- Chapter and verse number (e.g., Chapter 2, Verse 47)
- English translation from authoritative sources
- Summarized commentary (AI-generated)
- Full traditional commentary (when available)
Data Loading and Caching
Startup Loading
All verses are loaded from Pinecone into memory when the application starts:Why This Approach?
Pinecone is optimized for similarity search, not full data retrieval. The system uses a “dummy vector” (all zeros) with metadata filters to fetch all verses efficiently by chapter.
- Fast browsing: No database queries after startup
- Instant search: All verses available in memory
- Reduced latency: No network calls for verse retrieval
- Efficient pagination: Client can slice and filter locally
Lifespan Management
- All data loaded before accepting requests
- No cold start delays for users
- Predictable memory footprint
- Graceful shutdown handling
API Endpoints
Get All Verses
- Browse-by-chapter interfaces
- Client-side filtering and search
- Verse navigation components
- Chapter summaries and statistics
Get Specific Verse
The validation ensures chapter is between 1-18 and verse is between 1-78 (the maximum in Chapter 18). Requests with invalid ranges are rejected automatically.
Verse Retrieval
Metadata-Based Lookup
- Uses dummy vector
[0] * 768since we’re filtering by metadata, not similarity - Applies exact filter:
{"chapter": chapter, "verse": verse} - Returns top 1 match (which should be unique)
- Extracts metadata fields for response
chapter: Chapter number (1-18)verse: Verse number within chaptertranslation: English translation textsummarized_commentary: AI-generated summaryfull_commentary: Traditional scholarly commentary (if available)
Dual Commentary System
Summarized Commentary
Generated once during data preparation using GPT-4o-mini:- Concise: Typically 100-200 words
- Complete: Captures key teachings without detail
- Fast to read: Perfect for quick browsing
- Pre-computed: No API call needed at request time
Full Commentary
Stored in Pinecone metadata from traditional scholarly sources: Characteristics:- Comprehensive: 500-2000+ words
- Scholarly: From recognized Gita commentators
- Contextual: Includes philosophical and practical explanations
- Optional: Returned only when available
Chapter-Based Navigation
Efficient Chapter Fetching
The system fetches each chapter individually to handle varying verse counts:top_k=100?
- Chapter 18 has 78 verses (the maximum)
- Setting
top_k=100ensures we capture all verses even if data changes - Provides headroom for edge cases or data discrepancies
Chapter Statistics
| Chapter | Verses | Theme |
|---|---|---|
| 1 | 47 | Arjuna’s Dilemma |
| 2 | 72 | Transcendental Knowledge |
| 3 | 43 | Karma Yoga |
| 4 | 42 | Transcendental Knowledge |
| 5 | 29 | Karma Yoga—Action in Krishna Consciousness |
| 6 | 47 | Dhyana Yoga |
| 7 | 30 | Knowledge of the Absolute |
| 8 | 28 | Attaining the Supreme |
| 9 | 34 | The Most Confidential Knowledge |
| 10 | 42 | The Opulence of the Absolute |
| 11 | 55 | The Universal Form |
| 12 | 20 | Devotional Service |
| 13 | 35 | Nature, the Enjoyer, and Consciousness |
| 14 | 27 | The Three Modes of Material Nature |
| 15 | 20 | The Yoga of the Supreme Person |
| 16 | 24 | The Divine and Demoniac Natures |
| 17 | 28 | The Divisions of Faith |
| 18 | 78 | Conclusion—The Perfection of Renunciation |
Related Verses Discovery
When viewing a specific verse, users can discover related teachings through semantic similarity:- After finding the best match, extract next 3 semantically similar verses
- Ensure uniqueness (no duplicate chapter/verse pairs)
- Include translation and summary for each
- Stop at 3 related verses for optimal UX
- Provides variety without overwhelming
- Fits well in UI layouts
- Offers alternative perspectives
- Maintains focus on primary verse
Performance Optimization
Memory Caching
All 703 verses cached in RAM (~1-2MB) for instant access
Batch Loading
Chapters loaded in parallel during startup for faster initialization
Metadata Indexing
Pinecone indexes chapter/verse for O(1) lookups
Summary Truncation
Summaries limited to 500 chars in listing to reduce payload size
Cache Size Calculation
Search vs. Browse
GitaChat supports two complementary modes:Search Mode (Semantic)
- User asks a question or describes a situation
- System finds most relevant verse using embeddings
- Generates contextual commentary specific to query
- Returns 1 best match + 3 related verses
Browse Mode (Traditional)
- User navigates by chapter and verse
- System retrieves from cache (all verses endpoint)
- Or fetches specific verse with full commentary
- Displays pre-computed summaries for quick reading
| Scenario | Mode | Endpoint |
|---|---|---|
| ”How do I handle stress?” | Search | /api/query |
| ”Show me Chapter 2” | Browse | /api/all-verses |
| ”Read Chapter 6, Verse 35” | Browse | /api/verse |
| ”What does the Gita say about duty?” | Search | /api/query |
Data Structure
In-Memory Cache
Full Verse Response
Error Handling
Verse Not Found
- Invalid chapter/verse combination
- Data missing from Pinecone
- Metadata filter returns no matches
Invalid Input
- Chapter < 1 or > 18
- Verse < 1 or > 78
- Non-integer values
- Missing required fields
Rate Limiting
Different limits for different use cases:- Search (30/min): More frequent, interactive use
- All verses (10/min): Less frequent, typically once per session
- Specific verse (30/min): Frequent navigation between verses
Future Enhancements
Reading Progress
Track which verses users have read across sessions
Verse Comparison
Compare different translations side-by-side
Audio Narration
Sanskrit pronunciation and English narration
Daily Verse
Curated verse recommendation each day
Study Plans
Guided reading paths through related verses
Annotations
Let users add personal notes to verses
Implementation Notes
Why Dummy Vectors?
- Efficient: No computation needed
- Clear intent: Signals this is a metadata-only query
- Fast: Minimal data transfer
Why Not SQL?
Traditional relational databases would be simpler for verse retrieval, but Pinecone provides:- Unified storage: Embeddings and metadata in one place
- Semantic search: Core feature requires vector database
- Scalability: Cloud-native with automatic scaling
- Simplicity: One database instead of two
Next Steps
Semantic Search
Learn how AI finds the most relevant verses for your questions
Contextual Commentary
Discover how AI generates personalized wisdom for each search