Skip to content

Memory Patterns

Alessio Rocchi edited this page Jan 27, 2026 · 1 revision

Memory Patterns

Best practices for using aistack's memory system.


Key Naming

Structure: category:identifier

✓ GOOD:
- pattern:singleton
- api:user-create
- concept:jwt
- design:auth-flow

✗ BAD:
- temp123
- data
- stuff

Namespace Organization

✓ GOOD:
- user-auth
- payment-processing
- api-docs
- architecture

✗ BAD:
- default (for everything)
- misc

Metadata Usage

await memory.store('api:user-create', 'POST /api/users creates a user', {
  namespace: 'api-docs',
  metadata: {
    method: 'POST',
    path: '/api/users',
    auth: 'required',
    tags: ['user', 'crud'],
    version: '1.0'
  }
});

Search Optimization

// 1. Use namespaces to limit scope
await memory.search('jwt', { namespace: 'security' });

// 2. Use vector search for concepts
await memory.search('how to authenticate users', { useVector: true });

// 3. Use FTS for keywords
await memory.search('JWT AND validation');

Session-Based Memory

// Store session-specific data
await memory.store('finding:sql-injection', 'Found SQL injection in login', {
  namespace: `session:${session.id}`,
  metadata: { severity: 'high' }
});

Cleanup

// Periodic cleanup
const oldEntries = await memory.list({
  namespace: 'temp',
  // Add timestamp filter logic
});

for (const entry of oldEntries) {
  await memory.delete(entry.key, entry.namespace);
}

Related:

Clone this wiki locally