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

Method List

pkg/memory/logic/store_postgres.go:231–309  ·  view source on GitHub ↗

List 列出符合条件的 Memory

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

Source from the content-addressed store, hash-verified

229
230// List 列出符合条件的 Memory
231func (s *PostgreSQLStore) List(ctx context.Context, namespace string, filters ...Filter) ([]*LogicMemory, error) {
232 if s.closed {
233 return nil, ErrStoreClosed
234 }
235
236 opts := ApplyFilters(filters...)
237
238 // 构建查询
239 query := fmt.Sprintf(`
240 SELECT id, namespace, scope, type, category, key, value, description,
241 source_type, confidence, sources, provenance_created_at, provenance_updated_at, provenance_version,
242 access_count, last_accessed, metadata, created_at, updated_at
243 FROM %s
244 WHERE 1=1
245 `, s.tableName)
246
247 args := []any{}
248 argIndex := 1
249
250 if namespace != "" {
251 query += fmt.Sprintf(" AND namespace = $%d", argIndex)
252 args = append(args, namespace)
253 argIndex++
254 }
255
256 if opts.Type != "" {
257 query += fmt.Sprintf(" AND type = $%d", argIndex)
258 args = append(args, opts.Type)
259 argIndex++
260 }
261
262 if opts.Scope != "" {
263 query += fmt.Sprintf(" AND scope = $%d", argIndex)
264 args = append(args, opts.Scope)
265 argIndex++
266 }
267
268 if opts.MinConfidence > 0 {
269 query += fmt.Sprintf(" AND confidence >= $%d", argIndex)
270 args = append(args, opts.MinConfidence)
271 // argIndex++ 不需要,后续没有使用
272 }
273
274 // 排序
275 switch opts.OrderBy {
276 case OrderByConfidence:
277 query += " ORDER BY confidence DESC"
278 case OrderByLastAccessed:
279 query += " ORDER BY last_accessed DESC"
280 case OrderByCreatedAt:
281 query += " ORDER BY created_at DESC"
282 case OrderByAccessCount:
283 query += " ORDER BY access_count DESC"
284 default:
285 query += " ORDER BY confidence DESC"
286 }
287
288 // 限制数量

Callers 3

SearchByTypeMethod · 0.95
SearchByScopeMethod · 0.95
GetTopKMethod · 0.95

Calls 4

scanMemoryFromRowsMethod · 0.95
ApplyFiltersFunction · 0.85
NewStoreErrorFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected