From c5228acbab5a3c1650ed36aaf571aca79b800c85 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Wed, 31 Dec 2025 14:19:10 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=AE=80=E5=8C=96=E4=BC=9A?= =?UTF-8?q?=E8=AF=9D=E5=88=9B=E5=BB=BA=E8=AF=B7=E6=B1=82=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除会话策略和代理配置相关字段,仅保留标题和描述。会话现在作为独立的对话容器,配置由自定义代理在查询时动态提供。 --- client/example.go | 21 +-------- client/session.go | 67 +++++------------------------ internal/handler/session/handler.go | 7 +-- internal/handler/session/types.go | 42 +++--------------- 4 files changed, 21 insertions(+), 116 deletions(-) diff --git a/client/example.go b/client/example.go index 5b98bdf0..30696441 100644 --- a/client/example.go +++ b/client/example.go @@ -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) diff --git a/client/session.go b/client/session.go index 751fd348..d9979d8e 100644 --- a/client/session.go +++ b/client/session.go @@ -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 diff --git a/internal/handler/session/handler.go b/internal/handler/session/handler.go index 39ba42e9..f111f589 100644 --- a/internal/handler/session/handler.go +++ b/internal/handler/session/handler.go @@ -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 diff --git a/internal/handler/session/types.go b/internal/handler/session/types.go index 709896dc..e2a5610d 100644 --- a/internal/handler/session/types.go +++ b/internal/handler/session/types.go @@ -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