formatContextItem 格式化上下文项目
(item *KnowledgeItem)
| 572 | |
| 573 | // formatContextItem 格式化上下文项目 |
| 574 | func (r *RAG) formatContextItem(item *KnowledgeItem) string { |
| 575 | var parts []string |
| 576 | |
| 577 | if item.Title != "" { |
| 578 | parts = append(parts, "## "+item.Title) |
| 579 | } |
| 580 | |
| 581 | if item.Description != "" { |
| 582 | parts = append(parts, item.Description) |
| 583 | } |
| 584 | |
| 585 | if item.Content != "" { |
| 586 | parts = append(parts, item.Content) |
| 587 | } |
| 588 | |
| 589 | if len(item.Tags) > 0 { |
| 590 | parts = append(parts, "Tags: "+strings.Join(item.Tags, ", ")) |
| 591 | } |
| 592 | |
| 593 | if item.Source != "" { |
| 594 | parts = append(parts, "Source: "+item.Source) |
| 595 | } |
| 596 | |
| 597 | return strings.Join(parts, "\n") |
| 598 | } |
| 599 | |
| 600 | // compressContext 压缩上下文 |
| 601 | func (r *RAG) compressContext(context string) string { |