AgentSkillsCN

Claude Flow Memory

通过 AgentDB 统一管理、HNSW 索引、向量搜索,以及混合 SQLite+AgentDB 后端,实现记忆管理。适用于存储、搜索或管理代理记忆、配置记忆后端,或在知识库之间执行语义搜索时使用。

SKILL.md
--- frontmatter
name: "Claude Flow Memory"
description: "Memory management with AgentDB unification, HNSW indexing, vector search, and hybrid SQLite+AgentDB backend. Use when storing, searching, or managing agent memory, configuring memory backends, or performing semantic search across knowledge bases."

Claude Flow Memory

Memory module providing AgentDB unification, HNSW indexing (150x-12,500x faster search), vector search, and hybrid SQLite+AgentDB backend for persistent agent knowledge.

Quick Command Reference

TaskCommand
Initialize memorynpx @claude-flow/cli@latest memory init
Store entrynpx @claude-flow/cli@latest memory store --key k --value v
Retrieve entrynpx @claude-flow/cli@latest memory retrieve --key k
Semantic searchnpx @claude-flow/cli@latest memory search --query "pattern"
List entriesnpx @claude-flow/cli@latest memory list
Delete entrynpx @claude-flow/cli@latest memory delete --key k
View statsnpx @claude-flow/cli@latest memory stats
Configure backendnpx @claude-flow/cli@latest memory configure
Cleanup stalenpx @claude-flow/cli@latest memory cleanup
Compress storagenpx @claude-flow/cli@latest memory compress
Export to filenpx @claude-flow/cli@latest memory export --file mem.json
Import from filenpx @claude-flow/cli@latest memory import --file mem.json

Core Commands

memory init

Initialize memory database with sql.js (WASM SQLite).

bash
npx @claude-flow/cli@latest memory init

memory store

Store data in memory.

bash
npx @claude-flow/cli@latest memory store --key <key> --value <value> [options]

Options:

OptionDescription
--keyMemory key (required)
--valueMemory value (required)
--namespaceMemory namespace for organization
--ttlTime-to-live in seconds
--tagsComma-separated tags for filtering

Examples:

bash
# Simple store
npx @claude-flow/cli@latest memory store --key "api-pattern" --value "REST with pagination"

# With namespace and tags
npx @claude-flow/cli@latest memory store --key "auth-jwt" --value "JWT with refresh tokens" --namespace patterns --tags "auth,security"

# With TTL (expires in 1 hour)
npx @claude-flow/cli@latest memory store --key "temp-result" --value "cached data" --ttl 3600

memory retrieve

Retrieve data from memory.

bash
npx @claude-flow/cli@latest memory retrieve --key <key> [--namespace <ns>]
npx @claude-flow/cli@latest memory get --key <key>    # alias

memory search

Search memory with semantic/vector search (HNSW-indexed).

bash
npx @claude-flow/cli@latest memory search --query <query> [options]

Options:

OptionDescription
--querySearch query (required)
--namespaceNamespace to search within
--limitMaximum number of results
--thresholdSimilarity threshold (0-1)

Examples:

bash
# Basic search
npx @claude-flow/cli@latest memory search --query "authentication patterns"

# Scoped search
npx @claude-flow/cli@latest memory search --query "error handling" --namespace patterns --limit 5

# High-precision search
npx @claude-flow/cli@latest memory search --query "JWT" --threshold 0.8

memory list

List memory entries.

bash
npx @claude-flow/cli@latest memory list [--namespace <ns>] [--limit <n>]
npx @claude-flow/cli@latest memory ls    # alias

memory delete

Delete a memory entry.

bash
npx @claude-flow/cli@latest memory delete --key <key>
npx @claude-flow/cli@latest memory rm --key <key>    # alias

memory stats

Show memory statistics (entry count, size, namespaces).

bash
npx @claude-flow/cli@latest memory stats

memory configure

Configure memory backend.

bash
npx @claude-flow/cli@latest memory configure
npx @claude-flow/cli@latest memory config    # alias

memory cleanup

Clean up stale and expired memory entries.

bash
npx @claude-flow/cli@latest memory cleanup

memory compress

Compress and optimize memory storage.

bash
npx @claude-flow/cli@latest memory compress

memory export

Export memory to file.

bash
npx @claude-flow/cli@latest memory export --file <path>

memory import

Import memory from file.

bash
npx @claude-flow/cli@latest memory import --file <path>

Common Patterns

Bootstrap Memory for a Project

bash
# Initialize memory database
npx @claude-flow/cli@latest memory init

# Store project patterns
npx @claude-flow/cli@latest memory store --key "arch" --value "Event-sourced DDD with CQRS" --namespace project
npx @claude-flow/cli@latest memory store --key "stack" --value "TypeScript, Node.js, PostgreSQL" --namespace project

# Verify
npx @claude-flow/cli@latest memory stats

Search Across Knowledge Base

bash
# Search all namespaces
npx @claude-flow/cli@latest memory search --query "authentication best practices"

# Search specific namespace
npx @claude-flow/cli@latest memory search --query "error handling" --namespace patterns --limit 10

Memory Maintenance

bash
# Clean up expired entries
npx @claude-flow/cli@latest memory cleanup

# Compress storage
npx @claude-flow/cli@latest memory compress

# Export backup
npx @claude-flow/cli@latest memory export --file backup.json

Key Options

  • --key: Memory key for store/retrieve/delete
  • --value: Value to store
  • --namespace: Organizational namespace
  • --query: Search query for semantic search
  • --limit: Max results for list/search
  • --ttl: Time-to-live in seconds
  • --tags: Comma-separated tags
  • --threshold: Similarity threshold for search

Programmatic API

typescript
import { MemoryService, HNSWIndex } from '@claude-flow/memory';

// Initialize memory
const memory = new MemoryService({ backend: 'hybrid' });
await memory.init();

// Store
await memory.store('key', 'value', { namespace: 'patterns', ttl: 3600 });

// Search with HNSW
const results = await memory.search('authentication', { limit: 5 });

RAN DDD Context

Bounded Context: Cross-Cutting Related Skills: claude-flow, claude-flow-embeddings

References