feat(configuration): update asynq concurrency settings and enhance FAQ handling

- Increased the default worker pool size for the asynq server from 16 to 32 to improve performance during concurrent uploads.
- Updated the .env.example and docker-compose.yml files to reflect the new default concurrency setting.
- Enhanced the handling of FAQ entries in the tool results, ensuring distinct identification through standard questions, improving user experience and clarity in the output.
- Refactored related components to utilize the new FAQ attributes, ensuring consistent display and interaction across the application.
This commit is contained in:
wizardchen
2026-06-04 14:21:50 +08:00
committed by lyingbug
parent 8a3e21cd46
commit 035093dc35
14 changed files with 330 additions and 28 deletions
+24 -6
View File
@@ -258,7 +258,7 @@ func (t *GrepChunksTool) searchChunks(
query := t.db.WithContext(ctx).Table("chunks").
Select("chunks.id, chunks.content, chunks.chunk_index, chunks.knowledge_id, "+
"chunks.knowledge_base_id, chunks.chunk_type, chunks.created_at, "+
"chunks.knowledge_base_id, chunks.chunk_type, chunks.metadata, chunks.created_at, "+
"knowledges.title as knowledge_title").
Joins("JOIN knowledges ON chunks.knowledge_id = knowledges.id").
Where("chunks.is_enabled = ?", true).
@@ -375,6 +375,13 @@ func (t *GrepChunksTool) formatOutput(
counts := countRegexHits(r.Content, compiled, queries)
snippet := extractSnippetRegex(r.Content, compiled)
// FAQ entries share the owning knowledge's title, so expose the
// standard question as a per-chunk identifier when available.
faqAttr := ""
if q := faqStandardQuestion(&r.Chunk); q != "" {
faqAttr = fmt.Sprintf(" faq_question=\"%s\"", xmlEscape(q))
}
t.mu.Lock()
seen := t.seenChunks[r.ID]
t.seenChunks[r.ID] = true
@@ -382,10 +389,11 @@ func (t *GrepChunksTool) formatOutput(
if seen {
b.WriteString(fmt.Sprintf(
"<chunk chunk_id=\"%s\" knowledge_id=\"%s\" knowledge_title=\"%s\" chunk_index=\"%d\" score=\"%.3f\" already_seen=\"true\">\n",
"<chunk chunk_id=\"%s\" knowledge_id=\"%s\" knowledge_title=\"%s\"%s chunk_index=\"%d\" score=\"%.3f\" already_seen=\"true\">\n",
xmlEscape(r.ID),
xmlEscape(r.KnowledgeID),
xmlEscape(r.KnowledgeTitle),
faqAttr,
r.ChunkIndex,
r.MatchScore,
))
@@ -401,10 +409,11 @@ func (t *GrepChunksTool) formatOutput(
}
b.WriteString(fmt.Sprintf(
"<chunk chunk_id=\"%s\" knowledge_id=\"%s\" knowledge_title=\"%s\" chunk_index=\"%d\" score=\"%.3f\">\n",
"<chunk chunk_id=\"%s\" knowledge_id=\"%s\" knowledge_title=\"%s\"%s chunk_index=\"%d\" score=\"%.3f\">\n",
xmlEscape(r.ID),
xmlEscape(r.KnowledgeID),
xmlEscape(r.KnowledgeTitle),
faqAttr,
r.ChunkIndex,
r.MatchScore,
))
@@ -426,9 +435,13 @@ func (t *GrepChunksTool) formatOutput(
}
type knowledgeAggregation struct {
KnowledgeID string `json:"knowledge_id"`
KnowledgeBaseID string `json:"knowledge_base_id"`
KnowledgeTitle string `json:"knowledge_title"`
KnowledgeID string `json:"knowledge_id"`
KnowledgeBaseID string `json:"knowledge_base_id"`
KnowledgeTitle string `json:"knowledge_title"`
// FAQQuestion is the standard question of the first matched FAQ entry in
// this knowledge. FAQ entries share the owning knowledge's title, so the
// frontend uses this to give the row a distinct, human-readable label.
FAQQuestion string `json:"faq_question,omitempty"`
TitleMatch bool `json:"title_match"`
ChunkHitCount int `json:"chunk_hit_count"`
TotalChunkCount int `json:"total_chunk_count"`
@@ -484,6 +497,11 @@ func (t *GrepChunksTool) aggregateByKnowledge(
if chunk.TitleMatch {
entry.TitleMatch = true
}
if entry.FAQQuestion == "" {
if q := faqStandardQuestion(&chunk.Chunk); q != "" {
entry.FAQQuestion = q
}
}
if entry.MatchSnippet == "" {
if snippet := extractSnippetRegex(chunk.Content, compiled); snippet != "" {
entry.MatchSnippet = snippet
+30 -2
View File
@@ -230,6 +230,11 @@ func (t *ListKnowledgeChunksTool) Execute(ctx context.Context, args json.RawMess
"parent_chunk_id": c.ParentChunkID,
}
// FAQ 条目共用所属 Knowledge 的标题,补上标准问作为单条身份标识
if q := faqStandardQuestion(c); q != "" {
chunkData["faq_question"] = q
}
// 添加图片信息
if c.ImageInfo != "" {
var imageInfos []types.ImageInfo
@@ -310,8 +315,15 @@ func (t *ListKnowledgeChunksTool) buildOutput(
}
for _, c := range chunks {
fmt.Fprintf(&b, "<chunk chunk_id=\"%s\" chunk_index=\"%d\" type=\"%s\">\n",
c.ID, c.ChunkIndex, c.ChunkType)
// FAQ entries share the owning knowledge's title, so expose the
// standard question as a per-chunk identifier when available.
if q := faqStandardQuestion(c); q != "" {
fmt.Fprintf(&b, "<chunk chunk_id=\"%s\" chunk_index=\"%d\" type=\"%s\" question=\"%s\">\n",
c.ID, c.ChunkIndex, c.ChunkType, xmlEscape(q))
} else {
fmt.Fprintf(&b, "<chunk chunk_id=\"%s\" chunk_index=\"%d\" type=\"%s\">\n",
c.ID, c.ChunkIndex, c.ChunkType)
}
fmt.Fprintf(&b, "<content>%s</content>\n", summarizeContent(c.Content))
if c.ImageInfo != "" {
@@ -345,6 +357,22 @@ func (t *ListKnowledgeChunksTool) buildOutput(
return b.String()
}
// faqStandardQuestion returns the FAQ standard question for an FAQ-type chunk,
// or "" for non-FAQ chunks (or when metadata is missing/unparseable). All FAQ
// entries inside one knowledge share the same knowledge title, so surfacing the
// standard question gives each entry a distinct, human-readable identity in
// tool output that would otherwise look like duplicate same-titled chunks.
func faqStandardQuestion(c *types.Chunk) string {
if c == nil || c.ChunkType != types.ChunkTypeFAQ {
return ""
}
meta, err := c.FAQMetadata()
if err != nil || meta == nil {
return ""
}
return strings.TrimSpace(meta.StandardQuestion)
}
// summarizeContent summarizes the content of a chunk
func summarizeContent(content string) string {
cleaned := strings.TrimSpace(content)