MCPcopy Create free account
hub / github.com/astercloud/aster / SearchAcrossSessions

Method SearchAcrossSessions

pkg/session/search.go:144–180  ·  view source on GitHub ↗

SearchAcrossSessions 跨 Session 搜索

(ctx context.Context, agentIDs []string, query string, limit int)

Source from the content-addressed store, hash-verified

142
143// SearchAcrossSessions 跨 Session 搜索
144func (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 查找相似消息
183func (s *Searcher) FindSimilarMessages(ctx context.Context, agentID string, referenceMessage types.Message, limit int) ([]SearchResult, error) {

Callers

nothing calls this directly

Calls 2

SearchHistoryMethod · 0.95
sortByRelevanceFunction · 0.85

Tested by

no test coverage detected