feat: Add statistics localization and enhance knowledge base functionality

- Introduced new localization strings for document count, FAQ entries, and chunk count in English, Russian, and Chinese.
- Updated the KnowledgeBase and KnowledgeBaseList components to display knowledge and chunk counts.
- Implemented backend functions to count knowledge items and chunks associated with each knowledge base, improving data management and user insights.
This commit is contained in:
wizardchen
2025-11-21 01:39:43 +08:00
parent c678094724
commit 9e98848d69
12 changed files with 72 additions and 4 deletions
@@ -122,6 +122,29 @@ func (s *knowledgeBaseService) ListKnowledgeBases(ctx context.Context) ([]*types
return nil, err
}
// Query knowledge count and chunk count for each knowledge base
for _, kb := range kbs {
kb.EnsureDefaults()
// Get knowledge count
if kb.Type == types.KnowledgeBaseTypeDocument {
knowledgeCount, err := s.kgRepo.CountKnowledgeByKnowledgeBaseID(ctx, tenantID, kb.ID)
if err != nil {
logger.Warnf(ctx, "Failed to get knowledge count for knowledge base %s: %v", kb.ID, err)
} else {
kb.KnowledgeCount = knowledgeCount
}
} else if kb.Type == types.KnowledgeBaseTypeFAQ {
// Get chunk count
chunkCount, err := s.chunkRepo.CountChunksByKnowledgeBaseID(ctx, tenantID, kb.ID)
if err != nil {
logger.Warnf(ctx, "Failed to get chunk count for knowledge base %s: %v", kb.ID, err)
} else {
kb.ChunkCount = chunkCount
}
}
}
logger.Infof(
ctx,
"Knowledge base list retrieved successfully, tenant ID: %d, knowledge base count: %d",