Spaces:
Running
Running
A newer version of the Streamlit SDK is available:
1.51.0
Medical Chatbot - Recent Improvements
Issues Fixed
1. Model Initialization Error
Problem: "404 models/gemini-1.5-flash is not found" Solution:
- Added automatic model fallback mechanism
- Tries multiple model names until one works:
models/gemini-progemini-promodels/gemini-1.5-progemini-1.5-pro
2. Wrong/Inaccurate Answers
Problem: The model was giving incorrect or irrelevant answers
Solutions Applied:
A. Improved Prompt Engineering
- Before: Complex multi-step instructions
- After: Direct, clear instructions to use ONLY context information
- Added "DO NOT make up or guess information"
- Structured prompt with clear sections
B. Lower Temperature Setting
- Set
temperature=0.3(default is 0.7) - This makes responses more factual and less creative
- Better for medical information accuracy
C. Better Context Formatting
- Clear source citations in context
- Better structured context presentation
- Easier for model to parse and use information
D. Enhanced Generation Config
generation_config={
"temperature": 0.3, # Lower for factual responses
"top_p": 0.8, # Nucleus sampling
"top_k": 40, # Token selection limit
"max_output_tokens": 500, # Concise responses
}
E. Improved Retrieval
- Filters results by similarity threshold (0.5)
- Only returns highly relevant medical content
- Better context quality = better answers
Current Configuration
- Embedding Model: sentence-transformers/all-MiniLM-L6-v2
- LLM Model: Auto-detected Gemini model
- Database: 3,012 medical documents from MultiMedQA
- Top K Retrieval: 5 most relevant chunks
- Similarity Threshold: 0.5 (minimum relevance score)
How It Works Now
- User asks a medical question
- Query is embedded using Sentence Transformers
- Pinecone searches for similar medical content (top 5 results)
- Results are filtered by similarity score (β₯0.5)
- Context is formatted with clear citations
- Gemini generates answer using ONLY the retrieved context
- Response includes:
- Factual answer from medical database
- Citations with sources
- Confidence score
- Medical disclaimer
Testing the Improvements
Try these questions to verify accuracy:
- "What are the symptoms of diabetes?"
- "How is hypertension treated?"
- "Explain cardiac arrhythmia"
- "What causes chest pain?"
Key Improvements Summary
β Model auto-detection (tries multiple models) β Lower temperature for factual responses β Clearer prompt instructions β Better context formatting β Improved error handling β Debug logging for troubleshooting
The chatbot should now provide accurate, factual medical information based solely on the retrieved context from the medical database.