Tencent/WeKnora · error
failed to list existing FAQ chunks: %w
Error message
failed to list existing FAQ chunks: %w
What it means
calculateAppendOperations wraps errors from chunkRepo.ListAllFAQChunksWithMetadataByKnowledgeBaseID when loading all existing FAQ chunks for a knowledge base before computing append/merge operations. It means the append flow could not even determine the current chunk state, so no merge plan was produced. The underlying cause (DB connectivity, table issues, context cancellation) is preserved via %w.
Source
Thrown at internal/application/service/knowledge_faq_import.go:1009
// calculateAppendOperations 计算 Append 模式下的操作(支持智能合并)。
// 如果 entry 的标准问在 KB 中已存在,则视为合并操作(相似问 / 反例并集,
// 答案 / 策略以新条目为准);否则视为新建。无变化(hash 一致且操作位
// 也未变)的合并目标会被 skip 掉,避免无效写库 / 重建索引。
//
// 内部 master 行为,对应开源版仅 "重复 = 失败" 的简化逻辑。FAQ 导入的
// 常见使用方式是"导出修改后重新 append",需要这种合并语义才能正确叠加
// 新的相似问而不丢历史数据。
func (s *knowledgeService) calculateAppendOperations(ctx context.Context,
tenantID uint64, kbID string, entries []types.FAQEntryPayload,
) (newEntries []types.FAQEntryPayload, mergeOps []faqMergeOperation, skippedCount int, err error) {
if len(entries) == 0 {
return nil, nil, 0, nil
}
existingChunks, err := s.chunkRepo.ListAllFAQChunksWithMetadataByKnowledgeBaseID(ctx, tenantID, kbID)
if err != nil {
return nil, nil, 0, fmt.Errorf("failed to list existing FAQ chunks: %w", err)
}
existingStdQToChunk := make(map[string]*types.Chunk)
existingQuestions := make(map[string]bool)
for _, chunk := range existingChunks {
meta, cErr := chunk.FAQMetadata()
if cErr != nil || meta == nil {
continue
}
if meta.StandardQuestion != "" {
existingStdQToChunk[meta.StandardQuestion] = chunk
existingQuestions[meta.StandardQuestion] = true
}
for _, q := range meta.SimilarQuestions {
if q != "" {
existingQuestions[q] = true
}
}View on GitHub (pinned to 988cbb0330)
Solutions
- Inspect the wrapped cause in logs to identify the DB error
- Verify database connectivity and that the chunks table exists with expected schema
- Check for context deadline/cancellation; increase the import timeout or DB query timeout
- Retry the FAQ import once the database is healthy
Example fix
// before
existingChunks, err := s.chunkRepo.ListAllFAQChunksWithMetadataByKnowledgeBaseID(ctx, tenantID, kbID)
if err != nil {
return nil, nil, 0, fmt.Errorf("failed to list existing FAQ chunks: %w", err)
}
// after
existingChunks, err := s.chunkRepo.ListAllFAQChunksWithMetadataByKnowledgeBaseID(ctx, tenantID, kbID)
if err != nil {
logger.Errorf(ctx, "list existing FAQ chunks kb=%s: %v", kbID, err)
return nil, nil, 0, fmt.Errorf("failed to list existing FAQ chunks: %w", err)
} Defensive patterns
Strategy: retry
Validate before calling
// Pre-check DB reachability and chunk repo before starting an append import
if err := db.PingContext(ctx); err != nil {
return fmt.Errorf("database unavailable, abort FAQ import: %w", err)
}
count, err := chunkRepo.CountFAQChunks(ctx, tenantID, kbID)
if err != nil {
return fmt.Errorf("cannot read FAQ chunks, abort import: %w", err)
} Try / catch
err := executeAppendImport(ctx, payload)
var appErr *AppError
if errors.As(err, &appErr) && strings.Contains(appErr.Error(), "failed to list existing FAQ chunks") {
// transient DB issue: retry with backoff
return retryWithBackoff(3, executeAppendImport, ctx, payload)
}
return err Prevention
- Set generous but bounded DB statement timeouts for import transactions
- Health-check the database before enqueueing import tasks
- Monitor connection pool saturation during bulk imports
- Wrap chunk listing in a retry helper for transient errors
When it happens
Trigger: executeFAQImport runs in append mode with non-empty entries; the ListAllFAQChunksWithMetadataByKnowledgeBaseID query fails due to database outage, connection pool exhaustion, query timeout, or a canceled request context.
Common situations: Postgres/MySQL restart or failover during an import; long-running import whose context times out; misconfigured DSN or read-replica lag causing connection errors; schema mismatch after migration.
Related errors
- failed to get knowledge: %w
- failed to list existing chunks: %w
- failed to delete chunks: %w
- find conflicting memory: %w
- failed to resolve wiki page %s in knowledge base %s: %w
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/f1eb2deb7276f6a8.
Report an issue: GitHub.