Merge branch 'master' into custom_agent
This commit is contained in:
@@ -139,7 +139,7 @@ func (t *GetDocumentInfoTool) Execute(ctx context.Context, args map[string]inter
|
||||
ListPagedChunksByKnowledgeID(ctx, t.tenantID, id, &types.Pagination{
|
||||
Page: 1,
|
||||
PageSize: 1000,
|
||||
}, []types.ChunkType{"text"}, "", "")
|
||||
}, []types.ChunkType{"text"}, "", "", "", "")
|
||||
if err != nil {
|
||||
mu.Lock()
|
||||
results[id] = &docInfo{
|
||||
|
||||
@@ -1052,7 +1052,7 @@ func (t *KnowledgeSearchTool) formatOutput(
|
||||
_, total, err := t.chunkService.GetRepository().ListPagedChunksByKnowledgeID(ctx,
|
||||
t.tenantID, result.KnowledgeID,
|
||||
&types.Pagination{Page: 1, PageSize: 1},
|
||||
[]types.ChunkType{types.ChunkTypeText}, "", "",
|
||||
[]types.ChunkType{types.ChunkTypeText}, "", "", "", "",
|
||||
)
|
||||
if err != nil {
|
||||
logger.Warnf(
|
||||
|
||||
@@ -117,7 +117,7 @@ func (t *ListKnowledgeChunksTool) Execute(ctx context.Context, args map[string]i
|
||||
}
|
||||
|
||||
chunks, total, err := t.chunkService.GetRepository().ListPagedChunksByKnowledgeID(ctx,
|
||||
t.tenantID, knowledgeID, pagination, []types.ChunkType{types.ChunkTypeText, types.ChunkTypeFAQ}, "", "")
|
||||
t.tenantID, knowledgeID, pagination, []types.ChunkType{types.ChunkTypeText, types.ChunkTypeFAQ}, "", "", "", "")
|
||||
if err != nil {
|
||||
return &types.ToolResult{
|
||||
Success: false,
|
||||
|
||||
@@ -27,7 +27,9 @@ func (r *chunkRepository) CreateChunks(ctx context.Context, chunks []*types.Chun
|
||||
for _, chunk := range chunks {
|
||||
chunk.Content = common.CleanInvalidUTF8(chunk.Content)
|
||||
}
|
||||
return r.db.WithContext(ctx).CreateInBatches(chunks, 100).Error
|
||||
// Use Select("*") to ensure all fields including zero values (IsEnabled=false, Flags=0)
|
||||
// are inserted, bypassing GORM's default value behavior for zero values
|
||||
return r.db.WithContext(ctx).Select("*").CreateInBatches(chunks, 100).Error
|
||||
}
|
||||
|
||||
// GetChunkByID retrieves a chunk by its ID and tenant ID
|
||||
@@ -78,6 +80,8 @@ func (r *chunkRepository) ListPagedChunksByKnowledgeID(
|
||||
chunkType []types.ChunkType,
|
||||
tagID string,
|
||||
keyword string,
|
||||
searchField string,
|
||||
sortOrder string,
|
||||
) ([]*types.Chunk, int64, error) {
|
||||
var chunks []*types.Chunk
|
||||
var total int64
|
||||
@@ -94,7 +98,20 @@ func (r *chunkRepository) ListPagedChunksByKnowledgeID(
|
||||
}
|
||||
if keyword != "" {
|
||||
like := "%" + keyword + "%"
|
||||
db = db.Where("(content LIKE ? OR metadata::text LIKE ?)", like, like)
|
||||
switch searchField {
|
||||
case "standard_question":
|
||||
// Search only in standard_question field of metadata
|
||||
db = db.Where("metadata->>'standard_question' ILIKE ?", like)
|
||||
case "similar_questions":
|
||||
// Search in similar_questions array of metadata
|
||||
db = db.Where("metadata->'similar_questions'::text ILIKE ?", like)
|
||||
case "answers":
|
||||
// Search in answers array of metadata
|
||||
db = db.Where("metadata->'answers'::text ILIKE ?", like)
|
||||
default:
|
||||
// Search in all fields (content and metadata)
|
||||
db = db.Where("(content ILIKE ? OR metadata::text ILIKE ?)", like, like)
|
||||
}
|
||||
}
|
||||
return db
|
||||
}
|
||||
@@ -109,8 +126,14 @@ func (r *chunkRepository) ListPagedChunksByKnowledgeID(
|
||||
// Then query the paginated data
|
||||
dataQuery := baseFilter(r.db.WithContext(ctx))
|
||||
|
||||
// Default is time descending, "asc" for time ascending
|
||||
orderClause := "updated_at DESC"
|
||||
if sortOrder == "asc" {
|
||||
orderClause = "updated_at ASC"
|
||||
}
|
||||
|
||||
if err := dataQuery.
|
||||
Order("chunk_index ASC").
|
||||
Order(orderClause).
|
||||
Offset(page.Offset()).
|
||||
Limit(page.Limit()).
|
||||
Find(&chunks).Error; err != nil {
|
||||
|
||||
@@ -40,6 +40,20 @@ func (r *knowledgeTagRepository) GetByID(ctx context.Context, tenantID uint64, i
|
||||
return &tag, nil
|
||||
}
|
||||
|
||||
// GetByIDs retrieves multiple tags by their IDs in a single query
|
||||
func (r *knowledgeTagRepository) GetByIDs(ctx context.Context, tenantID uint64, ids []string) ([]*types.KnowledgeTag, error) {
|
||||
if len(ids) == 0 {
|
||||
return []*types.KnowledgeTag{}, nil
|
||||
}
|
||||
var tags []*types.KnowledgeTag
|
||||
if err := r.db.WithContext(ctx).
|
||||
Where("tenant_id = ? AND id IN (?)", tenantID, ids).
|
||||
Find(&tags).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
// GetByName gets a knowledge tag by name
|
||||
func (r *knowledgeTagRepository) GetByName(ctx context.Context, tenantID uint64, kbID string, name string) (*types.KnowledgeTag, error) {
|
||||
var tag types.KnowledgeTag
|
||||
|
||||
@@ -345,7 +345,7 @@ func (s *agentService) getKnowledgeBaseInfos(ctx context.Context, kbIDs []string
|
||||
pageResult, err := s.knowledgeService.ListFAQEntries(ctx, kbID, &types.Pagination{
|
||||
Page: 1,
|
||||
PageSize: 10,
|
||||
}, "", "")
|
||||
}, "", "", "", "")
|
||||
if err == nil && pageResult != nil {
|
||||
docCount = int(pageResult.Total)
|
||||
if entries, ok := pageResult.Data.([]*types.FAQEntry); ok {
|
||||
|
||||
@@ -151,6 +151,8 @@ func (s *chunkService) ListPagedChunksByKnowledgeID(ctx context.Context,
|
||||
chunkType,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
)
|
||||
if err != nil {
|
||||
logger.ErrorWithFields(ctx, err, map[string]interface{}{
|
||||
|
||||
@@ -395,6 +395,15 @@ func (e *EvaluationService) EvalDataset(ctx context.Context, detail *types.Evalu
|
||||
// Prepare chat management parameters for this QA pair
|
||||
chatManage := detail.Params.Clone()
|
||||
chatManage.Query = qaPair.Question
|
||||
chatManage.RewriteQuery = qaPair.Question
|
||||
// Set knowledge base ID and search targets for this evaluation
|
||||
chatManage.KnowledgeBaseIDs = []string{knowledgeBaseID}
|
||||
chatManage.SearchTargets = types.SearchTargets{
|
||||
&types.SearchTarget{
|
||||
Type: types.SearchTargetTypeKnowledgeBase,
|
||||
KnowledgeBaseID: knowledgeBaseID,
|
||||
},
|
||||
}
|
||||
|
||||
// Execute knowledge QA pipeline
|
||||
logger.Infof(ctx, "Running knowledge QA for question: %s", qaPair.Question)
|
||||
|
||||
@@ -2548,6 +2548,8 @@ func (s *knowledgeService) CloneChunk(ctx context.Context, src, dst *types.Knowl
|
||||
chunkType,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
)
|
||||
chunkPage++
|
||||
if err != nil {
|
||||
@@ -2642,7 +2644,7 @@ func (s *knowledgeService) CloneChunk(ctx context.Context, src, dst *types.Knowl
|
||||
|
||||
// ListFAQEntries lists FAQ entries under a FAQ knowledge base.
|
||||
func (s *knowledgeService) ListFAQEntries(ctx context.Context,
|
||||
kbID string, page *types.Pagination, tagID string, keyword string,
|
||||
kbID string, page *types.Pagination, tagID string, keyword string, searchField string, sortOrder string,
|
||||
) (*types.PageResult, error) {
|
||||
if page == nil {
|
||||
page = &types.Pagination{}
|
||||
@@ -2662,11 +2664,33 @@ func (s *knowledgeService) ListFAQEntries(ctx context.Context,
|
||||
}
|
||||
chunkType := []types.ChunkType{types.ChunkTypeFAQ}
|
||||
chunks, total, err := s.chunkRepo.ListPagedChunksByKnowledgeID(
|
||||
ctx, tenantID, faqKnowledge.ID, page, chunkType, tagID, keyword,
|
||||
ctx, tenantID, faqKnowledge.ID, page, chunkType, tagID, keyword, searchField, sortOrder,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Build tag ID to name mapping for all unique tag IDs (batch query)
|
||||
tagNameMap := make(map[string]string)
|
||||
tagIDs := make([]string, 0)
|
||||
tagIDSet := make(map[string]struct{})
|
||||
for _, chunk := range chunks {
|
||||
if chunk.TagID != "" {
|
||||
if _, exists := tagIDSet[chunk.TagID]; !exists {
|
||||
tagIDSet[chunk.TagID] = struct{}{}
|
||||
tagIDs = append(tagIDs, chunk.TagID)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(tagIDs) > 0 {
|
||||
tags, err := s.tagRepo.GetByIDs(ctx, tenantID, tagIDs)
|
||||
if err == nil {
|
||||
for _, tag := range tags {
|
||||
tagNameMap[tag.ID] = tag.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kb.EnsureDefaults()
|
||||
entries := make([]*types.FAQEntry, 0, len(chunks))
|
||||
for _, chunk := range chunks {
|
||||
@@ -2674,6 +2698,10 @@ func (s *knowledgeService) ListFAQEntries(ctx context.Context,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Set tag name from mapping
|
||||
if entry.TagID != "" {
|
||||
entry.TagName = tagNameMap[entry.TagID]
|
||||
}
|
||||
entries = append(entries, entry)
|
||||
}
|
||||
return types.NewPageResult(total, page, entries), nil
|
||||
@@ -3315,6 +3343,63 @@ func (s *knowledgeService) CreateFAQEntry(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 查询TagName
|
||||
if entry.TagID != "" {
|
||||
tag, tagErr := s.tagRepo.GetByID(ctx, tenantID, entry.TagID)
|
||||
if tagErr == nil && tag != nil {
|
||||
entry.TagName = tag.Name
|
||||
}
|
||||
}
|
||||
|
||||
return entry, nil
|
||||
}
|
||||
|
||||
// GetFAQEntry retrieves a single FAQ entry by ID.
|
||||
func (s *knowledgeService) GetFAQEntry(ctx context.Context,
|
||||
kbID string, entryID string,
|
||||
) (*types.FAQEntry, error) {
|
||||
if entryID == "" {
|
||||
return nil, werrors.NewBadRequestError("条目ID不能为空")
|
||||
}
|
||||
|
||||
kb, err := s.validateFAQKnowledgeBase(ctx, kbID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
kb.EnsureDefaults()
|
||||
|
||||
tenantID := ctx.Value(types.TenantIDContextKey).(uint64)
|
||||
|
||||
// 获取chunk
|
||||
chunk, err := s.chunkService.GetChunkByID(ctx, entryID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 验证chunk属于当前知识库
|
||||
if chunk.KnowledgeBaseID != kb.ID || chunk.TenantID != tenantID {
|
||||
return nil, werrors.NewNotFoundError("FAQ条目不存在")
|
||||
}
|
||||
|
||||
// 验证是FAQ类型
|
||||
if chunk.ChunkType != types.ChunkTypeFAQ {
|
||||
return nil, werrors.NewNotFoundError("FAQ条目不存在")
|
||||
}
|
||||
|
||||
// 转换为FAQEntry返回
|
||||
entry, err := s.chunkToFAQEntry(chunk, kb)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 查询TagName
|
||||
if entry.TagID != "" {
|
||||
tag, tagErr := s.tagRepo.GetByID(ctx, tenantID, entry.TagID)
|
||||
if tagErr == nil && tag != nil {
|
||||
entry.TagName = tag.Name
|
||||
}
|
||||
}
|
||||
|
||||
return entry, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -915,24 +915,46 @@ func getTenantConversationConfig(ctx context.Context) (*types.ConversationConfig
|
||||
}
|
||||
|
||||
// SearchKnowledge performs knowledge base search without LLM summarization
|
||||
// knowledgeBaseIDs: list of knowledge base IDs to search (supports multi-KB)
|
||||
// knowledgeIDs: list of specific knowledge (file) IDs to search
|
||||
func (s *sessionService) SearchKnowledge(ctx context.Context,
|
||||
knowledgeBaseID, query string,
|
||||
knowledgeBaseIDs []string, knowledgeIDs []string, query string,
|
||||
) ([]*types.SearchResult, error) {
|
||||
logger.Info(ctx, "Start knowledge base search without LLM summary")
|
||||
logger.Infof(ctx, "Knowledge base search parameters, knowledge base ID: %s, query: %s", knowledgeBaseID, query)
|
||||
logger.Infof(ctx, "Knowledge base search parameters, knowledge base IDs: %v, knowledge IDs: %v, query: %s",
|
||||
knowledgeBaseIDs, knowledgeIDs, query)
|
||||
|
||||
// Get tenant ID from context
|
||||
tenantID, ok := ctx.Value(types.TenantIDContextKey).(uint64)
|
||||
if !ok {
|
||||
logger.Error(ctx, "Failed to get tenant ID from context")
|
||||
return nil, fmt.Errorf("tenant ID not found in context")
|
||||
}
|
||||
|
||||
// Build unified search targets (computed once, used throughout pipeline)
|
||||
searchTargets, err := s.buildSearchTargets(ctx, tenantID, knowledgeBaseIDs, knowledgeIDs)
|
||||
if err != nil {
|
||||
logger.Warnf(ctx, "Failed to build search targets: %v", err)
|
||||
}
|
||||
|
||||
if len(searchTargets) == 0 {
|
||||
logger.Warn(ctx, "No search targets available, returning empty results")
|
||||
return []*types.SearchResult{}, nil
|
||||
}
|
||||
|
||||
// Create default retrieval parameters
|
||||
chatManage := &types.ChatManage{
|
||||
Query: query,
|
||||
RewriteQuery: query,
|
||||
VectorThreshold: s.cfg.Conversation.VectorThreshold, // Use default configuration
|
||||
KeywordThreshold: s.cfg.Conversation.KeywordThreshold, // Use default configuration
|
||||
EmbeddingTopK: s.cfg.Conversation.EmbeddingTopK, // Use default configuration
|
||||
RerankTopK: s.cfg.Conversation.RerankTopK, // Use default configuration
|
||||
RerankThreshold: s.cfg.Conversation.RerankThreshold, // Use default configuration
|
||||
MaxRounds: s.cfg.Conversation.MaxRounds,
|
||||
RewritePromptSystem: s.cfg.Conversation.RewritePromptSystem,
|
||||
RewritePromptUser: s.cfg.Conversation.RewritePromptUser,
|
||||
Query: query,
|
||||
RewriteQuery: query,
|
||||
KnowledgeBaseIDs: knowledgeBaseIDs,
|
||||
KnowledgeIDs: knowledgeIDs,
|
||||
SearchTargets: searchTargets,
|
||||
VectorThreshold: s.cfg.Conversation.VectorThreshold, // Use default configuration
|
||||
KeywordThreshold: s.cfg.Conversation.KeywordThreshold, // Use default configuration
|
||||
EmbeddingTopK: s.cfg.Conversation.EmbeddingTopK, // Use default configuration
|
||||
RerankTopK: s.cfg.Conversation.RerankTopK, // Use default configuration
|
||||
RerankThreshold: s.cfg.Conversation.RerankThreshold, // Use default configuration
|
||||
MaxRounds: s.cfg.Conversation.MaxRounds,
|
||||
}
|
||||
|
||||
// Get default models
|
||||
@@ -974,7 +996,8 @@ func (s *sessionService) SearchKnowledge(ctx context.Context,
|
||||
logger.Infof(ctx, "Trigger search event list: %v", methods)
|
||||
span.SetAttributes(
|
||||
attribute.String("query", query),
|
||||
attribute.String("knowledge_base_id", knowledgeBaseID),
|
||||
attribute.StringSlice("knowledge_base_ids", knowledgeBaseIDs),
|
||||
attribute.StringSlice("knowledge_ids", knowledgeIDs),
|
||||
attribute.String("method", strings.Join(methods, ",")),
|
||||
)
|
||||
|
||||
|
||||
+10
-6
@@ -28,11 +28,13 @@ func NewFAQHandler(knowledgeService interfaces.KnowledgeService) *FAQHandler {
|
||||
// @Tags FAQ管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "知识库ID"
|
||||
// @Param page query int false "页码"
|
||||
// @Param page_size query int false "每页数量"
|
||||
// @Param tag_id query string false "标签ID筛选"
|
||||
// @Param keyword query string false "关键词搜索"
|
||||
// @Param id path string true "知识库ID"
|
||||
// @Param page query int false "页码"
|
||||
// @Param page_size query int false "每页数量"
|
||||
// @Param tag_id query string false "标签ID筛选"
|
||||
// @Param keyword query string false "关键词搜索"
|
||||
// @Param search_field query string false "搜索字段: standard_question(标准问题), similar_questions(相似问法), answers(答案), 默认搜索全部"
|
||||
// @Param sort_order query string false "排序方式: asc(按更新时间正序), 默认按更新时间倒序"
|
||||
// @Success 200 {object} map[string]interface{} "FAQ列表"
|
||||
// @Failure 400 {object} errors.AppError "请求参数错误"
|
||||
// @Security Bearer
|
||||
@@ -49,8 +51,10 @@ func (h *FAQHandler) ListEntries(c *gin.Context) {
|
||||
|
||||
tagID := secutils.SanitizeForLog(c.Query("tag_id"))
|
||||
keyword := secutils.SanitizeForLog(c.Query("keyword"))
|
||||
searchField := secutils.SanitizeForLog(c.Query("search_field"))
|
||||
sortOrder := secutils.SanitizeForLog(c.Query("sort_order"))
|
||||
|
||||
result, err := h.knowledgeService.ListFAQEntries(ctx, secutils.SanitizeForLog(c.Param("id")), &page, tagID, keyword)
|
||||
result, err := h.knowledgeService.ListFAQEntries(ctx, secutils.SanitizeForLog(c.Param("id")), &page, tagID, keyword, searchField, sortOrder)
|
||||
if err != nil {
|
||||
logger.ErrorWithFields(ctx, err, nil)
|
||||
c.Error(err)
|
||||
|
||||
@@ -297,18 +297,38 @@ func (h *Handler) SearchKnowledge(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if request.KnowledgeBaseID == "" {
|
||||
logger.Error(ctx, "Knowledge base ID is empty")
|
||||
c.Error(errors.NewBadRequestError("Knowledge base ID cannot be empty"))
|
||||
// Merge single knowledge_base_id into knowledge_base_ids for backward compatibility
|
||||
knowledgeBaseIDs := request.KnowledgeBaseIDs
|
||||
if request.KnowledgeBaseID != "" {
|
||||
// Check if it's already in the list to avoid duplicates
|
||||
found := false
|
||||
for _, id := range knowledgeBaseIDs {
|
||||
if id == request.KnowledgeBaseID {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
knowledgeBaseIDs = append(knowledgeBaseIDs, request.KnowledgeBaseID)
|
||||
}
|
||||
}
|
||||
|
||||
if len(knowledgeBaseIDs) == 0 && len(request.KnowledgeIDs) == 0 {
|
||||
logger.Error(ctx, "No knowledge base IDs or knowledge IDs provided")
|
||||
c.Error(errors.NewBadRequestError("At least one knowledge_base_id, knowledge_base_ids or knowledge_ids must be provided"))
|
||||
return
|
||||
}
|
||||
|
||||
logger.Infof(ctx, "Knowledge search request, knowledge base ID: %s, query: %s",
|
||||
secutils.SanitizeForLog(request.KnowledgeBaseID),
|
||||
secutils.SanitizeForLog(request.Query))
|
||||
logger.Infof(
|
||||
ctx,
|
||||
"Knowledge search request, knowledge base IDs: %v, knowledge IDs: %v, query: %s",
|
||||
secutils.SanitizeForLogArray(knowledgeBaseIDs),
|
||||
secutils.SanitizeForLogArray(request.KnowledgeIDs),
|
||||
secutils.SanitizeForLog(request.Query),
|
||||
)
|
||||
|
||||
// Perform search
|
||||
searchResults, err := h.sessionService.SearchKnowledge(ctx, request.KnowledgeBaseID, request.Query)
|
||||
// Directly call knowledge retrieval service without LLM summarization
|
||||
searchResults, err := h.sessionService.SearchKnowledge(ctx, knowledgeBaseIDs, request.KnowledgeIDs, request.Query)
|
||||
if err != nil {
|
||||
logger.ErrorWithFields(ctx, err, nil)
|
||||
c.Error(errors.NewInternalServerError(err.Error()))
|
||||
|
||||
@@ -73,8 +73,10 @@ type CreateKnowledgeQARequest struct {
|
||||
|
||||
// SearchKnowledgeRequest defines the request structure for searching knowledge without LLM summarization
|
||||
type SearchKnowledgeRequest struct {
|
||||
Query string `json:"query" binding:"required"` // Query text to search for
|
||||
KnowledgeBaseID string `json:"knowledge_base_id" binding:"required"` // ID of the knowledge base to search
|
||||
Query string `json:"query" binding:"required"` // Query text to search for
|
||||
KnowledgeBaseID string `json:"knowledge_base_id"` // Single knowledge base ID (for backward compatibility)
|
||||
KnowledgeBaseIDs []string `json:"knowledge_base_ids"` // IDs of knowledge bases to search (multi-KB support)
|
||||
KnowledgeIDs []string `json:"knowledge_ids"` // IDs of specific knowledge (files) to search
|
||||
}
|
||||
|
||||
// StopSessionRequest represents the stop session request
|
||||
|
||||
@@ -65,12 +65,27 @@ func (c *ChatManage) Clone() *ChatManage {
|
||||
knowledgeIDs := make([]string, len(c.KnowledgeIDs))
|
||||
copy(knowledgeIDs, c.KnowledgeIDs)
|
||||
|
||||
// Deep copy search targets slice
|
||||
searchTargets := make(SearchTargets, len(c.SearchTargets))
|
||||
for i, t := range c.SearchTargets {
|
||||
if t != nil {
|
||||
kidsCopy := make([]string, len(t.KnowledgeIDs))
|
||||
copy(kidsCopy, t.KnowledgeIDs)
|
||||
searchTargets[i] = &SearchTarget{
|
||||
Type: t.Type,
|
||||
KnowledgeBaseID: t.KnowledgeBaseID,
|
||||
KnowledgeIDs: kidsCopy,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &ChatManage{
|
||||
Query: c.Query,
|
||||
RewriteQuery: c.RewriteQuery,
|
||||
SessionID: c.SessionID,
|
||||
KnowledgeBaseIDs: knowledgeBaseIDs,
|
||||
KnowledgeIDs: knowledgeIDs,
|
||||
SearchTargets: searchTargets,
|
||||
VectorThreshold: c.VectorThreshold,
|
||||
KeywordThreshold: c.KeywordThreshold,
|
||||
EmbeddingTopK: c.EmbeddingTopK,
|
||||
@@ -101,6 +116,7 @@ func (c *ChatManage) Clone() *ChatManage {
|
||||
RewritePromptUser: c.RewritePromptUser,
|
||||
EnableRewrite: c.EnableRewrite,
|
||||
EnableQueryExpansion: c.EnableQueryExpansion,
|
||||
TenantID: c.TenantID,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -180,6 +180,7 @@ type FAQEntry struct {
|
||||
KnowledgeID string `json:"knowledge_id"`
|
||||
KnowledgeBaseID string `json:"knowledge_base_id"`
|
||||
TagID string `json:"tag_id"`
|
||||
TagName string `json:"tag_name"`
|
||||
IsEnabled bool `json:"is_enabled"`
|
||||
IsRecommended bool `json:"is_recommended"`
|
||||
StandardQuestion string `json:"standard_question"`
|
||||
|
||||
@@ -18,6 +18,8 @@ type ChunkRepository interface {
|
||||
ListChunksByKnowledgeID(ctx context.Context, tenantID uint64, knowledgeID string) ([]*types.Chunk, error)
|
||||
// ListPagedChunksByKnowledgeID lists paged chunks by knowledge id.
|
||||
// When tagID is non-empty, results are filtered by tag_id.
|
||||
// sortOrder: "asc" for time ascending (updated_at ASC), default is time descending (updated_at DESC)
|
||||
// searchField: specifies which field to search in (for FAQ: "standard_question", "similar_questions", "answers", "" for all)
|
||||
ListPagedChunksByKnowledgeID(
|
||||
ctx context.Context,
|
||||
tenantID uint64,
|
||||
@@ -26,6 +28,8 @@ type ChunkRepository interface {
|
||||
chunkType []types.ChunkType,
|
||||
tagID string,
|
||||
keyword string,
|
||||
searchField string,
|
||||
sortOrder string,
|
||||
) ([]*types.Chunk, int64, error)
|
||||
ListChunkByParentID(ctx context.Context, tenantID uint64, parentID string) ([]*types.Chunk, error)
|
||||
// UpdateChunk updates a chunk
|
||||
|
||||
@@ -74,12 +74,16 @@ type KnowledgeService interface {
|
||||
UpdateImageInfo(ctx context.Context, knowledgeID string, chunkID string, imageInfo string) error
|
||||
// ListFAQEntries lists FAQ entries under a FAQ knowledge base.
|
||||
// When tagID is non-empty, results are filtered by tag_id on FAQ chunks.
|
||||
// searchField: specifies which field to search in ("standard_question", "similar_questions", "answers", "" for all)
|
||||
// sortOrder: "asc" for time ascending (updated_at ASC), default is time descending (updated_at DESC)
|
||||
ListFAQEntries(
|
||||
ctx context.Context,
|
||||
kbID string,
|
||||
page *types.Pagination,
|
||||
tagID string,
|
||||
keyword string,
|
||||
searchField string,
|
||||
sortOrder string,
|
||||
) (*types.PageResult, error)
|
||||
// UpsertFAQEntries imports or appends FAQ entries asynchronously.
|
||||
// Returns task ID (Knowledge ID) for tracking import progress.
|
||||
|
||||
@@ -41,7 +41,9 @@ type SessionService interface {
|
||||
// KnowledgeQAByEvent performs knowledge-based question answering by event
|
||||
KnowledgeQAByEvent(ctx context.Context, chatManage *types.ChatManage, eventList []types.EventType) error
|
||||
// SearchKnowledge performs knowledge-based search, without summarization
|
||||
SearchKnowledge(ctx context.Context, knowledgeBaseID, query string) ([]*types.SearchResult, error)
|
||||
// knowledgeBaseIDs: list of knowledge base IDs to search (supports multi-KB)
|
||||
// knowledgeIDs: list of specific knowledge (file) IDs to search
|
||||
SearchKnowledge(ctx context.Context, knowledgeBaseIDs []string, knowledgeIDs []string, query string) ([]*types.SearchResult, error)
|
||||
// AgentQA performs agent-based question answering with conversation history and streaming support
|
||||
// eventBus is optional - if nil, uses service's default EventBus
|
||||
// customAgent is optional - if provided, uses custom agent configuration instead of tenant defaults
|
||||
|
||||
@@ -26,6 +26,8 @@ type KnowledgeTagRepository interface {
|
||||
Create(ctx context.Context, tag *types.KnowledgeTag) error
|
||||
Update(ctx context.Context, tag *types.KnowledgeTag) error
|
||||
GetByID(ctx context.Context, tenantID uint64, id string) (*types.KnowledgeTag, error)
|
||||
// GetByIDs retrieves multiple tags by their IDs in a single query.
|
||||
GetByIDs(ctx context.Context, tenantID uint64, ids []string) ([]*types.KnowledgeTag, error)
|
||||
GetByName(ctx context.Context, tenantID uint64, kbID string, name string) (*types.KnowledgeTag, error)
|
||||
ListByKB(
|
||||
ctx context.Context,
|
||||
|
||||
Reference in New Issue
Block a user