refactor: Implement upload progress tracking in KnowledgeBaseList component and enhance error handling for file uploads
This commit is contained in:
@@ -302,7 +302,8 @@ For every retrieval attempt (Phase 1 or Phase 3), follow this exact chain:
|
||||
|
||||
### Final Output Standards
|
||||
* **Definitive:** Based strictly on the "Deep Read" content.
|
||||
* **Sourced:** Cite sources immediately after claims: <kb doc="..." chunk_id="..." /> or <web url="..." title="..." />.
|
||||
* **Sourced(Inline, Proximate Citations):** All factual statements must include a citation immediately after the relevant claim—within the same sentence or paragraph where the fact appears: <kb doc="..." chunk_id="..." /> or <web url="..." title="..." />.
|
||||
Citations may not be placed at the end of the answer. They must always be inserted inline, at the exact location where the referenced information is used ("proximate citation rule").
|
||||
* **Structured:** Clear hierarchy and logic.
|
||||
|
||||
### System Status
|
||||
@@ -383,7 +384,8 @@ For every information seeking step, strictly follow this 3-step atomic unit:
|
||||
|
||||
### Final Output Standards
|
||||
1. **Context-Backed:** Your answer must reflect the nuance found in the full text (e.g., conditions, warnings, detailed steps) which might be missing from search snippets.
|
||||
2. **Sourced:** Cite sources immediately after claims: <kb doc="..." chunk_id="..." /> .
|
||||
2 **Sourced(Inline, Proximate Citations):** All factual statements must include a citation immediately after the relevant claim—within the same sentence or paragraph where the fact appears: <kb doc="..." chunk_id="..." />.
|
||||
Citations may not be placed at the end of the answer. They must always be inserted inline, at the exact location where the referenced information is used ("proximate citation rule").
|
||||
3. **Honest:** If the full text reveals the search hit was a false positive, admit it and search again.
|
||||
|
||||
### System Status
|
||||
|
||||
@@ -255,6 +255,7 @@ type chunkWithTitle struct {
|
||||
KnowledgeTitle string `json:"knowledge_title" gorm:"column:knowledge_title"`
|
||||
MatchScore float64 `json:"match_score" gorm:"column:match_score"` // Score based on match count and position
|
||||
MatchedPatterns int `json:"matched_patterns"` // Number of unique patterns matched
|
||||
TotalChunkCount int `json:"total_chunk_count" gorm:"column:total_chunk_count"`
|
||||
}
|
||||
|
||||
// searchChunks performs the database search with pattern matching
|
||||
@@ -265,7 +266,7 @@ func (t *GrepChunksTool) searchChunks(
|
||||
) ([]chunkWithTitle, int64, error) {
|
||||
// Build base query
|
||||
query := t.db.Debug().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, knowledges.title as knowledge_title").
|
||||
Select("chunks.id, chunks.content, chunks.chunk_index, chunks.knowledge_id, chunks.knowledge_base_id, chunks.chunk_type, chunks.created_at, knowledges.title as knowledge_title, COUNT(*) OVER (PARTITION BY chunks.knowledge_id) AS total_chunk_count").
|
||||
Joins("LEFT JOIN knowledges ON chunks.knowledge_id = knowledges.id").
|
||||
Where("chunks.tenant_id = ?", t.tenantID).
|
||||
Where("chunks.is_enabled = ?", true).
|
||||
@@ -333,11 +334,6 @@ func (t *GrepChunksTool) formatOutput(
|
||||
|
||||
if len(results) == 0 {
|
||||
output.WriteString("No matches found.\n")
|
||||
output.WriteString("\n=== ⚠️ CRITICAL - Next Steps ===\n")
|
||||
output.WriteString("- ❌ DO NOT use training data or general knowledge to answer\n")
|
||||
output.WriteString("- ✅ Try knowledge_search for semantic search\n")
|
||||
output.WriteString("- ✅ If KB search fails and web_search is enabled: You MUST use web_search\n")
|
||||
output.WriteString("- NEVER fabricate or infer answers - ONLY use retrieved content\n")
|
||||
return output.String()
|
||||
}
|
||||
|
||||
@@ -348,11 +344,12 @@ func (t *GrepChunksTool) formatOutput(
|
||||
patternSummaries = append(patternSummaries, fmt.Sprintf("%s=%d", pattern, count))
|
||||
}
|
||||
|
||||
output.WriteString(fmt.Sprintf("%d) knowledge_id=%s | title=%s | chunk_hits=%d | pattern_hits=[%s]\n",
|
||||
output.WriteString(fmt.Sprintf("%d) knowledge_id=%s | title=%s | chunk_hits=%d | chunk_total=%d | pattern_hits=[%s]\n",
|
||||
idx+1,
|
||||
result.KnowledgeID,
|
||||
result.KnowledgeTitle,
|
||||
result.ChunkHitCount,
|
||||
result.TotalChunkCount,
|
||||
strings.Join(patternSummaries, ", "),
|
||||
))
|
||||
}
|
||||
@@ -364,6 +361,7 @@ type knowledgeAggregation struct {
|
||||
KnowledgeBaseID string `json:"knowledge_base_id"`
|
||||
KnowledgeTitle string `json:"knowledge_title"`
|
||||
ChunkHitCount int `json:"chunk_hit_count"`
|
||||
TotalChunkCount int `json:"total_chunk_count"`
|
||||
PatternCounts map[string]int `json:"pattern_counts"`
|
||||
TotalPatternHits int `json:"total_pattern_hits"`
|
||||
DistinctPatterns int `json:"distinct_patterns"`
|
||||
@@ -398,6 +396,7 @@ func (t *GrepChunksTool) aggregateByKnowledge(results []chunkWithTitle, patterns
|
||||
KnowledgeID: knowledgeID,
|
||||
KnowledgeBaseID: chunk.KnowledgeBaseID,
|
||||
KnowledgeTitle: title,
|
||||
TotalChunkCount: chunk.TotalChunkCount,
|
||||
PatternCounts: make(map[string]int, len(patternKeys)),
|
||||
}
|
||||
for _, pKey := range patternKeys {
|
||||
|
||||
Reference in New Issue
Block a user