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

Method List

pkg/memory/logic/store_inmemory.go:99–145  ·  view source on GitHub ↗

List 列出符合条件的 Memory

(ctx context.Context, namespace string, filters ...Filter)

Source from the content-addressed store, hash-verified

97
98// List 列出符合条件的 Memory
99func (s *InMemoryStore) List(ctx context.Context, namespace string, filters ...Filter) ([]*LogicMemory, error) {
100 s.mu.RLock()
101 defer s.mu.RUnlock()
102
103 if s.closed {
104 return nil, ErrStoreClosed
105 }
106
107 opts := ApplyFilters(filters...)
108
109 var result []*LogicMemory
110 for _, memory := range s.memories {
111 // 过滤 namespace
112 if namespace != "" && memory.Namespace != namespace {
113 continue
114 }
115
116 // 过滤类型
117 if opts.Type != "" && memory.Type != opts.Type {
118 continue
119 }
120
121 // 过滤作用域
122 if opts.Scope != "" && memory.Scope != opts.Scope {
123 continue
124 }
125
126 // 过滤置信度
127 if memory.Provenance != nil && memory.Provenance.Confidence < opts.MinConfidence {
128 continue
129 }
130
131 // 返回拷贝
132 copied := *memory
133 result = append(result, &copied)
134 }
135
136 // 排序
137 sortMemories(result, opts.OrderBy)
138
139 // 限制数量
140 if opts.MaxResults > 0 && len(result) > opts.MaxResults {
141 result = result[:opts.MaxResults]
142 }
143
144 return result, nil
145}
146
147// SearchByType 按类型搜索
148func (s *InMemoryStore) SearchByType(ctx context.Context, namespace, memoryType string) ([]*LogicMemory, error) {

Callers 5

TestInMemoryStore_ListFunction · 0.95
TestInMemoryStore_CloseFunction · 0.95
SearchByTypeMethod · 0.95
SearchByScopeMethod · 0.95
GetTopKMethod · 0.95

Calls 2

ApplyFiltersFunction · 0.85
sortMemoriesFunction · 0.85

Tested by 2

TestInMemoryStore_ListFunction · 0.76
TestInMemoryStore_CloseFunction · 0.76