refactor: 简化会话创建请求结构

移除会话策略和代理配置相关字段,仅保留标题和描述。会话现在作为独立的对话容器,配置由自定义代理在查询时动态提供。
This commit is contained in:
wizardchen
2025-12-31 14:19:10 +08:00
committed by lyingbug
parent d954ba22af
commit c5228acbab
4 changed files with 21 additions and 116 deletions
+2 -19
View File
@@ -111,25 +111,8 @@ func ExampleUsage() {
// 4. Create a session
fmt.Println("\n4. Creating session...")
sessionRequest := &CreateSessionRequest{
KnowledgeBaseID: createdKB.ID,
SessionStrategy: &SessionStrategy{
MaxRounds: 10,
EnableRewrite: true,
FallbackStrategy: "fixed_answer",
FallbackResponse: "Sorry, I cannot answer this question",
EmbeddingTopK: 5,
KeywordThreshold: 0.5,
VectorThreshold: 0.7,
RerankModelID: "rerank_model_id",
RerankTopK: 3,
RerankThreshold: 0.8,
SummaryModelID: "summary_model_id",
SummaryParameters: &SummaryConfig{
Temperature: 0.7,
TopP: 0.9,
MaxTokens: 100,
},
},
Title: "Test Session",
Description: "A test session for knowledge Q&A",
}
session, err := apiClient.CreateSession(context.Background(), sessionRequest)
+10 -57
View File
@@ -16,23 +16,6 @@ import (
"strings"
)
// SessionStrategy defines session strategy
type SessionStrategy struct {
MaxRounds int `json:"max_rounds"` // Maximum number of rounds to maintain
EnableRewrite bool `json:"enable_rewrite"` // Enable query rewrite
FallbackStrategy string `json:"fallback_strategy"` // Fallback strategy
FallbackResponse string `json:"fallback_response"` // Fixed fallback response content
EmbeddingTopK int `json:"embedding_top_k"` // Top K for vector retrieval
KeywordThreshold float64 `json:"keyword_threshold"` // Keyword retrieval threshold
VectorThreshold float64 `json:"vector_threshold"` // Vector retrieval threshold
RerankModelID string `json:"rerank_model_id"` // Rerank model ID
RerankTopK int `json:"rerank_top_k"` // Top K for reranking
RerankThreshold float64 `json:"reranking_threshold"` // Reranking threshold
SummaryModelID string `json:"summary_model_id"` // Summary model ID
SummaryParameters *SummaryConfig `json:"summary_parameters"` // Summary model parameters
NoMatchPrefix string `json:"no_match_prefix"` // Fallback response prefix
}
// SummaryConfig defines summary configuration
type SummaryConfig struct {
MaxTokens int `json:"max_tokens"`
@@ -50,52 +33,22 @@ type SummaryConfig struct {
Thinking *bool `json:"thinking"`
}
// SessionAgentConfig defines session-level agent configuration (matches server struct).
// Sessions only store Enabled and KnowledgeBases; other configs are read from Tenant at runtime
type SessionAgentConfig struct {
AgentModeEnabled bool `json:"agent_mode_enabled"` // Whether agent mode is enabled for this session
WebSearchEnabled bool `json:"web_search_enabled"` // Whether web search is enabled for this session
KnowledgeBases []string `json:"knowledge_bases"` // Accessible knowledge base IDs for this session
}
// CreateSessionRequest session creation request
// Sessions are now knowledge-base-independent and serve as conversation containers.
// All configuration comes from custom agent at query time.
type CreateSessionRequest struct {
KnowledgeBaseID string `json:"knowledge_base_id"` // Associated knowledge base ID (optional in agent mode)
SessionStrategy *SessionStrategy `json:"session_strategy"` // Session strategy
AgentConfig *SessionAgentConfig `json:"agent_config"` // Agent configuration (optional, for agent mode)
}
// ContextConfig configures LLM context management
type ContextConfig struct {
MaxTokens int `json:"max_tokens"` // Maximum tokens allowed in LLM context
CompressionStrategy string `json:"compression_strategy"` // Compression strategy: "sliding_window" or "smart"
RecentMessageCount int `json:"recent_message_count"` // Number of recent messages to keep
SummarizeThreshold int `json:"summarize_threshold"` // Number of messages before summarization
Title string `json:"title"` // Session title (optional)
Description string `json:"description"` // Session description (optional)
}
// Session session information
type Session struct {
ID string `json:"id"`
TenantID uint64 `json:"tenant_id"`
KnowledgeBaseID string `json:"knowledge_base_id"`
Title string `json:"title"`
Description string `json:"description"`
MaxRounds int `json:"max_rounds"`
EnableRewrite bool `json:"enable_rewrite"`
FallbackStrategy string `json:"fallback_strategy"`
FallbackResponse string `json:"fallback_response"`
EmbeddingTopK int `json:"embedding_top_k"`
KeywordThreshold float64 `json:"keyword_threshold"`
VectorThreshold float64 `json:"vector_threshold"`
RerankModelID string `json:"rerank_model_id"`
RerankTopK int `json:"rerank_top_k"`
RerankThreshold float64 `json:"rerank_threshold"` // Reranking threshold
SummaryModelID string `json:"summary_model_id"`
SummaryParameters *SummaryConfig `json:"summary_parameters"`
AgentConfig *SessionAgentConfig `json:"agent_config"` // Agent configuration (optional)
ContextConfig *ContextConfig `json:"context_config"` // Context management configuration (optional)
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
ID string `json:"id"`
TenantID uint64 `json:"tenant_id"`
Title string `json:"title"`
Description string `json:"description"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
// SessionResponse session response
+4 -3
View File
@@ -71,10 +71,9 @@ func (h *Handler) CreateSession(c *gin.Context) {
return
}
// Validate session creation request
// Sessions are now knowledge-base-independent:
// - All configuration comes from custom agent at query time
// - Session only stores basic info (tenant ID, title, etc.)
// - Session only stores basic info (tenant ID, title, description)
logger.Infof(
ctx,
"Processing session creation request, tenant ID: %d",
@@ -83,7 +82,9 @@ func (h *Handler) CreateSession(c *gin.Context) {
// Create session object with base properties
createdSession := &types.Session{
TenantID: tenantID.(uint64),
TenantID: tenantID.(uint64),
Title: request.Title,
Description: request.Description,
}
// Call service to create session
+5 -37
View File
@@ -4,46 +4,14 @@ import (
"github.com/Tencent/WeKnora/internal/types"
)
// SessionStrategy defines the configuration for a conversation session strategy
type SessionStrategy struct {
// Maximum number of conversation rounds to maintain
MaxRounds int `json:"max_rounds"`
// Whether to enable query rewrite for multi-round conversations
EnableRewrite bool `json:"enable_rewrite"`
// Strategy to use when no relevant knowledge is found
FallbackStrategy types.FallbackStrategy `json:"fallback_strategy"`
// Fixed response content for fallback
FallbackResponse string `json:"fallback_response"`
// Number of top results to retrieve from vector search
EmbeddingTopK int `json:"embedding_top_k"`
// Threshold for keyword-based retrieval
KeywordThreshold float64 `json:"keyword_threshold"`
// Threshold for vector-based retrieval
VectorThreshold float64 `json:"vector_threshold"`
// ID of the model used for reranking results
RerankModelID string `json:"rerank_model_id"`
// Number of top results after reranking
RerankTopK int `json:"rerank_top_k"`
// Threshold for reranking results
RerankThreshold float64 `json:"rerank_threshold"`
// ID of the model used for summarization
SummaryModelID string `json:"summary_model_id"`
// Parameters for the summary model
SummaryParameters *types.SummaryConfig `json:"summary_parameters" gorm:"type:json"`
// Prefix for responses when no match is found
NoMatchPrefix string `json:"no_match_prefix"`
}
// CreateSessionRequest represents a request to create a new session
// Sessions are now knowledge-base-independent and serve as conversation containers.
// Knowledge bases can be specified dynamically in each query request (AgentQA/KnowledgeQA).
// All configuration (knowledge bases, model settings, etc.) comes from custom agent at query time.
type CreateSessionRequest struct {
// ID of the associated knowledge base (optional, can be set/changed during queries)
KnowledgeBaseID string `json:"knowledge_base_id"`
// Session strategy configuration
SessionStrategy *SessionStrategy `json:"session_strategy"`
// Agent configuration (optional, session-level config only: enabled and knowledge_bases)
AgentConfig *types.SessionAgentConfig `json:"agent_config"`
// Title for the session (optional)
Title string `json:"title"`
// Description for the session (optional)
Description string `json:"description"`
}
// GenerateTitleRequest defines the request structure for generating a session title