feat(knowledge): add channel support to knowledge entries and related components
- Introduced a new `channel` field in the Knowledge struct and associated request types to track the source channel (e.g., "web", "api", "browser_extension"). - Updated various frontend components to display channel information and enhance user experience with channel labels. - Enhanced localization files to support channel labels in English and Chinese. - Modified backend services and database migrations to accommodate the new channel feature, ensuring consistent tracking across knowledge entries. - Refactored related functions to integrate channel handling, improving overall knowledge management and context.
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
// KnowledgeService defines the interface for knowledge services.
|
||||
type KnowledgeService interface {
|
||||
// CreateKnowledgeFromFile creates knowledge from a file.
|
||||
// tagID is optional - when provided, the file will be assigned to the specified tag/category.
|
||||
// channel identifies the ingestion channel (e.g. "web", "api", "wechat"); empty defaults to "web".
|
||||
CreateKnowledgeFromFile(
|
||||
ctx context.Context,
|
||||
kbID string,
|
||||
@@ -21,11 +21,12 @@ type KnowledgeService interface {
|
||||
enableMultimodel *bool,
|
||||
customFileName string,
|
||||
tagID string,
|
||||
channel string,
|
||||
) (*types.Knowledge, error)
|
||||
// CreateKnowledgeFromURL creates knowledge from a URL.
|
||||
// When fileName or fileType is provided (or the URL path has a known file extension),
|
||||
// the URL is treated as a direct file download instead of a web page crawl.
|
||||
// tagID is optional - when provided, the knowledge will be assigned to the specified tag/category.
|
||||
// channel identifies the ingestion channel; empty defaults to "web".
|
||||
CreateKnowledgeFromURL(
|
||||
ctx context.Context,
|
||||
kbID string,
|
||||
@@ -35,16 +36,20 @@ type KnowledgeService interface {
|
||||
enableMultimodel *bool,
|
||||
title string,
|
||||
tagID string,
|
||||
channel string,
|
||||
) (*types.Knowledge, error)
|
||||
// CreateKnowledgeFromPassage creates knowledge from text passages.
|
||||
CreateKnowledgeFromPassage(ctx context.Context, kbID string, passage []string) (*types.Knowledge, error)
|
||||
// channel identifies the ingestion channel; empty defaults to "web".
|
||||
CreateKnowledgeFromPassage(ctx context.Context, kbID string, passage []string, channel string) (*types.Knowledge, error)
|
||||
// CreateKnowledgeFromPassageSync creates knowledge from text passages and waits until chunks are indexed.
|
||||
CreateKnowledgeFromPassageSync(ctx context.Context, kbID string, passage []string) (*types.Knowledge, error)
|
||||
CreateKnowledgeFromPassageSync(ctx context.Context, kbID string, passage []string, channel string) (*types.Knowledge, error)
|
||||
// CreateKnowledgeFromManual creates or saves manual Markdown knowledge content.
|
||||
// channel identifies the ingestion channel; empty defaults to "web".
|
||||
CreateKnowledgeFromManual(
|
||||
ctx context.Context,
|
||||
kbID string,
|
||||
payload *types.ManualKnowledgePayload,
|
||||
channel string,
|
||||
) (*types.Knowledge, error)
|
||||
// GetKnowledgeByID retrieves knowledge by ID (uses tenant from context).
|
||||
GetKnowledgeByID(ctx context.Context, id string) (*types.Knowledge, error)
|
||||
|
||||
@@ -16,6 +16,20 @@ const (
|
||||
KnowledgeTypeFAQ = "faq"
|
||||
)
|
||||
|
||||
// Channel constants identify through which channel a knowledge entry was ingested.
|
||||
// Aligned with Message.Channel values ("web", "api", "im") but allows finer granularity.
|
||||
const (
|
||||
ChannelWeb = "web" // Web UI (default)
|
||||
ChannelAPI = "api" // External API call
|
||||
ChannelBrowserExtension = "browser_extension" // Browser extension / plugin
|
||||
ChannelWechat = "wechat" // WeChat
|
||||
ChannelWecom = "wecom" // WeCom (企业微信)
|
||||
ChannelFeishu = "feishu" // Feishu / Lark
|
||||
ChannelDingtalk = "dingtalk" // DingTalk
|
||||
ChannelSlack = "slack" // Slack
|
||||
ChannelIM = "im" // Generic IM channel
|
||||
)
|
||||
|
||||
// Knowledge parse status constants
|
||||
const (
|
||||
// ParseStatusPending indicates the knowledge is waiting to be processed
|
||||
@@ -69,8 +83,10 @@ type Knowledge struct {
|
||||
Title string `json:"title"`
|
||||
// Description of the knowledge
|
||||
Description string `json:"description"`
|
||||
// Source of the knowledge
|
||||
// Source of the knowledge (e.g. URL address for url type, "manual" for manual type)
|
||||
Source string `json:"source"`
|
||||
// Channel indicates through which channel the knowledge was ingested (web, api, browser_extension, wechat, etc.)
|
||||
Channel string `json:"channel" gorm:"type:varchar(50);default:'web'"`
|
||||
// Parse status of the knowledge
|
||||
ParseStatus string `json:"parse_status"`
|
||||
// Summary status for async summary generation
|
||||
@@ -148,6 +164,7 @@ type ManualKnowledgePayload struct {
|
||||
Content string `json:"content"`
|
||||
Status string `json:"status"`
|
||||
TagID string `json:"tag_id"`
|
||||
Channel string `json:"channel"`
|
||||
}
|
||||
|
||||
// KnowledgeSearchScope defines a (tenant_id, knowledge_base_id) scope for knowledge search (e.g. own KBs + shared KBs).
|
||||
@@ -271,6 +288,9 @@ func (k *Knowledge) EnsureManualDefaults() {
|
||||
if k.Source == "" {
|
||||
k.Source = KnowledgeTypeManual
|
||||
}
|
||||
if k.Channel == "" {
|
||||
k.Channel = ChannelWeb
|
||||
}
|
||||
}
|
||||
|
||||
// IsDraft returns whether the payload should be saved as draft.
|
||||
|
||||
@@ -120,6 +120,9 @@ type SearchResult struct {
|
||||
// Used to indicate the source of the knowledge, such as "url"
|
||||
KnowledgeSource string `json:"knowledge_source"`
|
||||
|
||||
// KnowledgeChannel indicates through which channel the knowledge was ingested (web, api, wechat, etc.)
|
||||
KnowledgeChannel string `json:"knowledge_channel"`
|
||||
|
||||
// ChunkMetadata stores chunk-level metadata (e.g., generated questions)
|
||||
ChunkMetadata JSON `json:"chunk_metadata,omitempty"`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user