Chat Assistant Configuration#
A chat assistant (called a Dialog in the backend) is the central configuration unit that binds an LLM, a set of knowledge bases, retrieval parameters, and behavioral feature flags together into a deployable chat interface.
Data Model#
The Dialog class in api/db/db_models.py holds all persistent configuration. Key fields:
| Field | Type | Default | Purpose |
|---|---|---|---|
llm_id | CharField(128) | tenant default | Chat model, composite model@instance@provider or UUID |
llm_setting | JSONField | {temperature:0.1, top_p:0.3, frequency_penalty:0.7, presence_penalty:0.4, max_tokens:512} | LLM generation parameters |
prompt_config | JSONField | see below | System prompt, feature flags, Tavily key |
prompt_type | CharField | "simple" | simple or advanced prompt mode |
similarity_threshold | FloatField | 0.2 | Minimum relevance score for retrieved chunks |
vector_similarity_weight | FloatField | 0.3 | Balance between vector and keyword similarity |
top_n | IntegerField | 6 | Retrieval page size |
top_k | IntegerField | 1024 | Max retrieval candidates |
kb_ids | JSONField | [] | Linked knowledge base IDs |
rerank_id | CharField(128) | — | Optional rerank model |
meta_data_filter | JSONField | {} | Document metadata filter rules |
The default prompt_config value is :
{
"system": "",
"prologue": "Hi! I'm your assistant. What can I do for you?",
"parameters": [],
"empty_response": "Sorry! No relevant content was found in the knowledge base!"
}
prompt_config Feature Flags#
All behavioral toggles live inside prompt_config (a JSON blob on the Dialog record). The frontend schema in use-chat-setting-schema.tsx documents every valid key:
| Key | Type | Purpose |
|---|---|---|
system | string (required, min 1 char) | System prompt injected into the LLM |
quote | boolean | Enables in-answer citation references |
keyword | boolean | Appends keyword extraction to the query |
tts | boolean | Text-to-speech output |
refine_multiturn | boolean | Rewrites multi-turn queries into a single question |
use_kg | boolean | Adds knowledge graph retrieval to the context |
toc_enhance | boolean (optional) | Table-of-contents enhanced retrieval |
cross_languages | string[] (optional) | Translate queries across listed languages |
reasoning | boolean (optional) | Reasoning/deep-research mode |
parameters | {key, optional}[] | Named variables interpolated into system prompt |
empty_response | string (optional) | Reply when no KB content is found |
prologue | string (optional) | Greeting message |
tavily_api_key | string (optional) | Enables real-time web search via Tavily |
reference_metadata | {include, fields} (optional) | Enriches citations with document metadata |
At runtime in dialog_service.py, these flags are read directly from dialog.prompt_config using .get() with safe defaults (e.g., prompt_config.get("quote", True), prompt_config.get("keyword", False)).
Frontend Validation (Zod Schema)#
The form schema in use-chat-setting-schema.tsx composes sub-schemas for each concern:
prompt_config— validated bypromptConfigSchema;systemis the only required string field (min length 1)name— required, min length 1dataset_ids— array (may be empty)llm_setting— validated byLlmSettingFieldSchemafrom the shared LLM settings component- Retrieval sliders —
vectorSimilarityWeightSchema,similarityThresholdSchema,topnSchemafrom shared components - Rerank —
rerankFormSchema - Metadata filter —
MetadataFilterSchema
Web Search via Tavily#
Tavily integration adds real-time web results to the retrieval context. Two things must both be true for web search to fire:
prompt_config["tavily_api_key"]must be non-empty- The
internetflag in the request must be truthy
The backend helper _should_use_web_search() enforces this — if either condition fails, it returns False. The internet flag accepts bool, int, float, or string ("true", "1", "yes", "on", etc.) via _normalize_internet_flag().
When enabled, Tavily.retrieve_chunks() is called with search_depth="advanced" and max_results=6 . Results are converted to the standard chunk format (with vector_similarity fixed at 1.0 and term_similarity at 0) and merged directly into kbinfos["chunks"] alongside knowledge base results .
Retrieval Flow (Simplified)#
async_chat()
│
├─ SQL path? (if field_map from KB) → use_sql()
│
└─ Vector path:
├─ retriever.retrieval() ← top_n, similarity_threshold, vector_similarity_weight, top_k
├─ toc_enhance? → retriever.retrieval_by_toc()
├─ Tavily (internet + tavily_api_key)? → extend chunks
└─ use_kg? → kg_retriever.retrieval()
See dialog_service.py lines 757–790 for the complete branching logic.
Key Source Files#
| File | Purpose |
|---|---|
api/db/db_models.py (Dialog) | Dialog ORM model — all persistent config fields and defaults |
api/db/services/dialog_service.py | async_chat() runtime logic, feature flag reads, web search dispatch |
web/src/pages/next-chats/chat/app-settings/use-chat-setting-schema.tsx | Zod validation schema for the settings form |
rag/utils/tavily_conn.py | Tavily client wrapper — search() + retrieve_chunks() |