📖 You are viewing: User Guide - Learn how to build chat applicationsSee also: SDK Reference · API Specification
Source Code:
src/gaia/chat/sdk.py · src/gaia/rag/sdk.pyFirst time here? Complete the Setup guide first to install GAIA and its dependencies.
Quick Start
1
Install dependencies
Activate your virtual environment and install GAIA with RAG support:
2
Create a simple chat
Start chatting with just a few lines of code:
simple_chat.py
3
Use the full SDK
Access advanced features with the complete ChatSDK:
full_chat.py
Core Classes
ChatConfig
Configure your chat session with these options:ChatResponse
Responses include text, history, and optional statistics:SimpleChat
SimpleChat
Lightweight wrapper for basic chat without complex configuration. Perfect for getting started quickly.
CLI Usage
Interactive Mode
Start a conversational chat session:Interactive Commands
Interactive Commands
/clear- Clear conversation history/history- Show conversation history/stats- Show performance statistics/help- Show help messagequit,exit,bye- End conversation
Single Query Mode
Execute one-shot queries:Python SDK Examples
Streaming Chat
Stream responses in real-time:streaming.py
Custom Assistant Name
Personalize your assistant:custom_assistant.py
Session Management
Manage multiple conversation contexts:sessions.py
Conversation History
Access and manage conversation history:history.py
Document Q&A (RAG)
RAG (Retrieval-Augmented Generation) enables chatting with PDF documents using semantic search and context retrieval.
Python SDK with RAG
1
Enable RAG and index documents
rag_chat.py
2
Chat with document context
3
Disable RAG when done
CLI with RAG
- Single Document
- Multiple Documents
- One-shot Query
- Voice Mode
RAG Configuration
Advanced RAG setup options:advanced_rag.py
RAG Debug Mode
Enable debug mode to see detailed retrieval information:Debug Information Includes
Debug Information Includes
- Search keys generated by the LLM
- Chunks found for each search
- Relevance scores
- Deduplication statistics
- Score distributions
Chunking Strategies
Structural Chunking
Default - Fast processing
LLM-Based Semantic
More accurate context
RAG Troubleshooting
Missing Dependencies
Missing Dependencies
PDF Issues
PDF Issues
- Ensure PDF has extractable text (not scanned images)
- Check file is not password-protected
- Verify file is not corrupted
Performance Tuning
Performance Tuning
API Reference
ChatSDK Core Methods
Messaging
send(message: str) -> ChatResponsesend_stream(message: str)
History
get_history() -> List[str]clear_history()get_formatted_history() -> List[Dict]
RAG (Document Q&A)
enable_rag(documents=None, **kwargs)disable_rag()add_document(path: str) -> bool
Configuration
update_config(**kwargs)get_stats() -> Dictdisplay_stats(stats=None)start_interactive_session()
SimpleChat Methods
ask(question: str) -> str- Ask question, get responseask_stream(question: str)- Ask question, stream responseclear_memory()- Clear conversation memoryget_conversation() -> List[Dict]- Get conversation history
ChatSession Methods
create_session(id, config=None, **kwargs) -> ChatSDK- Create new sessionget_session(id) -> ChatSDK- Get existing sessiondelete_session(id) -> bool- Delete sessionlist_sessions() -> List[str]- List all sessionsclear_all_sessions()- Delete all sessions
Utility Functions
quick_chat(message, system_prompt=None, model=None, assistant_name=None) -> strquick_chat_with_memory(messages, system_prompt=None, model=None, assistant_name=None) -> List[str]
Best Practices
Choose the Right Interface
SimpleChat for basic needs, ChatSDK for full features, ChatSession for multi-context appsMemory Management
Configure
max_history_length based on memory constraintsPerformance
Enable
show_stats=True during developmentError Handling
Wrap chat operations in try-catch blocks
Resource Cleanup
Clear sessions when done to free memory
Assistant Naming
Use meaningful names for distinct use cases
Next Steps
Voice Interaction
Add speech recognition and text-to-speech
CLI Reference
Explore all command-line options
Development Guide
Learn to build custom agents
API Server
Integrate via OpenAI-compatible API