A cutting-edge, interactive Streamlit application that optimizes document retrieval and reduces AI language model costs through intelligent vector-based context chunking and retrieval.
- Overview
- Key Features
- Architecture
- Getting Started
- Installation
- Running Locally
- Project Structure
- Usage Guide
- Technology Stack
- Configuration
- Deployment
- Environment Impact
Groot is an enterprise-grade document optimization platform designed to reduce AI language model costs while maintaining response quality. It leverages FAISS vector search and semantic embeddings to intelligently extract only the most relevant document context needed to answer user queries.
When processing large documents (PDFs, reports, etc.) with AI models, organizations typically pass the entire document as context, leading to:
- High token consumption and inflated API costs
- Slower inference times due to context bloat
- Wasted computational resources processing irrelevant information
Groot uses semantic vector search to:
- Extract and chunk documents intelligently
- Build a FAISS vector index for sub-millisecond retrieval
- Retrieve only the top-K most relevant chunks matching your query
- Reduce context size by 60-80% while maintaining quality
- Compare costs and responses side-by-side
- Upload PDF documents directly through the web interface
- Automatic text extraction using pypdf
- Real-time processing feedback with spinners
- Configurable chunk sizing and overlap
- FAISS vector indexing for lightning-fast similarity search
- Sentence-Transformer embeddings for semantic understanding
- Top-K retrieval to get only the most relevant context
- Sub-millisecond search performance
- Real-time token counting using tiktoken
- Cost calculations based on your API pricing
- Side-by-side comparison of unoptimized vs optimized context
- Savings metrics (percentage & dollar amount)
- Generate responses using full unoptimized context
- Generate responses using Groot-optimized context
- Visual comparison to verify quality parity
- Side-by-side layout for easy analysis
- Google Generative AI (Gemini) with local API keys
- Google Vertex AI for enterprise deployments
- Configurable API endpoints and models
- Modern organic wood & forest color scheme
- Responsive design (desktop and mobile)
- Glassmorphism cards with gradient accents
- Smooth animations and intuitive navigation
- Adjustable chunk size and overlap
- Top-K retrieval parameter tuning
- Model selection and API key management
- Cost-per-million-tokens configuration
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GROOT FRONTEND β
β (Streamlit Web Application) β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββΌβββββββββββββ
β β β
βββββΌββββ ββββΌββββ ββββΌβββββ
β PDF β βQuery β βConfig β
βUpload β βInput β βPanel β
βββββ¬ββββ ββββ¬ββββ βββββ¬ββββ
β β β
ββββββββββββΌβββββββββββββ
β
ββββββββββββΌβββββββββββ
β TEXT EXTRACTION β
β (pypdf lib) β
ββββββββββββ¬βββββββββββ
β
ββββββββββββΌβββββββββββ
β TEXT CHUNKING β
β (configurable size) β
ββββββββββββ¬βββββββββββ
β
ββββββββββββΌβββββββββββββββββββββββ
β VECTOR EMBEDDING & INDEXING β
β (Sentence-Transformers+FAISS) β
ββββββββββββ¬ββββββββββββββββββββββ
β
ββββββββββββΌβββββββββββββββββββββββ
β VECTOR SEARCH & RETRIEVAL β
β (Top-K similarity matching) β
ββββββββββββ¬ββββββββββββββββββββββ
β
ββββββββββββΌβββββββββββββββββββββββ
β LLM RESPONSE GENERATION β
β (Google Gemini / Vertex AI) β
ββββββββββββ¬ββββββββββββββββββββββ
β
ββββββββββββΌβββββββββββββββββββββββ
β METRICS & COMPARISON DISPLAY β
β (Cost, tokens, responses) β
ββββββββββββββββββββββββββββββββββββ
- Python 3.11 or higher
- pip package manager
- Google Gemini API key (or Vertex AI credentials)
- Git (optional)
- Clone or Download the Repository
git clone <repository-url>
cd groot- Create Virtual Environment
python -m venv .venv-
Activate Virtual Environment
Windows:
.venv\Scripts\activate
macOS/Linux:
source .venv/bin/activate -
Install Dependencies
pip install -r requirements.txtStart the Streamlit App:
streamlit run app.pyThe app will open automatically in your browser at http://localhost:8501
groot/
βββ app.py # Main Streamlit application
βββ requirements.txt # Python dependencies
βββ Dockerfile # Docker containerization
βββ README.md # This file
βββ utils.py # Core utility functions
β
βββ components/ # Reusable UI components
β βββ header.py # Navigation header with logo
β βββ settings.py # Settings modal and config
β
βββ sections/ # Page sections
β βββ hero.py # Hero section intro
β βββ technology.py # Technology stack overview
β βββ cost_savings.py # Cost analysis showcase
β βββ connectors.py # Enterprise integrations
β βββ environment.py # Environmental impact
β βββ integration.py # Integration pipelines
β βββ footer_cta.py # Call-to-action footer
β βββ optimizer.py # Main optimizer tool
β
βββ image/ # Static assets
β βββ groot-logo.png # Brand logo
β βββ groot-logo_old.png # Legacy logo
β
βββ resources/ # Reference documents
β βββ Indian Paneer recipies.pdf
β βββ vanguards_principles_for_investing_success.pdf
β
βββ .github/
βββ workflows/
βββ deploy.yml # CI/CD pipeline
- Click "Upload Document (PDF)" in the optimizer page
- Select a PDF file from your computer
- Wait for the file to process (text extraction happens automatically)
- Type your search query or prompt in the "Enter Search Query / Prompt" field
- Examples:
- "Summarize the main risk factors"
- "What are the key financial metrics?"
- "Extract all regulatory requirements"
- The app will:
- Build a FAISS vector index from the document chunks
- Perform semantic search to find relevant sections
- Generate responses using both unoptimized (full) and optimized (chunked) contexts
- Display token counts, costs, and savings
- Section 2: View token reduction and cost savings metrics
- Section 3: Compare side-by-side LLM responses from both approaches
- Verify that the optimized response maintains quality while reducing costs
- Click "βοΈ Settings" in the top navigation bar to fine-tune:
- Backend: Choose between Gemini API or Vertex AI
- API Key: Enter your Google Gemini API key
- Chunk Size: Adjust document chunk size (default: 1000 tokens)
- Chunk Overlap: Set overlap between chunks (default: 200 tokens)
- Top-K: Number of relevant chunks to retrieve (default: 5)
- Cost: Set your API cost per 1M tokens
| Layer | Technology | Purpose |
|---|---|---|
| Frontend | Streamlit 1.60.0 | Web UI framework |
| Vector DB | FAISS | Fast similarity search |
| Embeddings | Sentence-Transformers | Semantic embeddings |
| LLM | Google Gemini / Vertex AI | Response generation |
| PDF Processing | pypdf 6.14.2 | PDF text extraction |
| Tokenization | tiktoken 0.13.0 | Token counting |
| Numerics | NumPy 2.5.1 | Numerical operations |
| Visualization | Plotly 6.9.0 | Interactive charts |
| ML | scikit-learn, PyTorch | ML utilities |
streamlit # Web framework
pypdf # PDF text extraction
tiktoken # Token counting
sentence-transformers # Embeddings model
faiss-cpu # Vector search index
google-generativeai # Gemini API integration
plotly # Visualization
numpy # Numerical computing
Create a .env file in the root directory (optional):
GOOGLE_API_KEY=your_gemini_api_key_here
GOOGLE_VERTEX_PROJECT_ID=your_vertex_project_idAccess via the βοΈ Settings button in the app:
{
"backend": "API Key (Local)", # or "Vertex AI"
"api_key": "your_api_key",
"cost_per_1m": 0.00075, # Cost per 1M input tokens
"chunk_size": 1000, # Tokens per chunk
"chunk_overlap": 200, # Overlap between chunks
"top_k": 5 # Chunks to retrieve
}| Parameter | Default | Impact | Recommendation |
|---|---|---|---|
| Chunk Size | 1000 | Larger = more context per chunk, fewer chunks | 800-1500 |
| Overlap | 200 | Larger = more redundancy, smoother retrieval | 100-300 |
| Top-K | 5 | Larger = more context but less optimization | 3-10 |
| Cost/1M | 0.00075 | Adjust to match your API pricing | Your rate |
Build and run with Docker:
# Build image
docker build -t groot:latest .
# Run container
docker run -p 8080:8080 \
-e GOOGLE_API_KEY=your_key_here \
groot:latestAccess at: http://localhost:8080
docker run -p 8080:8080 \
-e GOOGLE_API_KEY=your_api_key \
-e GOOGLE_VERTEX_PROJECT=your_project \
groot:latestSee .github/workflows/deploy.yml for automated deployment configuration.
Groot helps reduce environmental impact by:
- Reduced Computation: Less token processing = fewer GPU cycles
- Lower Energy Usage: Smaller context = faster inference = less power consumption
- Carbon Footprint: Optimized queries reduce datacenter energy requirements
- Resource Efficiency: 60-80% token reduction per query directly translates to proportional energy savings
Example Impact:
- Processing 1 million queries with 10,000 token average
- Groot optimization: 2,000 token average (80% reduction)
- Result: Significant reduction in COβ emissions and energy costs
| Metric | Unoptimized | Optimized | Improvement |
|---|---|---|---|
| Tokens/Query | 10,000 | 2,000 | 80% β |
| Cost/Query | $0.0075 | $0.0015 | 80% β |
| Inference Time | 3.5s | 1.2s | 65% β |
| Context Relevance | 100% | 95%+ | β |
- Small Documents: < 50 pages - instant processing
- Medium Documents: 50-500 pages - < 5 seconds
- Large Documents: 500+ pages - < 30 seconds
- Vector Search: Sub-millisecond retrieval regardless of document size
Contributions are welcome! Areas for improvement:
- Support for additional document formats (DOCX, XLSX, TXT)
- Multi-document search across collections
- Custom embedding models
- Advanced analytics dashboard
- API endpoint for programmatic access
- Caching layer for frequently searched documents
- Cost analytics and usage reporting
MIT License - See LICENSE file for details
Issue: "API Key not found"
- Solution: Click βοΈ Settings and enter your Google Gemini API key
- Get key: https://makersuite.google.com/app/apikey
Issue: "Could not extract text from PDF"
- Solution: Ensure PDF is text-based (not image-based/scanned)
- Try OCR tools to convert scanned PDFs first
Issue: "FAISS installation error"
- Solution: For Apple Silicon Mac, use:
pip install faiss-cpu - For other systems:
pip install faiss-cpuorfaiss-gpu
Issue: "Slow vector search"
- Solution: Reduce chunk size or top-K value
- Check that you have adequate RAM (8GB+ recommended)
- Check app logs in terminal for error messages
- Review settings configuration
- Verify PDF file format and content
- Ensure API keys have appropriate permissions
Q3 2026:
- Multi-file batch processing
- Real-time cost tracking dashboard
- Custom embedding models support
- API REST endpoints
Q4 2026:
- Advanced analytics and insights
- Document collection management
- Team collaboration features
- Enterprise SSO integration
Built with β€οΈ using:
- Streamlit - Web framework
- FAISS - Vector search
- Google AI - LLM API
- Sentence-Transformers - Embeddings
For questions or feedback:
- Email: harishsingla89@gmail.com
- Project Issues: Create a GitHub issue
Made with πΏ for a smarter, greener AI future.