feat: 支持输入框内选择知识库和文件,优化选择交互体验
This commit is contained in:
@@ -15,11 +15,13 @@ type AgentConfig struct {
|
||||
AllowedTools []string `json:"allowed_tools"` // List of allowed tool names
|
||||
Temperature float64 `json:"temperature"` // LLM temperature for agent
|
||||
KnowledgeBases []string `json:"knowledge_bases"` // Accessible knowledge base IDs
|
||||
KnowledgeIDs []string `json:"knowledge_ids"` // Accessible knowledge IDs (individual documents)
|
||||
SystemPromptWebEnabled string `json:"system_prompt_web_enabled,omitempty"` // Custom prompt when web search is enabled
|
||||
SystemPromptWebDisabled string `json:"system_prompt_web_disabled,omitempty"` // Custom prompt when web search is disabled
|
||||
UseCustomSystemPrompt bool `json:"use_custom_system_prompt"` // Whether to use custom system prompt instead of default
|
||||
WebSearchEnabled bool `json:"web_search_enabled"` // Whether web search tool is enabled
|
||||
WebSearchMaxResults int `json:"web_search_max_results"` // Maximum number of web search results (default: 5)
|
||||
SearchTargets SearchTargets `json:"-"` // Pre-computed unified search targets (runtime only)
|
||||
}
|
||||
|
||||
// SessionAgentConfig represents session-level agent configuration
|
||||
@@ -28,6 +30,7 @@ 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
|
||||
KnowledgeIDs []string `json:"knowledge_ids"` // Accessible knowledge IDs (individual documents) for this session
|
||||
}
|
||||
|
||||
// Value implements driver.Valuer interface for AgentConfig
|
||||
|
||||
@@ -8,12 +8,15 @@ type ChatManage struct {
|
||||
RewriteQuery string `json:"rewrite_query,omitempty"` // Query after rewriting for better retrieval
|
||||
History []*History `json:"history,omitempty"` // Chat history for context
|
||||
|
||||
KnowledgeBaseID string `json:"knowledge_base_id"` // ID of the knowledge base to search against (deprecated, use KnowledgeBaseIDs)
|
||||
KnowledgeBaseIDs []string `json:"knowledge_base_ids"` // IDs of knowledge bases to search (multi-KB support)
|
||||
VectorThreshold float64 `json:"vector_threshold"` // Minimum score threshold for vector search results
|
||||
KeywordThreshold float64 `json:"keyword_threshold"` // Minimum score threshold for keyword search results
|
||||
EmbeddingTopK int `json:"embedding_top_k"` // Number of top results to retrieve from embedding search
|
||||
VectorDatabase string `json:"vector_database"` // Vector database type/name to use
|
||||
KnowledgeBaseIDs []string `json:"knowledge_base_ids"` // IDs of knowledge bases to search (multi-KB support)
|
||||
KnowledgeIDs []string `json:"knowledge_ids,omitempty"` // IDs of specific files to search (optional)
|
||||
// SearchTargets is the pre-computed unified search targets
|
||||
// Computed once at request entry point, used throughout the pipeline
|
||||
SearchTargets SearchTargets `json:"-"`
|
||||
VectorThreshold float64 `json:"vector_threshold"` // Minimum score threshold for vector search results
|
||||
KeywordThreshold float64 `json:"keyword_threshold"` // Minimum score threshold for keyword search results
|
||||
EmbeddingTopK int `json:"embedding_top_k"` // Number of top results to retrieve from embedding search
|
||||
VectorDatabase string `json:"vector_database"` // Vector database type/name to use
|
||||
|
||||
RerankModelID string `json:"rerank_model_id"` // Model ID for reranking search results
|
||||
RerankTopK int `json:"rerank_top_k"` // Number of top results after reranking
|
||||
@@ -33,13 +36,15 @@ type ChatManage struct {
|
||||
RewritePromptUser string `json:"rewrite_prompt_user"` // Custom user prompt for rewrite stage
|
||||
|
||||
// Internal fields for pipeline data processing
|
||||
SearchResult []*SearchResult `json:"-"` // Results from search phase
|
||||
RerankResult []*SearchResult `json:"-"` // Results after reranking
|
||||
MergeResult []*SearchResult `json:"-"` // Final merged results after all processing
|
||||
Entity []string `json:"-"` // List of identified entities
|
||||
GraphResult *GraphData `json:"-"` // Graph data from search phase
|
||||
UserContent string `json:"-"` // Processed user content
|
||||
ChatResponse *ChatResponse `json:"-"` // Final response from chat model
|
||||
SearchResult []*SearchResult `json:"-"` // Results from search phase
|
||||
RerankResult []*SearchResult `json:"-"` // Results after reranking
|
||||
MergeResult []*SearchResult `json:"-"` // Final merged results after all processing
|
||||
Entity []string `json:"-"` // List of identified entities
|
||||
EntityKBIDs []string `json:"-"` // Knowledge base IDs with ExtractConfig enabled
|
||||
EntityKnowledge map[string]string `json:"-"` // KnowledgeID -> KnowledgeBaseID mapping for graph-enabled files
|
||||
GraphResult *GraphData `json:"-"` // Graph data from search phase
|
||||
UserContent string `json:"-"` // Processed user content
|
||||
ChatResponse *ChatResponse `json:"-"` // Final response from chat model
|
||||
|
||||
// Event system for streaming responses
|
||||
EventBus EventBusInterface `json:"-"` // EventBus for emitting streaming events
|
||||
@@ -56,12 +61,16 @@ func (c *ChatManage) Clone() *ChatManage {
|
||||
knowledgeBaseIDs := make([]string, len(c.KnowledgeBaseIDs))
|
||||
copy(knowledgeBaseIDs, c.KnowledgeBaseIDs)
|
||||
|
||||
// Deep copy knowledge IDs slice
|
||||
knowledgeIDs := make([]string, len(c.KnowledgeIDs))
|
||||
copy(knowledgeIDs, c.KnowledgeIDs)
|
||||
|
||||
return &ChatManage{
|
||||
Query: c.Query,
|
||||
RewriteQuery: c.RewriteQuery,
|
||||
SessionID: c.SessionID,
|
||||
KnowledgeBaseID: c.KnowledgeBaseID,
|
||||
KnowledgeBaseIDs: knowledgeBaseIDs,
|
||||
KnowledgeIDs: knowledgeIDs,
|
||||
VectorThreshold: c.VectorThreshold,
|
||||
KeywordThreshold: c.KeywordThreshold,
|
||||
EmbeddingTopK: c.EmbeddingTopK,
|
||||
|
||||
@@ -21,6 +21,7 @@ const (
|
||||
MatchTypeRelationChunk // 关系Chunk匹配类型
|
||||
MatchTypeGraph
|
||||
MatchTypeWebSearch // 网络搜索匹配类型
|
||||
MatchTypeDirectLoad // 直接加载匹配类型
|
||||
)
|
||||
|
||||
// IndexInfo contains information about indexed content
|
||||
|
||||
@@ -119,6 +119,8 @@ type KnowledgeService interface {
|
||||
SaveKBCloneProgress(ctx context.Context, progress *types.KBCloneProgress) error
|
||||
// GetFAQImportProgress retrieves the progress of an FAQ import task
|
||||
GetFAQImportProgress(ctx context.Context, taskID string) (*types.FAQImportProgress, error)
|
||||
// SearchKnowledge searches knowledge items by keyword across the tenant.
|
||||
SearchKnowledge(ctx context.Context, keyword string, offset, limit int) ([]*types.Knowledge, bool, error)
|
||||
}
|
||||
|
||||
// KnowledgeRepository defines the interface for knowledge repositories.
|
||||
@@ -156,4 +158,6 @@ type KnowledgeRepository interface {
|
||||
CountKnowledgeByKnowledgeBaseID(ctx context.Context, tenantID uint64, kbID string) (int64, error)
|
||||
// CountKnowledgeByStatus counts the number of knowledge items with the specified parse status.
|
||||
CountKnowledgeByStatus(ctx context.Context, tenantID uint64, kbID string, parseStatuses []string) (int64, error)
|
||||
// SearchKnowledge searches knowledge items by keyword across the tenant.
|
||||
SearchKnowledge(ctx context.Context, tenantID uint64, keyword string, offset, limit int) ([]*types.Knowledge, bool, error)
|
||||
}
|
||||
|
||||
@@ -111,6 +111,15 @@ type KnowledgeBaseRepository interface {
|
||||
// - Possible errors such as record not existing, database errors, etc.
|
||||
GetKnowledgeBaseByID(ctx context.Context, id string) (*types.KnowledgeBase, error)
|
||||
|
||||
// GetKnowledgeBaseByIDs queries knowledge bases by multiple IDs
|
||||
// Parameters:
|
||||
// - ctx: Context information
|
||||
// - ids: List of knowledge base IDs
|
||||
// Returns:
|
||||
// - List of knowledge base objects
|
||||
// - Possible errors such as database errors, etc.
|
||||
GetKnowledgeBaseByIDs(ctx context.Context, ids []string) ([]*types.KnowledgeBase, error)
|
||||
|
||||
// ListKnowledgeBases lists all knowledge bases in the system
|
||||
// Parameters:
|
||||
// - ctx: Context information
|
||||
|
||||
@@ -28,11 +28,12 @@ type SessionService interface {
|
||||
GenerateTitleAsync(ctx context.Context, session *types.Session, userQuery string, eventBus *event.EventBus)
|
||||
// KnowledgeQA performs knowledge-based question answering
|
||||
// knowledgeBaseIDs: list of knowledge base IDs to search (supports multi-KB)
|
||||
// knowledgeIDs: list of specific knowledge (file) IDs to search
|
||||
// summaryModelID: optional summary model ID override (if empty, uses session/KB default)
|
||||
// webSearchEnabled: whether to enable web search to supplement knowledge base results
|
||||
// Events are emitted through eventBus (references, answer chunks, completion)
|
||||
KnowledgeQA(ctx context.Context,
|
||||
session *types.Session, query string, knowledgeBaseIDs []string,
|
||||
session *types.Session, query string, knowledgeBaseIDs []string, knowledgeIDs []string,
|
||||
assistantMessageID string, summaryModelID string, webSearchEnabled bool, eventBus *event.EventBus,
|
||||
) error
|
||||
// KnowledgeQAByEvent performs knowledge-based question answering by event
|
||||
|
||||
@@ -103,6 +103,8 @@ type Knowledge struct {
|
||||
ErrorMessage string `json:"error_message"`
|
||||
// Deletion time of the knowledge
|
||||
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
|
||||
// Knowledge base name (not stored in database, populated on query)
|
||||
KnowledgeBaseName string `json:"knowledge_base_name" gorm:"-"`
|
||||
}
|
||||
|
||||
// GetMetadata returns the metadata as a map[string]string.
|
||||
|
||||
@@ -30,6 +30,8 @@ type RetrieveParams struct {
|
||||
Embedding []float32
|
||||
// Knowledge base IDs
|
||||
KnowledgeBaseIDs []string
|
||||
// Knowledge IDs
|
||||
KnowledgeIDs []string
|
||||
// Excluded knowledge IDs
|
||||
ExcludeKnowledgeIDs []string
|
||||
// Excluded chunk IDs
|
||||
|
||||
@@ -5,6 +5,44 @@ import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// SearchTargetType represents the type of search target
|
||||
type SearchTargetType string
|
||||
|
||||
const (
|
||||
// SearchTargetTypeKnowledgeBase - search entire knowledge base
|
||||
SearchTargetTypeKnowledgeBase SearchTargetType = "knowledge_base"
|
||||
// SearchTargetTypeKnowledge - search specific knowledge files within a knowledge base
|
||||
SearchTargetTypeKnowledge SearchTargetType = "knowledge"
|
||||
)
|
||||
|
||||
// SearchTarget represents a unified search target
|
||||
// Either search an entire knowledge base, or specific knowledge files within a knowledge base
|
||||
type SearchTarget struct {
|
||||
// Type of search target
|
||||
Type SearchTargetType `json:"type"`
|
||||
// KnowledgeBaseID is the ID of the knowledge base to search
|
||||
KnowledgeBaseID string `json:"knowledge_base_id"`
|
||||
// KnowledgeIDs is the list of specific knowledge IDs to search within the knowledge base
|
||||
// Only used when Type is SearchTargetTypeKnowledge
|
||||
KnowledgeIDs []string `json:"knowledge_ids,omitempty"`
|
||||
}
|
||||
|
||||
// SearchTargets is a list of search targets, pre-computed at request entry point
|
||||
type SearchTargets []*SearchTarget
|
||||
|
||||
// GetAllKnowledgeBaseIDs returns all unique knowledge base IDs from the search targets
|
||||
func (st SearchTargets) GetAllKnowledgeBaseIDs() []string {
|
||||
seen := make(map[string]bool)
|
||||
var result []string
|
||||
for _, t := range st {
|
||||
if !seen[t.KnowledgeBaseID] {
|
||||
seen[t.KnowledgeBaseID] = true
|
||||
result = append(result, t.KnowledgeBaseID)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// SearchResult represents the search result
|
||||
type SearchResult struct {
|
||||
// ID
|
||||
@@ -53,12 +91,13 @@ type SearchResult struct {
|
||||
|
||||
// SearchParams represents the search parameters
|
||||
type SearchParams struct {
|
||||
QueryText string `json:"query_text"`
|
||||
VectorThreshold float64 `json:"vector_threshold"`
|
||||
KeywordThreshold float64 `json:"keyword_threshold"`
|
||||
MatchCount int `json:"match_count"`
|
||||
DisableKeywordsMatch bool `json:"disable_keywords_match"`
|
||||
DisableVectorMatch bool `json:"disable_vector_match"`
|
||||
QueryText string `json:"query_text"`
|
||||
VectorThreshold float64 `json:"vector_threshold"`
|
||||
KeywordThreshold float64 `json:"keyword_threshold"`
|
||||
MatchCount int `json:"match_count"`
|
||||
DisableKeywordsMatch bool `json:"disable_keywords_match"`
|
||||
DisableVectorMatch bool `json:"disable_vector_match"`
|
||||
KnowledgeIDs []string `json:"knowledge_ids"`
|
||||
}
|
||||
|
||||
// Value implements the driver.Valuer interface, used to convert SearchResult to database value
|
||||
|
||||
Reference in New Issue
Block a user