Starting the Application
First Run: Data Loading
On the first run, you’ll see console output indicating data preparation:- Loads all PDFs from the
data/directory - Extracts and processes metadata
- Splits text into semantic chunks
- Downloads the embedding model (if not cached)
- Generates embeddings for all chunks
- Stores embeddings in ChromaDB
Using the Chat Interface
Interface Overview
The DeenPAL interface consists of:- Title Bar: “Deen Pal Chatbot”
- Chat History: Scrollable conversation display
- Input Box: Text field at the bottom for typing questions
- Submit: Press Enter or click the send button
Asking Questions
Example Queries
Here are some example questions you can ask:General Guidance
Specific Topics
Comparative Questions
Seeking Wisdom
Response Format:The chatbot typically responds with:
- Relevant Hadith citations (Book, Chapter, Number)
- The Hadith text
- A brief explanation
- Direct answer to your question
Chat History Functionality
DeenPAL maintains conversation context within a session:app.py
How It Works
- Storage: All messages are stored in
st.session_state.messages - Display: On each interaction, the full history is displayed
- Context: Previous messages are included in the RAG chain invocation
app.py
Benefits
- Contextual Responses: The chatbot understands follow-up questions
- Persistent Conversation: The full conversation remains visible
- Reference Previous Answers: You can refer back to earlier topics
Clearing History
To start a fresh conversation:- Refresh the browser page
- Or restart the Streamlit server
Chat history is only maintained within a browser session. Closing the browser or refreshing the page clears the history.
Understanding the Response Flow
Here’s what happens when you submit a query:- User Query: You type and submit a question
- Display Question: The question appears in the chat
- Retrieve Hadiths: Vector similarity search finds relevant Hadiths
- MMR Selection: Maximal Marginal Relevance selects diverse results
- LLM Processing: The language model generates a response
- Display Answer: The answer appears in the chat
- Store in History: Both question and answer are saved
Performance Considerations
Response Time
First Query:- Slower due to model initialization
- May take 5-15 seconds
- Faster due to caching
- Typically 2-5 seconds
Factors Affecting Speed
- Number of retrieved Hadiths (k): More results = slower processing
- LLM provider: Different providers have different response times
- Internet connection: Required for API calls
- System resources: CPU/RAM affect local processing
Troubleshooting Common Issues
Application Won’t Start
Error:Port Already in Use
Error:No Response from Chatbot
Possible Causes:- API Key Issue: Check
.envfile - No Data: Ensure PDFs are in
data/directory - Network Error: Verify internet connection
ChromaDB Error
Error:Slow First Load
Cause: Downloading embedding model and processing PDFs Solution:- Be patient on first run
- Ensure stable internet connection
- Consider using fewer/smaller PDFs initially
Memory Issues
Error:- Reduce number of PDFs
- Increase system RAM
- Lower
fetch_kparameter inchains.py
Stopping the Application
To stop the Streamlit server:- Return to the terminal where it’s running
- Press Ctrl+C
- Wait for graceful shutdown
Advanced Usage
Running on a Custom Port
Running on All Network Interfaces
Disabling Auto-Reload
Production Deployment
For production use, consider:- Use a production WSGI server
- Add authentication
- Set up HTTPS
- Configure resource limits
- Implement logging
Next Steps
Now that you’re running DeenPAL:- Experiment with different types of questions
- Adjust retriever parameters for optimal results
- Customize prompts to match your use case
- Add more Hadith collections to expand coverage
