208 lines
9.3 KiB
TypeScript
208 lines
9.3 KiB
TypeScript
/**
|
|
* @claude-flow/memory - V3 Unified Memory System
|
|
*
|
|
* Provides a unified memory interface backed by AgentDB with HNSW indexing
|
|
* for 150x-12,500x faster vector search compared to brute-force approaches.
|
|
*
|
|
* @module @claude-flow/memory
|
|
*
|
|
* @example
|
|
* ```typescript
|
|
* import { UnifiedMemoryService, query, QueryTemplates } from '@claude-flow/memory';
|
|
*
|
|
* // Initialize the memory service
|
|
* const memory = new UnifiedMemoryService({
|
|
* dimensions: 1536,
|
|
* cacheEnabled: true,
|
|
* embeddingGenerator: async (text) => embeddings.embed(text),
|
|
* });
|
|
*
|
|
* await memory.initialize();
|
|
*
|
|
* // Store entries
|
|
* await memory.store({
|
|
* key: 'auth-patterns',
|
|
* content: 'OAuth 2.0 implementation patterns for secure authentication',
|
|
* tags: ['auth', 'security', 'patterns'],
|
|
* });
|
|
*
|
|
* // Semantic search
|
|
* const results = await memory.semanticSearch('user authentication best practices', 5);
|
|
*
|
|
* // Query with fluent builder
|
|
* const entries = await memory.query(
|
|
* query()
|
|
* .semantic('security vulnerabilities')
|
|
* .inNamespace('security')
|
|
* .withTags(['critical'])
|
|
* .threshold(0.8)
|
|
* .limit(10)
|
|
* .build()
|
|
* );
|
|
* ```
|
|
*/
|
|
export type { MemoryType, AccessLevel, ConsistencyLevel, DistanceMetric, MemoryEntry, MemoryEntryInput, MemoryEntryUpdate, QueryType, MemoryQuery, SearchResult, SearchOptions, HNSWConfig, HNSWStats, QuantizationConfig, IMemoryBackend, BackendStats, HealthCheckResult, ComponentHealth, CacheConfig, CacheStats, CachedEntry, MigrationSource, MigrationConfig, MigrationProgress, MigrationResult, MigrationError, MemoryEventType, MemoryEvent, MemoryEventHandler, SONAMode, LearningPattern, EmbeddingGenerator, } from './types.js';
|
|
export { generateMemoryId, createDefaultEntry, PERFORMANCE_TARGETS, } from './types.js';
|
|
export { AutoMemoryBridge, resolveAutoMemoryDir, findGitRoot } from './auto-memory-bridge.js';
|
|
export type { AutoMemoryBridgeConfig, MemoryInsight, InsightCategory, SyncDirection, SyncMode, PruneStrategy, SyncResult, ImportResult, } from './auto-memory-bridge.js';
|
|
export { LearningBridge } from './learning-bridge.js';
|
|
export type { LearningBridgeConfig, LearningStats, ConsolidateResult, PatternMatch, } from './learning-bridge.js';
|
|
export { RvfLearningStore } from './rvf-learning-store.js';
|
|
export type { RvfLearningStoreConfig, PatternRecord, LoraRecord, EwcRecord, TrajectoryRecord, } from './rvf-learning-store.js';
|
|
export { PersistentSonaCoordinator } from './persistent-sona.js';
|
|
export type { PersistentSonaConfig } from './persistent-sona.js';
|
|
export { RvfMigrator } from './rvf-migration.js';
|
|
export type { RvfMigrationOptions, RvfMigrationResult } from './rvf-migration.js';
|
|
export { MemoryGraph } from './memory-graph.js';
|
|
export type { MemoryGraphConfig, GraphNode, GraphEdge, GraphStats, RankedResult, EdgeType, } from './memory-graph.js';
|
|
export { resolveAgentMemoryDir, createAgentBridge, transferKnowledge, listAgentScopes, } from './agent-memory-scope.js';
|
|
export type { AgentMemoryScope, AgentScopedConfig, TransferOptions, TransferResult, } from './agent-memory-scope.js';
|
|
export { ControllerRegistry, INIT_LEVELS } from './controller-registry.js';
|
|
export type { AgentDBControllerName, CLIControllerName, ControllerName, InitLevel, ControllerHealth, RegistryHealthReport, RuntimeConfig, } from './controller-registry.js';
|
|
export { AgentDBAdapter } from './agentdb-adapter.js';
|
|
export type { AgentDBAdapterConfig } from './agentdb-adapter.js';
|
|
export { AgentDBBackend } from './agentdb-backend.js';
|
|
export type { AgentDBBackendConfig } from './agentdb-backend.js';
|
|
export { SQLiteBackend } from './sqlite-backend.js';
|
|
export type { SQLiteBackendConfig } from './sqlite-backend.js';
|
|
export { SqlJsBackend } from './sqljs-backend.js';
|
|
export type { SqlJsBackendConfig } from './sqljs-backend.js';
|
|
export { HybridBackend } from './hybrid-backend.js';
|
|
export type { HybridBackendConfig, StructuredQuery, SemanticQuery, HybridQuery, } from './hybrid-backend.js';
|
|
export { RvfBackend } from './rvf-backend.js';
|
|
export type { RvfBackendConfig } from './rvf-backend.js';
|
|
export { HnswLite, cosineSimilarity } from './hnsw-lite.js';
|
|
export type { HnswSearchResult } from './hnsw-lite.js';
|
|
export { HNSWIndex } from './hnsw-index.js';
|
|
export { CacheManager, TieredCacheManager } from './cache-manager.js';
|
|
export { QueryBuilder, query, QueryTemplates } from './query-builder.js';
|
|
export type { SortDirection, SortField } from './query-builder.js';
|
|
export { MemoryMigrator, createMigrator, migrateMultipleSources } from './migration.js';
|
|
export { createDatabase, getPlatformInfo, getAvailableProviders } from './database-provider.js';
|
|
export type { DatabaseProvider, DatabaseOptions } from './database-provider.js';
|
|
import { EventEmitter } from 'node:events';
|
|
import { IMemoryBackend, MemoryEntry, MemoryEntryInput, MemoryEntryUpdate, MemoryQuery, SearchResult, SearchOptions, BackendStats, HealthCheckResult, EmbeddingGenerator, MigrationSource, MigrationConfig, MigrationResult } from './types.js';
|
|
import { AgentDBAdapter, AgentDBAdapterConfig } from './agentdb-adapter.js';
|
|
/**
|
|
* Configuration for UnifiedMemoryService
|
|
*/
|
|
export interface UnifiedMemoryServiceConfig extends Partial<AgentDBAdapterConfig> {
|
|
/** Enable automatic embedding generation */
|
|
autoEmbed?: boolean;
|
|
/** Default embedding dimensions */
|
|
dimensions?: number;
|
|
/** Embedding generator function */
|
|
embeddingGenerator?: EmbeddingGenerator;
|
|
}
|
|
/**
|
|
* Unified Memory Service
|
|
*
|
|
* High-level interface for the V3 memory system that provides:
|
|
* - Simple API for common operations
|
|
* - Automatic embedding generation
|
|
* - Cross-agent memory sharing
|
|
* - SONA integration for learning
|
|
* - Event-driven notifications
|
|
* - Performance monitoring
|
|
*/
|
|
export declare class UnifiedMemoryService extends EventEmitter implements IMemoryBackend {
|
|
private adapter;
|
|
private config;
|
|
private initialized;
|
|
constructor(config?: UnifiedMemoryServiceConfig);
|
|
initialize(): Promise<void>;
|
|
shutdown(): Promise<void>;
|
|
store(entry: MemoryEntry): Promise<void>;
|
|
get(id: string): Promise<MemoryEntry | null>;
|
|
getByKey(namespace: string, key: string): Promise<MemoryEntry | null>;
|
|
update(id: string, update: MemoryEntryUpdate): Promise<MemoryEntry | null>;
|
|
delete(id: string): Promise<boolean>;
|
|
query(query: MemoryQuery): Promise<MemoryEntry[]>;
|
|
search(embedding: Float32Array, options: SearchOptions): Promise<SearchResult[]>;
|
|
bulkInsert(entries: MemoryEntry[]): Promise<void>;
|
|
bulkDelete(ids: string[]): Promise<number>;
|
|
count(namespace?: string): Promise<number>;
|
|
listNamespaces(): Promise<string[]>;
|
|
clearNamespace(namespace: string): Promise<number>;
|
|
getStats(): Promise<BackendStats>;
|
|
healthCheck(): Promise<HealthCheckResult>;
|
|
/**
|
|
* Store an entry from simple input
|
|
*/
|
|
storeEntry(input: MemoryEntryInput): Promise<MemoryEntry>;
|
|
/**
|
|
* Semantic search by content string
|
|
*/
|
|
semanticSearch(content: string, k?: number, threshold?: number): Promise<SearchResult[]>;
|
|
/**
|
|
* Find similar entries to a given entry
|
|
*/
|
|
findSimilar(id: string, k?: number): Promise<SearchResult[]>;
|
|
/**
|
|
* Get or create an entry
|
|
*/
|
|
getOrCreate(namespace: string, key: string, creator: () => MemoryEntryInput | Promise<MemoryEntryInput>): Promise<MemoryEntry>;
|
|
/**
|
|
* Append content to an existing entry
|
|
*/
|
|
appendContent(id: string, content: string): Promise<MemoryEntry | null>;
|
|
/**
|
|
* Add tags to an existing entry
|
|
*/
|
|
addTags(id: string, tags: string[]): Promise<MemoryEntry | null>;
|
|
/**
|
|
* Remove tags from an existing entry
|
|
*/
|
|
removeTags(id: string, tags: string[]): Promise<MemoryEntry | null>;
|
|
/**
|
|
* Migrate from a legacy memory source
|
|
*/
|
|
migrateFrom(source: MigrationSource, sourcePath: string, options?: Partial<MigrationConfig>): Promise<MigrationResult>;
|
|
/**
|
|
* Share an entry with another agent
|
|
*/
|
|
shareWith(id: string, agentId: string): Promise<MemoryEntry | null>;
|
|
/**
|
|
* Get entries shared with a specific agent
|
|
*/
|
|
getSharedWith(agentId: string): Promise<MemoryEntry[]>;
|
|
/**
|
|
* Get the underlying adapter for advanced operations
|
|
*/
|
|
getAdapter(): AgentDBAdapter;
|
|
/**
|
|
* Check if the service is initialized
|
|
*/
|
|
isInitialized(): boolean;
|
|
}
|
|
/**
|
|
* Create a simple in-memory service (for testing)
|
|
*/
|
|
export declare function createInMemoryService(): UnifiedMemoryService;
|
|
/**
|
|
* Create a persistent memory service
|
|
*/
|
|
export declare function createPersistentService(path: string): UnifiedMemoryService;
|
|
/**
|
|
* Create a memory service with embedding support
|
|
*/
|
|
export declare function createEmbeddingService(embeddingGenerator: EmbeddingGenerator, dimensions?: number): UnifiedMemoryService;
|
|
/**
|
|
* Create a hybrid memory service (SQLite + AgentDB)
|
|
* This is the DEFAULT recommended configuration per ADR-009
|
|
*
|
|
* @example
|
|
* ```typescript
|
|
* const memory = createHybridService('./data/memory.db', embeddingFn);
|
|
* await memory.initialize();
|
|
*
|
|
* // Structured queries go to SQLite
|
|
* const user = await memory.getByKey('users', 'john@example.com');
|
|
*
|
|
* // Semantic queries go to AgentDB
|
|
* const similar = await memory.semanticSearch('authentication patterns', 10);
|
|
* ```
|
|
*/
|
|
export declare function createHybridService(databasePath: string, embeddingGenerator: EmbeddingGenerator, dimensions?: number): UnifiedMemoryService;
|
|
export default UnifiedMemoryService;
|
|
//# sourceMappingURL=index.d.ts.map
|