Nano Banana Pro
Agent skill for nano-banana-pro
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Sign in to like and favorite skills
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Maximum-quality RAG system for complex multi-topic queries across 2,257 pages of Watermelon documentation. PRODUCTION READY with 78% precision, 100% MRR, and 92.7% quality score.
GitHub: https://github.com/hardik121121/wm_help_assistant_final
Key Features:
# After cloning cp .env.example .env # Edit .env with your API keys python3 -m venv venv source venv/bin/activate pip install -r requirements.txt
# Launch Streamlit UI (most common) ./run_app.sh # Test end-to-end pipeline python -m src.generation.end_to_end_pipeline # Run evaluation (5 queries recommended - Groq free tier limit) python -m src.evaluation.comprehensive_evaluation # Validate configuration python -m config.settings
All modules with
if __name__ == "__main__" can be tested independently:
python -m src.query.query_understanding python -m src.retrieval.hybrid_search python -m src.generation.answer_generator python -m src.database.vector_store python -m src.database.bm25_index
CRITICAL: Always use
python -m src.module.name NOT python src/module/name.py
Located in
scripts/ - standalone, no src/ imports:
# Compare evaluation results (A/B testing) python scripts/compare_evaluations.py tests/results/baseline.json tests/results/new.json # Diagnose quality issues python scripts/diagnose_quality.py # Enrich chunks with computed metadata python scripts/enrich_chunks.py
NO external dependencies or reprocessing needed!
cache/hierarchical_chunks.json (5.2 MB, 2,133 chunks)cache/hierarchical_embeddings.pkl (60 MB, 2,106 vectors)cache/bm25_index.pkl (64 MB, 16,460 vocab terms)cache/images/ (1,549 semantically-named images)Just clone, add API keys, and run!
All major objects are dataclasses (no ORM):
# ✅ Correct - nested access pipeline_result.answer.answer pipeline_result.validation.overall_score # ❌ Wrong - flattening doesn't exist pipeline_result.answer_text # AttributeError! # ✅ JSON serialization from dataclasses import asdict result_dict = asdict(result) # ✅ Mutable defaults @dataclass class MyClass: items: List[str] = field(default_factory=list) # Correct tags: List[str] = [] # Wrong - shared between instances!
# ✅ Correct settings.pdf_path settings.vector_weight settings.chunk_size # ❌ Wrong - settings are NOT nested settings.paths.pdf_path settings.retrieval.vector_weight
Pinecone has 40KB metadata limit. Full content/metadata loaded at initialization:
# In hybrid_search.py __init__ self.chunk_content_map = {chunk['metadata']['chunk_id']: chunk.get('content', '')} self.chunk_metadata_map = {chunk['metadata']['chunk_id']: chunk.get('metadata', {})} # During retrieval - ALWAYS restore full data chunk_id = match.metadata.get('chunk_id') content = self.chunk_content_map.get(chunk_id, '') # Full content full_metadata = self.chunk_metadata_map.get(chunk_id, {}) merged_metadata = {**match.metadata, **full_metadata}
If retrieval returns empty content, check content_map is loaded!
Every query → 3 variations with 32 synonym mappings:
src/query/query_expander.py - integration name mappinghybrid_search.py50/50 proven optimal via A/B testing:
# config/settings.py vector_weight: float = 0.5 # Semantic search (50%) bm25_weight: float = 0.5 # Keyword search (50%) rrf_k: int = 60 # Can override per-query in hybrid_search.py results = hybrid_search.search( query="...", vector_weight=0.6, # Override if needed bm25_weight=0.4 )
Tested: 50/50 → 78% precision, 100% MRR vs 45/55 → 72% precision, 82% MRR
No async/await in codebase (intentional):
ALWAYS use
for imports to work correctly:python -m
# ✅ Correct python -m src.evaluation.comprehensive_evaluation python -m src.generation.end_to_end_pipeline # ❌ Wrong - import errors python src/evaluation/comprehensive_evaluation.py
chunk = { 'content': '...', # Full text content 'metadata': { # Identification 'chunk_id': 'sec_156_chunk_2', 'section_id': 'sec_156', # Navigation 'page_start': 38, 'page_end': 40, 'heading_path': ['Installation', 'Kubernetes', 'Configuration'], 'current_heading': 'Configuration', 'heading_level': 3, # AI-Enhanced (UNIQUE - from docling_processor) 'content_type': 'configuration', # troubleshooting, integration, etc. 'topics': ['kubernetes', 'deployment', 'security'], 'content_summary': 'LLM-generated summary...', 'integration_names': ['Slack', 'MS Teams'], 'technical_depth': 'high', # Structural Detection 'has_code': True, 'has_tables': False, 'has_images': True, 'has_lists': True, # Image & Table 'image_paths': ['cache/images_enhanced/kubernetes_config_page38_img0.png'], 'image_captions': ['Kubernetes deployment diagram'], 'table_texts': [], # Chunk Management 'is_continuation': False, 'chunk_index': 0, 'total_chunks_in_section': 1, 'token_count': 282, 'char_count': 1128, 'is_toc': False } }
See:
docs/REFERENCE_CARD.md for complete field descriptions
❌
python src/evaluation/comprehensive_evaluation.py
✅ python -m src.evaluation.comprehensive_evaluation
❌
settings.paths.pdf_path
✅ settings.pdf_path
❌ Retrieving from Pinecone without loading content_map ✅ Load content_map in
__init__, restore during retrieval
❌
json.dumps(dataclass_instance)
✅ json.dumps(asdict(dataclass_instance))
❌
items: List[str] = []
✅ items: List[str] = field(default_factory=list)
❌ Running 30 test queries at once (exceeds free tier) ✅ Run 5 queries at a time (~14 queries/day limit)
❌ Changing weights without A/B testing ✅ Save baseline, make change, compare with
scripts/compare_evaluations.py
❌ Trying to reprocess PDF (all data already included!) ✅ Use existing
cache/ files (ready to go)
Query → Understanding → Multi-Step Retrieval → Generation → Validation (Phase 3) (Phase 4) (Phase 6) (Phase 6)
5 Layers:
Key Classes:
QueryUnderstandingEngine - Decomposes complex queriesMultiStepRetriever - Independent retrieval per sub-questionHybridSearch - RRF fusion of vector + BM25AnswerGenerator - Strategy-aware generation (4 strategies)ResponseValidator - Quality validationFor complete architecture:
docs/technical/architecture.md
Status: 🟢 PRODUCTION READY
| Metric | Value | Target | Status |
|---|---|---|---|
| Precision@10 | 78.0% | >70% | ✅ Excellent |
| MRR | 100% | >80% | ✅ Perfect |
| Quality Score | 92.7% | >75% | ✅ Outstanding |
| Completeness | 100% | >85% | ✅ Perfect |
| Success Rate | 100% | >90% | ✅ Perfect |
| Avg Query Time | 25.2s | <30s | ✅ Fast |
| Cost per Query | $0.003 | <$0.01 | ✅ Cheap |
See:
tests/results/comprehensive_evaluation.json
Create
.env from .env.example and add:
Groq Free Tier: 100K tokens/day ≈ 14 queries/day (7K tokens per query)
One-Time Setup (already done - included in repo):
Per Query:
Monthly (300 queries): ~$10-15
# Day 1: Baseline python -m src.evaluation.comprehensive_evaluation # Enter: 5 cp tests/results/comprehensive_evaluation.json tests/results/baseline.json # Day 2: After changes python -m src.evaluation.comprehensive_evaluation # Enter: 5 # Compare python scripts/compare_evaluations.py \ tests/results/baseline.json \ tests/results/comprehensive_evaluation.json
# 1. Edit config/settings.py # Change vector_weight and bm25_weight # 2. Run evaluation python -m src.evaluation.comprehensive_evaluation # 3. Compare with baseline python scripts/compare_evaluations.py \ tests/results/baseline_50_50_weights.json \ tests/results/comprehensive_evaluation.json
# src/query/query_expander.py self.integration_aliases = { 'zendesk': ['zendesk support', 'zendesk help desk'], 'hubspot': ['hubspot crm', 'hubspot marketing'], # Add new mappings here }
├── config/ │ └── settings.py # Flat Pydantic configuration ├── src/ │ ├── query/ # Phase 3: Understanding │ │ ├── query_understanding.py │ │ ├── query_decomposer.py │ │ ├── query_expander.py # 32 synonym mappings │ │ └── query_classifier.py │ ├── database/ # Phase 5: Indexes │ │ ├── vector_store.py # Pinecone │ │ ├── bm25_index.py │ │ └── run_phase5.py # One-time setup (already done) │ ├── retrieval/ # Phase 4: Multi-step │ │ ├── hybrid_search.py # RRF fusion + content mapping │ │ ├── multi_step_retriever.py │ │ ├── reranker.py # Cohere │ │ └── context_organizer.py │ ├── generation/ # Phase 6: Answer │ │ ├── answer_generator.py # 4 strategies │ │ ├── smart_image_selector.py # 🆕 LLM-based image filtering │ │ ├── response_validator.py │ │ └── end_to_end_pipeline.py │ └── evaluation/ # Phase 7: Metrics │ ├── comprehensive_evaluation.py │ ├── retrieval_metrics.py │ └── generation_metrics.py ├── cache/ # ✅ All data included │ ├── hierarchical_chunks.json │ ├── hierarchical_embeddings.pkl │ ├── bm25_index.pkl │ └── images/ ├── scripts/ # Standalone utilities │ ├── compare_evaluations.py │ ├── diagnose_quality.py │ └── enrich_chunks.py ├── tests/ │ ├── test_queries.json # 30 complex queries │ └── results/ # Evaluation outputs ├── docs/ # Complete documentation │ ├── technical/architecture.md │ ├── features/smart-image-selection.md # 🆕 Smart image filtering │ ├── guides/quick-start-ui.md # Streamlit usage │ ├── REFERENCE_CARD.md # Chunk structure │ └── INTEGRATION_GUIDE.md ├── app.py # Streamlit UI ├── run_app.sh # Launch script └── .env.example # Config template
asdict() for JSONsettings.key not settings.category.keypython -m - required for importsModuleNotFoundError: No module named 'src'
Solution: Use
python -m src.module.name not python src/module/name.py
Chunks have 0 chars, no content
Solution: Check
content_map is loaded in hybrid_search.py initialization
AttributeError: 'Settings' object has no attribute 'paths'
Solution: Settings are flat - use
settings.pdf_path not settings.paths.pdf_path
Rate limit exceeded
Solution: Wait until midnight UTC or use 5 queries max per batch
FileNotFoundError: cache/hierarchical_chunks.json
Solution: Ensure you cloned from correct repo with all files
src/generation/smart_image_selector.py - LLM-based image filteringsrc/generation/answer_generator.py - Uses _extract_images_smart()app.py - Inline image display (2-column grid within answer box)tests/results/comprehensive_evaluation.jsondocs/features/smart-image-selection.mdwatermelon-docs-v2✅ All Phases Complete (9/9):
Status: 🟢 PRODUCTION READY
Last Updated: 2025-11-09 Version: 1.0.0 Status: ✅ PRODUCTION READY