SearchAcrossSessions 跨 Session 搜索
(ctx context.Context, agentIDs []string, query string, limit int)
| 142 | |
| 143 | // SearchAcrossSessions 跨 Session 搜索 |
| 144 | func (s *Searcher) SearchAcrossSessions(ctx context.Context, agentIDs []string, query string, limit int) ([]SearchResult, error) { |
| 145 | if query == "" { |
| 146 | return nil, errors.New("search query cannot be empty") |
| 147 | } |
| 148 | |
| 149 | if limit <= 0 { |
| 150 | limit = 50 |
| 151 | } |
| 152 | |
| 153 | allResults := []SearchResult{} |
| 154 | |
| 155 | for _, agentID := range agentIDs { |
| 156 | opts := SearchOptions{ |
| 157 | Query: query, |
| 158 | AgentID: agentID, |
| 159 | Limit: limit, |
| 160 | } |
| 161 | |
| 162 | results, err := s.SearchHistory(ctx, opts) |
| 163 | if err != nil { |
| 164 | // 记录错误但继续搜索其他 session |
| 165 | continue |
| 166 | } |
| 167 | |
| 168 | allResults = append(allResults, results...) |
| 169 | } |
| 170 | |
| 171 | // 按相关性排序 |
| 172 | sortByRelevance(allResults) |
| 173 | |
| 174 | // 限制结果数量 |
| 175 | if len(allResults) > limit { |
| 176 | allResults = allResults[:limit] |
| 177 | } |
| 178 | |
| 179 | return allResults, nil |
| 180 | } |
| 181 | |
| 182 | // FindSimilarMessages 查找相似消息 |
| 183 | func (s *Searcher) FindSimilarMessages(ctx context.Context, agentID string, referenceMessage types.Message, limit int) ([]SearchResult, error) { |
nothing calls this directly
no test coverage detected