diff --git a/internal/knowledge/store.go b/internal/knowledge/store.go index 5c762c8..0c186a1 100644 --- a/internal/knowledge/store.go +++ b/internal/knowledge/store.go @@ -17,6 +17,7 @@ import ( "time" "unicode" + "github.com/example/glpi-ai-agent/internal/brainactivity" "github.com/example/glpi-ai-agent/internal/model" ) @@ -1073,6 +1074,7 @@ func safeID(v string) bool { // are scored separately. Missing metadata does not lower a document's score: // the weights of available components are normalized dynamically. func (s *Store) Search(ctx context.Context, text string, topK int, categorySets ...[]model.Category) ([]model.KnowledgeHit, error) { + startedAt := time.Now() if s == nil { return nil, fmt.Errorf("knowledge store is not initialized") } @@ -1191,6 +1193,11 @@ func (s *Store) Search(ctx context.Context, text string, topK int, categorySets if topK > 0 && len(hits) > topK { hits = hits[:topK] } + activityHits := make([]brainactivity.Hit, 0, len(hits)) + for _, hit := range hits { + activityHits = append(activityHits, brainactivity.Hit{ID: hit.Doc.ID, Score: hit.Score}) + } + brainactivity.EmitSearch("agent", text, activityHits, time.Since(startedAt)) return hits, nil }