class ChatConfiguration
A dataclass that stores configuration settings for a chat interface integrated with a RAG (Retrieval-Augmented Generation) engine, managing search parameters, data sources, and model settings.
/tf/active/vicechatdev/vice_ai/models.py
30 - 137
moderate
Purpose
ChatConfiguration serves as a centralized configuration container for chat interfaces that use RAG engines. It manages settings for document retrieval (collections, search thresholds, topK results), search behavior (web search, extensive search, memory), filtering options (keyword and reference filtering), and LLM parameters (model, temperature, tokens). The class provides backward compatibility with legacy field names and includes methods for serialization/deserialization to/from dictionaries. It's designed to match RAG engine defaults and can be persisted or transmitted between components.
Source Code
class ChatConfiguration:
"""Configuration for chat interface linked to a text section - matches RAG engine defaults"""
# Data sources
collections: List[str] = None
# Core RAG engine settings (matching flow_control defaults)
enableSearch: bool = True
enableWebSearch: bool = False
enableMemory: bool = False # RAG default is false
enableExtensiveSearch: bool = False
topK: int = 5
searchThreshold: float = 0.7
detailLevel: str = "balanced" # "Balanced" -> "balanced"
maxSources: int = 10
targetSummaryTokens: int = 8000 # matches RAG default
extensiveChunks: int = 100 # matches RAG default extensive_search_chunks
summaryTokens: int = 5000
# Keyword and reference filtering (matching RAG defaults)
enableKeywordFiltering: bool = False
enableReferenceFiltering: bool = True
referenceThreshold: float = 0.3 # matches RAG relevance_threshold
manualKeywords: List[str] = None
# Instructions
detailedInstructions: str = ""
instructionTemplate: str = ""
# Legacy fields (keep for backward compatibility but with RAG-aligned defaults)
system_prompt: str = ""
model: str = "gpt-4o" # matches RAG actual model
temperature: float = 0.0 # matches RAG default temp
max_tokens: int = 4000 # more reasonable default
context_window: int = 10
auto_save: bool = True
reference_mode: str = "citations"
selected_collections: List[str] = None # alias for collections
uploaded_documents: List[str] = None
use_reranking: bool = False
min_score: float = 0.5
diversity_threshold: float = 0.8
system_instructions: str = "" # legacy
detailed_instructions: str = "" # legacy
def __post_init__(self):
if self.collections is None:
self.collections = []
if self.selected_collections is None:
self.selected_collections = []
if self.uploaded_documents is None:
self.uploaded_documents = []
if self.manualKeywords is None:
self.manualKeywords = []
def to_dict(self) -> Dict:
return asdict(self)
@classmethod
def from_dict(cls, data: Dict) -> 'ChatConfiguration':
"""Create ChatConfiguration from dict with backward compatibility"""
# Handle backward compatibility and field name mapping
converted_data = {}
# Field mappings from old names to new names
field_mappings = {
'enable_search': 'enableSearch',
'enable_web_search': 'enableWebSearch',
'enable_memory': 'enableMemory',
'enable_extensive_search': 'enableExtensiveSearch',
'top_k': 'topK',
'search_threshold': 'searchThreshold',
'detail_level': 'detailLevel',
'max_sources': 'maxSources',
'target_summary_tokens': 'targetSummaryTokens',
'extensive_chunks': 'extensiveChunks',
'summary_tokens': 'summaryTokens',
'enable_keyword_filtering': 'enableKeywordFiltering',
'enable_reference_filtering': 'enableReferenceFiltering',
'reference_threshold': 'referenceThreshold',
'manual_keywords': 'manualKeywords',
'detailed_instructions': 'detailedInstructions',
'instruction_template': 'instructionTemplate'
}
# Get valid field names for ChatConfiguration
import inspect
valid_fields = set(inspect.signature(cls).parameters.keys())
# Convert old field names to new field names
for old_key, new_key in field_mappings.items():
if old_key in data and new_key in valid_fields:
converted_data[new_key] = data[old_key]
elif new_key in data and new_key in valid_fields:
converted_data[new_key] = data[new_key]
# Handle collections field (prioritize 'collections' over 'selected_collections')
if 'collections' in valid_fields:
if 'collections' in data:
converted_data['collections'] = data['collections']
elif 'selected_collections' in data:
converted_data['collections'] = data['selected_collections']
# Copy remaining fields directly (only if they're valid)
for key, value in data.items():
if key not in field_mappings and key != 'selected_collections' and key in valid_fields:
converted_data[key] = value
return cls(**converted_data)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
- | - |
Parameter Details
collections: List of collection names/IDs to search within. Defaults to empty list if None. Primary field for specifying data sources.
enableSearch: Boolean flag to enable/disable search functionality. Default is True.
enableWebSearch: Boolean flag to enable/disable web search capabilities. Default is False.
enableMemory: Boolean flag to enable/disable conversation memory. Default is False to match RAG defaults.
enableExtensiveSearch: Boolean flag to enable/disable extensive search mode for deeper retrieval. Default is False.
topK: Integer specifying the number of top results to retrieve from search. Default is 5.
searchThreshold: Float threshold (0.0-1.0) for minimum similarity score in search results. Default is 0.7.
detailLevel: String indicating the level of detail in responses. Default is 'balanced'. Expected values: 'balanced', 'concise', 'detailed'.
maxSources: Maximum number of sources to include in responses. Default is 10.
targetSummaryTokens: Target token count for generated summaries. Default is 8000 to match RAG defaults.
extensiveChunks: Number of chunks to retrieve in extensive search mode. Default is 100.
summaryTokens: Token budget for summary generation. Default is 5000.
enableKeywordFiltering: Boolean to enable/disable keyword-based filtering of results. Default is False.
enableReferenceFiltering: Boolean to enable/disable reference-based filtering. Default is True.
referenceThreshold: Float threshold (0.0-1.0) for reference relevance filtering. Default is 0.3.
manualKeywords: List of manually specified keywords for filtering. Defaults to empty list if None.
detailedInstructions: String containing detailed instructions for the chat behavior. Default is empty string.
instructionTemplate: String template for formatting instructions. Default is empty string.
system_prompt: Legacy field for system-level prompts. Default is empty string.
model: LLM model identifier. Default is 'gpt-4o' to match RAG defaults.
temperature: Float (0.0-2.0) controlling randomness in model responses. Default is 0.0 for deterministic output.
max_tokens: Maximum tokens in model response. Default is 4000.
context_window: Number of previous messages to include in context. Default is 10.
auto_save: Boolean to enable/disable automatic saving of chat state. Default is True.
reference_mode: String specifying how references are displayed. Default is 'citations'. Expected values: 'citations', 'inline', 'footnotes'.
selected_collections: Legacy alias for 'collections' field. Maintained for backward compatibility.
uploaded_documents: List of uploaded document identifiers. Defaults to empty list if None.
use_reranking: Boolean to enable/disable result reranking. Default is False.
min_score: Minimum score threshold for including results. Default is 0.5.
diversity_threshold: Float threshold for result diversity filtering. Default is 0.8.
system_instructions: Legacy field for system instructions. Default is empty string.
detailed_instructions: Legacy field for detailed instructions. Default is empty string.
Return Value
Instantiation returns a ChatConfiguration object with all configuration attributes initialized. The to_dict() method returns a Dict containing all configuration fields as key-value pairs. The from_dict() class method returns a new ChatConfiguration instance created from a dictionary, handling backward compatibility with legacy field names.
Class Interface
Methods
__post_init__(self) -> None
Purpose: Initializes list attributes to empty lists if they are None, called automatically after dataclass __init__
Returns: None. Modifies instance attributes in-place.
to_dict(self) -> Dict
Purpose: Converts the ChatConfiguration instance to a dictionary representation for serialization
Returns: Dictionary containing all configuration fields as key-value pairs
from_dict(cls, data: Dict) -> ChatConfiguration
Purpose: Creates a ChatConfiguration instance from a dictionary with backward compatibility for legacy field names
Parameters:
data: Dictionary containing configuration data. Supports both old snake_case and new camelCase field names.
Returns: New ChatConfiguration instance with fields populated from the input dictionary
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
collections |
List[str] | List of collection names/IDs to search within | instance |
enableSearch |
bool | Flag to enable/disable search functionality | instance |
enableWebSearch |
bool | Flag to enable/disable web search capabilities | instance |
enableMemory |
bool | Flag to enable/disable conversation memory | instance |
enableExtensiveSearch |
bool | Flag to enable/disable extensive search mode | instance |
topK |
int | Number of top results to retrieve from search | instance |
searchThreshold |
float | Minimum similarity score threshold for search results | instance |
detailLevel |
str | Level of detail in responses (balanced, concise, detailed) | instance |
maxSources |
int | Maximum number of sources to include in responses | instance |
targetSummaryTokens |
int | Target token count for generated summaries | instance |
extensiveChunks |
int | Number of chunks to retrieve in extensive search mode | instance |
summaryTokens |
int | Token budget for summary generation | instance |
enableKeywordFiltering |
bool | Flag to enable/disable keyword-based filtering | instance |
enableReferenceFiltering |
bool | Flag to enable/disable reference-based filtering | instance |
referenceThreshold |
float | Threshold for reference relevance filtering | instance |
manualKeywords |
List[str] | List of manually specified keywords for filtering | instance |
detailedInstructions |
str | Detailed instructions for chat behavior | instance |
instructionTemplate |
str | Template for formatting instructions | instance |
system_prompt |
str | Legacy field for system-level prompts | instance |
model |
str | LLM model identifier (e.g., gpt-4o) | instance |
temperature |
float | Controls randomness in model responses (0.0-2.0) | instance |
max_tokens |
int | Maximum tokens in model response | instance |
context_window |
int | Number of previous messages to include in context | instance |
auto_save |
bool | Flag to enable/disable automatic saving of chat state | instance |
reference_mode |
str | How references are displayed (citations, inline, footnotes) | instance |
selected_collections |
List[str] | Legacy alias for collections field | instance |
uploaded_documents |
List[str] | List of uploaded document identifiers | instance |
use_reranking |
bool | Flag to enable/disable result reranking | instance |
min_score |
float | Minimum score threshold for including results | instance |
diversity_threshold |
float | Threshold for result diversity filtering | instance |
system_instructions |
str | Legacy field for system instructions | instance |
detailed_instructions |
str | Legacy field for detailed instructions | instance |
Dependencies
dataclassestypinginspect
Required Imports
from dataclasses import dataclass, asdict
from typing import List, Dict
import inspect
Usage Example
# Create a new configuration with defaults
from dataclasses import dataclass, asdict
from typing import List, Dict
import inspect
config = ChatConfiguration()
# Create with custom settings
config = ChatConfiguration(
collections=['documents', 'research_papers'],
enableSearch=True,
enableWebSearch=True,
topK=10,
searchThreshold=0.8,
model='gpt-4o',
temperature=0.2,
detailedInstructions='Focus on technical accuracy'
)
# Convert to dictionary for serialization
config_dict = config.to_dict()
# Create from dictionary (with backward compatibility)
old_format_dict = {
'enable_search': True,
'top_k': 5,
'selected_collections': ['docs'],
'detail_level': 'balanced'
}
config_from_dict = ChatConfiguration.from_dict(old_format_dict)
# Access attributes
print(config.collections)
print(config.topK)
print(config.model)
Best Practices
- Always use from_dict() class method when deserializing from external sources to ensure backward compatibility with legacy field names.
- The __post_init__ method automatically initializes list fields to empty lists if None, preventing NoneType errors.
- Use 'collections' field instead of 'selected_collections' for new code, though both are supported for compatibility.
- The class is immutable after creation unless explicitly modified. Consider creating new instances for different configurations.
- Field names use camelCase for new fields (enableSearch, topK) but snake_case for legacy fields (system_prompt, max_tokens).
- When persisting configuration, use to_dict() to ensure all fields are captured correctly.
- The from_dict() method validates fields against the class signature, ignoring invalid fields to prevent errors.
- Default values are aligned with RAG engine defaults for consistency across the system.
- Temperature of 0.0 provides deterministic responses; increase for more creative outputs.
- The searchThreshold and referenceThreshold values should be tuned based on your data quality and retrieval needs.
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class DocChatRAG 63.6% similar
-
function process_chat_background 63.3% similar
-
function init_chat_engine_v1 62.7% similar
-
class ChatSession_v1 62.1% similar
-
function basic_rag_example 62.0% similar