refactor: Update wiki prompts and ingestion logic for improved content handling
- Renamed `WikiPageUpdatePrompt` to `WikiPageModifyPrompt` to better reflect its functionality of adding new information and removing outdated content in a single operation. - Enhanced the instructions for both `WikiPageModifyPrompt` and `WikiPageRetractPrompt` to clarify the handling of additions and retractions, ensuring accurate content updates. - Consolidated the logic for enqueuing retraction tasks in the `cleanupWikiOnKnowledgeDelete` method to streamline the process of managing affected pages. - Removed the `rebuildWikiIndexSimple` function to simplify the codebase, as its functionality is no longer needed with the new ingestion approach. These changes improve the clarity and efficiency of the wiki content management process, enhancing overall system performance.
This commit is contained in:
@@ -1327,8 +1327,10 @@ func (s *knowledgeService) cleanupWikiOnKnowledgeDelete(ctx context.Context, kbI
|
||||
len(deletedSlugs), knowledgeID, deletedSlugs)
|
||||
}
|
||||
|
||||
// Enqueue async LLM retraction for multi-source pages
|
||||
if len(retractSlugs) > 0 {
|
||||
allAffectedSlugs := append(retractSlugs, deletedSlugs...)
|
||||
|
||||
// Enqueue async LLM retraction and index rebuild
|
||||
if len(allAffectedSlugs) > 0 {
|
||||
lang, _ := types.LanguageFromContext(ctx)
|
||||
tenantID, _ := types.TenantIDFromContext(ctx)
|
||||
EnqueueWikiRetract(ctx, s.task, s.redisClient, WikiRetractPayload{
|
||||
@@ -1338,16 +1340,9 @@ func (s *knowledgeService) cleanupWikiOnKnowledgeDelete(ctx context.Context, kbI
|
||||
DocTitle: docTitle,
|
||||
DocSummary: docSummary,
|
||||
Language: lang,
|
||||
PageSlugs: retractSlugs,
|
||||
PageSlugs: allAffectedSlugs,
|
||||
})
|
||||
logger.Infof(ctx, "wiki cleanup: enqueued retract task for %d pages: %v", len(retractSlugs), retractSlugs)
|
||||
}
|
||||
|
||||
// If pages were deleted but no retract task was enqueued,
|
||||
// we still need to update the index and log synchronously.
|
||||
// (When retractSlugs > 0, ProcessWikiRetract handles index/log.)
|
||||
if len(deletedSlugs) > 0 && len(retractSlugs) == 0 {
|
||||
s.rebuildWikiIndexSimple(ctx, kbID, knowledgeID, docTitle, deletedSlugs)
|
||||
logger.Infof(ctx, "wiki cleanup: enqueued retract task for %d pages: %v", len(allAffectedSlugs), allAffectedSlugs)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1365,81 +1360,6 @@ func removeSourceRef(refs types.StringArray, knowledgeID string) types.StringArr
|
||||
return result
|
||||
}
|
||||
|
||||
// rebuildWikiIndexSimple regenerates the index page from current page listing
|
||||
// and appends a deletion log entry. Does NOT use LLM — generates a simple
|
||||
// structured listing while preserving the LLM-generated intro from Summary field.
|
||||
func (s *knowledgeService) rebuildWikiIndexSimple(ctx context.Context, kbID, knowledgeID, docTitle string, deletedSlugs []string) {
|
||||
// Rebuild index
|
||||
allPages, err := s.wikiService.ListAllPages(ctx, kbID)
|
||||
if err != nil {
|
||||
logger.Warnf(ctx, "wiki cleanup: failed to list pages: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
indexPage, _ := s.wikiService.GetIndex(ctx, kbID)
|
||||
if indexPage == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Preserve LLM-generated intro from Summary field
|
||||
var indexContent strings.Builder
|
||||
if indexPage.Summary != "" && indexPage.Summary != "Index" {
|
||||
indexContent.WriteString(indexPage.Summary)
|
||||
indexContent.WriteString("\n")
|
||||
} else {
|
||||
indexContent.WriteString("# Wiki Index\n\n")
|
||||
}
|
||||
|
||||
// Group pages by type
|
||||
typeOrder := []string{types.WikiPageTypeSummary, types.WikiPageTypeEntity, types.WikiPageTypeConcept, types.WikiPageTypeSynthesis, types.WikiPageTypeComparison}
|
||||
grouped := make(map[string][]*types.WikiPage)
|
||||
for _, p := range allPages {
|
||||
if p.PageType == types.WikiPageTypeIndex || p.PageType == types.WikiPageTypeLog {
|
||||
continue
|
||||
}
|
||||
if p.Status == types.WikiPageStatusArchived {
|
||||
continue
|
||||
}
|
||||
grouped[p.PageType] = append(grouped[p.PageType], p)
|
||||
}
|
||||
|
||||
for _, pt := range typeOrder {
|
||||
pages := grouped[pt]
|
||||
if len(pages) == 0 {
|
||||
continue
|
||||
}
|
||||
label := pt
|
||||
if len(label) > 0 {
|
||||
label = strings.ToUpper(label[:1]) + label[1:]
|
||||
}
|
||||
fmt.Fprintf(&indexContent, "\n## %s\n\n", label)
|
||||
for _, p := range pages {
|
||||
fmt.Fprintf(&indexContent, "- [[%s]] — %s\n", p.Slug, p.Summary)
|
||||
}
|
||||
}
|
||||
|
||||
indexPage.Content = indexContent.String()
|
||||
if _, err := s.wikiService.UpdatePage(ctx, indexPage); err != nil {
|
||||
logger.Warnf(ctx, "wiki cleanup: failed to rebuild index: %v", err)
|
||||
}
|
||||
|
||||
// Append log entry
|
||||
logPage, _ := s.wikiService.GetLog(ctx, kbID)
|
||||
if logPage != nil {
|
||||
entry := fmt.Sprintf("\n## [%s] delete | %s\n- **Source**: knowledge/%s\n- **Pages deleted**: %d (%s)\n",
|
||||
time.Now().UTC().Format("2006-01-02 15:04:05"),
|
||||
docTitle,
|
||||
knowledgeID,
|
||||
len(deletedSlugs),
|
||||
strings.Join(deletedSlugs, ", "),
|
||||
)
|
||||
logPage.Content = logPage.Content + entry
|
||||
if _, err := s.wikiService.UpdatePage(ctx, logPage); err != nil {
|
||||
logger.Warnf(ctx, "wiki cleanup: failed to update log: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteKnowledgeList deletes a knowledge entry and all related resources
|
||||
func (s *knowledgeService) DeleteKnowledgeList(ctx context.Context, ids []string) error {
|
||||
if len(ids) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user