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

Method SearchBySourceType

pkg/memory/semantic.go:287–322  ·  view source on GitHub ↗

SearchBySourceType 按来源类型检索记忆。

(ctx context.Context, query string, meta map[string]any, topK int, sourceTypes []SourceType)

Source from the content-addressed store, hash-verified

285
286// SearchBySourceType 按来源类型检索记忆。
287func (sm *SemanticMemory) SearchBySourceType(ctx context.Context, query string, meta map[string]any, topK int, sourceTypes []SourceType) ([]vector.Hit, error) {
288 if !sm.cfg.EnableProvenance {
289 return sm.Search(ctx, query, meta, topK)
290 }
291
292 // 先执行标准检索
293 hits, err := sm.Search(ctx, query, meta, topK*2)
294 if err != nil {
295 return nil, err
296 }
297
298 // 按来源类型过滤
299 sourceTypeMap := make(map[SourceType]bool)
300 for _, st := range sourceTypes {
301 sourceTypeMap[st] = true
302 }
303
304 var filtered []vector.Hit
305 for _, hit := range hits {
306 provenance := FromMetadata(hit.Metadata)
307 if provenance == nil {
308 continue
309 }
310
311 if sourceTypeMap[provenance.SourceType] {
312 filtered = append(filtered, hit)
313 }
314 }
315
316 // 限制返回数量
317 if len(filtered) > topK {
318 filtered = filtered[:topK]
319 }
320
321 return filtered, nil
322}
323
324// PruneMemories 剪枝(删除)低置信度记忆。
325// 返回被删除的记忆ID列表。

Callers

nothing calls this directly

Calls 2

SearchMethod · 0.95
FromMetadataFunction · 0.85

Tested by

no test coverage detected