feat: update auto reply and packaging
This commit is contained in:
@@ -162,9 +162,18 @@ func (e *AutoReplyEngine) rebuildKnowledgeIndex() (*KnowledgeIndex, error) {
|
||||
return nil, err
|
||||
}
|
||||
e.updateKnowledgeStatus(idx)
|
||||
if err := e.rebuildEmbeddingIndex(idx); err != nil {
|
||||
e.setLastErrorWithScope(autoReplyErrorScopeKnowledge, err.Error())
|
||||
if requiresEmbeddingIndex(cfg.Retrieval.RetrievalMode) {
|
||||
if err := e.rebuildEmbeddingIndex(idx); err != nil {
|
||||
e.setLastErrorWithScope(autoReplyErrorScopeKnowledge, err.Error())
|
||||
return idx, err
|
||||
}
|
||||
if len(idx.Chunks) > 0 && e.embeddingEntryCount() == 0 {
|
||||
err := fmt.Errorf("向量索引为空,请先重建知识库索引")
|
||||
e.setLastErrorWithScope(autoReplyErrorScopeKnowledge, err.Error())
|
||||
return idx, err
|
||||
}
|
||||
}
|
||||
e.clearLastErrorScope(autoReplyErrorScopeKnowledge)
|
||||
return idx, nil
|
||||
}
|
||||
|
||||
@@ -206,6 +215,19 @@ func (e *AutoReplyEngine) updateKnowledgeStatus(idx *KnowledgeIndex) {
|
||||
e.mu.Unlock()
|
||||
}
|
||||
|
||||
func (e *AutoReplyEngine) embeddingEntryCount() int {
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
if e.embeddingIndex == nil {
|
||||
return 0
|
||||
}
|
||||
return len(e.embeddingIndex.Entries)
|
||||
}
|
||||
|
||||
func requiresEmbeddingIndex(mode string) bool {
|
||||
return strings.TrimSpace(mode) != retrievalModeKeywordOnly
|
||||
}
|
||||
|
||||
func scoreKnowledgeChunk(queryTokens map[string]int, chunk KnowledgeChunk) float64 {
|
||||
textTokens := tokenizeKnowledgeText(chunk.Title + " " + chunk.Content)
|
||||
if len(textTokens) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user