This is Bruce - a modular, production-ready Speech-to-Speech Retrieval-Augmented Generation (RAG) Assistant. The system has been refactored from a monolithic design into focused, reusable modules with comprehensive documentation.
Complete RAG pipeline implementation
KnowledgeBase- Document loading and chunkingEmbeddingManager- OpenAI embedding generationFAISSIndex- Vector similarity search wrapperRAGRetriever- Context retrieval and rankingRAGSystem- Main orchestrator
Key Methods:
rag = RAGSystem()
rag.initialize() # Load or build index
results = rag.retrieve_context(query, k=3)
confidence = rag.get_confidence_level(score)Intelligent prompt generation system
PromptTemplate- Reusable template classSystemPrompt- Assistant personalityPromptGenerator- Context-aware generationConversationManager- Chat history managementRAGPromptBuilder- RAG-specific prompt construction
Key Methods:
prompt = PromptGenerator.generate(confidence, question, context)
system = SystemPrompt.get_content()
conv = ConversationManager()
built = RAGPromptBuilder.build_rag_prompt(question, chunks, history)Knowledge base management utilities
KnowledgeBaseManager- File I/O and operationsContentOrganizer- Section-based organization
Key Methods:
manager = KnowledgeBaseManager()
manager.load_knowledge_base()
manager.append_to_knowledge_base(text)
manager.display_stats()
stats = manager.get_knowledge_base_stats()Refactored main voice assistant
- Uses rag_system.py for RAG operations
- Uses prompt_manager.py for prompt generation
- Uses kb_manager.py optionally
- Clean, modular architecture
- Comprehensive error handling
Key Methods:
assistant = VoiceAssistant()
assistant.run()
assistant.listen_for_wake_word()
assistant.start_conversation()
assistant.speak(text)Testing and diagnostic suite
- Environment variable validation
- Dependency checking
- File verification
- RAG system testing
- Prompt testing
- Interactive menu
Usage:
python rag_diagnostics.py --full # Full diagnostics
python rag_diagnostics.py --interactive # Interactive menu
python rag_diagnostics.py --rag # Test RAG
python rag_diagnostics.py --prompts # Test promptsComplete usage guide covering:
- Feature overview
- Architecture explanation
- Setup instructions
- Customization guide
- API reference
- Troubleshooting
- Best practices
When to read: Start here for detailed understanding
Fast reference guide for:
- File structure
- Common tasks
- Configuration options
- Troubleshooting table
- Module dependencies
- Performance tips
When to read: Need quick answers
Detailed explanation of:
- What was refactored
- Benefits of each module
- Before/after comparison
- Migration guide
- Key improvements
When to read: Understand what's new
Summary of all improvements:
- Modularization details
- Prompt improvements
- Knowledge base features
- System tools
- Getting started
When to read: Quick overview of changes
Required API keys:
PORCUPINE_API_KEY=your_key_here
GROQ_API_KEY=your_key_here
OPEN_API=your_key_herePlain text file with your knowledge content
- Already populated with system information
- Edit to add your custom knowledge
- Optional section-based organization
Python package requirements:
groq
SpeechRecognition
faiss-cpu
python-dotenv
scikit-learn
...and more
Porcupine wake word detection model
- Detects "Hey Bruce" phrase
- Pre-trained model included
These are created automatically on first run:
- faiss_index.idx - Vector similarity index
- embeddings.npy - Document embeddings
- doc_chunks.pkl - Text chunks cache
No action needed - system creates these.
- S2S_v8.py - Original monolithic version
- S2S_v9.py - Previous version
- README.md - Original documentation
These are preserved for reference. Use S2S_v10.py instead.
pip install -r requirements.txt
cat > .env << EOF
PORCUPINE_API_KEY=your_key
GROQ_API_KEY=your_key
OPEN_API=your_key
EOFpython rag_diagnostics.py --full# Edit knowledge base
nano info.txt
# Edit prompts
nano prompt_manager.pypython S2S_v10.pySay: "Hey Bruce!"
Ask: "Your question"
Say: "Goodbye" to exit
S2S_v10.py (main application)
├── imports rag_system.py
│ ├── imports numpy, faiss, openai
│ ├── imports langchain_text_splitters
│ └── imports sklearn
├── imports prompt_manager.py
│ └── minimal dependencies
└── (optional) imports kb_manager.py
rag_diagnostics.py (testing tool)
├── imports rag_system.py
├── imports prompt_manager.py
└── imports kb_manager.py
kb_manager.py (standalone utility)
└── minimal dependencies
Located in: .env
PORCUPINE_API_KEY # From picovoice.ai
GROQ_API_KEY # From console.groq.com
OPEN_API # From platform.openai.comLocated in: S2S_v10.py → _configure_speech_recognition()
energy_threshold- Noise sensitivitypause_threshold- Pause detectionphrase_threshold- Minimum audio length
Located in: S2S_v10.py → _configure_tts()
rate- Speaking speed (100-200)volume- Volume level (0.0-1.0)
Located in: rag_system.py
chunk_size- Document chunk size (default: 500)chunk_overlap- Overlap between chunks (default: 50)k- Number of chunks to retrieve (default: 5)- Confidence thresholds: 0.85 (HIGH), 0.75 (MEDIUM)
Located in: prompt_manager.py → PromptGenerator.TEMPLATES
- Edit text for HIGH confidence level
- Edit text for MEDIUM confidence level
- Edit text for LOW confidence level
Located in: prompt_manager.py → SystemPrompt.SYSTEM_CONTENT
- Update personality description
- Change tone and style
- Modify behavior guidelines
python rag_diagnostics.py --fullChecks everything and provides detailed report.
# Test RAG retrieval
python rag_diagnostics.py --rag
# Test prompt generation
python rag_diagnostics.py --prompts
# Interactive menu
python rag_diagnostics.py --interactive# Test RAG
from rag_system import RAGSystem
rag = RAGSystem()
rag.initialize()
results = rag.retrieve_context("test", k=3)
# Test prompts
from prompt_manager import PromptGenerator
prompt = PromptGenerator.generate("HIGH", "Q", "context")
# Test KB manager
from kb_manager import KnowledgeBaseManager
mgr = KnowledgeBaseManager()
mgr.display_stats()User Voice Input
↓ [S2S_v10.py]
Speech Recognition (Google STT)
↓ [prompt_manager.py]
Text Preprocessing
↓ [rag_system.py]
Embedding Generation (OpenAI)
↓
FAISS Vector Search
↓
Retrieve Context
↓ [prompt_manager.py]
Confidence Analysis
↓
Prompt Generation
↓ [S2S_v10.py]
LLM API Call (Groq)
↓
Text Response
↓
Text-to-Speech (pyttsx3)
↓
Voice Output
rag_system.py
├─ KnowledgeBase (load/chunk documents)
├─ EmbeddingManager (create embeddings)
├─ FAISSIndex (vector search)
└─ RAGRetriever (get relevant chunks)
prompt_manager.py
├─ SystemPrompt (define personality)
├─ PromptTemplate (reusable formats)
├─ PromptGenerator (create prompts)
├─ ConversationManager (track history)
└─ RAGPromptBuilder (assemble final prompt)
kb_manager.py
├─ KnowledgeBaseManager (file operations)
└─ ContentOrganizer (organize sections)
S2S_v10.py (main application)
└─ Uses all modules for voice interaction
- Wake word detection
- Question answering from knowledge base
- Time/date queries
- Conversation management
- Edit prompts for specific domain
- Add custom knowledge to info.txt
- Adjust confidence thresholds
- Change assistant personality
- Import modules into other projects
- Use RAG system as library
- Create custom retrievers
- Build web interfaces
- Add new prompt templates
- Implement re-ranking strategies
- Integrate external APIs
- Create specialized knowledge bases
- Never commit
.envfile - Use environment variables for keys
- Regenerate keys if exposed
- Use version control exclusions
- Local processing where possible
- API-based operations for embeddings/LLM
- No persistent conversation storage (default)
- Consider implementing logging guards
- Validate user input
- Use HTTPS for any web integrations
- Monitor API usage
- Keep dependencies updated
- Takes 1-2 minutes for embedding generation
- Creates FAISS index
- Caches embeddings
- 2-3 second startup (loads cache)
- Fast RAG retrieval (~100ms)
- LLM response time depends on API
- Keep knowledge base focused
- Use good document structure
- Monitor similarity score distribution
- Consider batch embedding for large KBs
- OpenAI embeddings: ~$0.02/1M tokens
- Groq: Free tier available
- Monitor API usage regularly
- Cache embeddings to reduce calls
| Issue | Solution |
|---|---|
| Missing API keys | Create .env with required keys |
| Module not found | Run pip install -r requirements.txt |
| Microphone error | Check microphone in system settings |
| No context retrieved | Check similarity scores in logs |
| Slow responses | Verify API keys and internet |
- Run diagnostics:
python rag_diagnostics.py --full - Check console logs for error messages
- Test individual modules independently
- Review configuration in respective files
- Check knowledge base content and format
- System logs to console with timestamps
- Enable debug logging by modifying
logging.basicConfig - Check logs for specific error information
- Read
QUICK_REFERENCE.md(overview) - Read
IMPROVEMENTS.txt(what's new) - Run
python rag_diagnostics.py --full - Try running assistant:
python S2S_v10.py
- Read
MODULAR_GUIDE.md(complete guide) - Review source code with docstrings
- Study
rag_system.py(RAG implementation) - Review
prompt_manager.py(prompt logic) - Examine
S2S_v10.py(integration)
- Understand module architecture
- Edit
prompt_manager.pyfor custom prompts - Update
info.txtwith domain knowledge - Test with
rag_diagnostics.py - Deploy customized version
-
Verify Setup
python rag_diagnostics.py --full
-
Customize Content
- Edit
info.txtwith your knowledge - Edit
prompt_manager.pyfor your style
- Edit
-
Test System
python S2S_v10.py
-
Interact
- Say "Hey Bruce"
- Ask questions
- Get smart answers
-
Monitor & Improve
- Check logs for errors
- Review RAG confidence scores
- Refine knowledge base
- MODULAR_GUIDE.md - Comprehensive guide
- QUICK_REFERENCE.md - Quick lookup
- Source code docstrings - Implementation details
- rag_diagnostics.py - System health checks
- Module imports - Individual testing
- Console logs - Detailed information
- Clear module separation
- Comprehensive docstrings
- Type hints throughout
- Error handling and logging
- All Python files created
- Diagnostics pass:
python rag_diagnostics.py --full -
.envfile with API keys created -
info.txtpopulated with knowledge - Can run:
python S2S_v10.py - Say "Hey Bruce" activates system
- Can ask questions and get responses
- Logs show reasonable confidence scores
Your RAG system is now:
- ✅ Modularized into focused components
- ✅ Better prompts with confidence levels
- ✅ Improved knowledge base management
- ✅ Comprehensive diagnostics
- ✅ Extensively documented
- ✅ Production-ready
Start with: python S2S_v10.py
Questions? Read: MODULAR_GUIDE.md
Quick lookup? See: QUICK_REFERENCE.md
Your intelligent voice assistant is ready to go! 🚀