tasq/node_modules/@claude-flow/memory/dist/agentdb-adapter.d.ts

165 lines
4.8 KiB
TypeScript

/**
* V3 AgentDB Adapter
*
* Unified memory backend implementation using AgentDB with HNSW indexing
* for 150x-12,500x faster vector search. Implements IMemoryBackend interface.
*
* @module v3/memory/agentdb-adapter
*/
import { EventEmitter } from 'node:events';
import { IMemoryBackend, MemoryEntry, MemoryEntryInput, MemoryEntryUpdate, MemoryQuery, SearchOptions, SearchResult, BackendStats, HealthCheckResult, EmbeddingGenerator } from './types.js';
/**
* Configuration for AgentDB Adapter
*/
export interface AgentDBAdapterConfig {
/** Vector dimensions for embeddings (default: 1536 for OpenAI) */
dimensions: number;
/** Maximum number of entries */
maxEntries: number;
/** Enable caching */
cacheEnabled: boolean;
/** Maximum cache size */
cacheSize: number;
/** Cache TTL in milliseconds */
cacheTtl: number;
/** HNSW M parameter (max connections per layer) */
hnswM: number;
/** HNSW efConstruction parameter */
hnswEfConstruction: number;
/** Default namespace */
defaultNamespace: string;
/** Embedding generator function */
embeddingGenerator?: EmbeddingGenerator;
/** Enable persistence to disk */
persistenceEnabled: boolean;
/** Persistence path */
persistencePath?: string;
}
/**
* AgentDB Memory Backend Adapter
*
* Provides unified memory storage with:
* - HNSW-based vector search (150x-12,500x faster than brute force)
* - LRU caching with TTL support
* - Namespace-based organization
* - Full-text and metadata filtering
* - Event-driven architecture
*/
export declare class AgentDBAdapter extends EventEmitter implements IMemoryBackend {
private config;
private entries;
private index;
private cache;
private namespaceIndex;
private keyIndex;
private tagIndex;
private initialized;
private stats;
constructor(config?: Partial<AgentDBAdapterConfig>);
/**
* Initialize the adapter
*/
initialize(): Promise<void>;
/**
* Shutdown the adapter
*/
shutdown(): Promise<void>;
/**
* Store a memory entry
*/
store(entry: MemoryEntry): Promise<void>;
/**
* Get a memory entry by ID
*/
get(id: string): Promise<MemoryEntry | null>;
/**
* Get a memory entry by key within a namespace
*/
getByKey(namespace: string, key: string): Promise<MemoryEntry | null>;
/**
* Update a memory entry
*/
update(id: string, update: MemoryEntryUpdate): Promise<MemoryEntry | null>;
/**
* Delete a memory entry
*/
delete(id: string): Promise<boolean>;
/**
* Query memory entries with filters
*/
query(query: MemoryQuery): Promise<MemoryEntry[]>;
/**
* Semantic vector search
*/
search(embedding: Float32Array, options: SearchOptions): Promise<SearchResult[]>;
/**
* Bulk insert entries (OPTIMIZED: 2-3x faster with batched operations)
*
* Performance improvements:
* - Parallel embedding generation
* - Batched index updates
* - Deferred cache population
* - Single event emission
*/
bulkInsert(entries: MemoryEntry[], options?: {
batchSize?: number;
}): Promise<void>;
/**
* Bulk delete entries (OPTIMIZED: parallel deletion)
*/
bulkDelete(ids: string[]): Promise<number>;
/**
* Bulk get entries by IDs (OPTIMIZED: parallel fetch with cache)
*/
bulkGet(ids: string[]): Promise<Map<string, MemoryEntry | null>>;
/**
* Bulk update entries (OPTIMIZED: batched updates)
*/
bulkUpdate(updates: Array<{
id: string;
update: MemoryEntryUpdate;
}>): Promise<Map<string, MemoryEntry | null>>;
/**
* Get entry count
*/
count(namespace?: string): Promise<number>;
/**
* List all namespaces
*/
listNamespaces(): Promise<string[]>;
/**
* Clear all entries in a namespace
*/
clearNamespace(namespace: string): Promise<number>;
/**
* Get backend statistics
*/
getStats(): Promise<BackendStats>;
/**
* Perform health check
*/
healthCheck(): Promise<HealthCheckResult>;
/**
* Store a new entry from input
*/
storeEntry(input: MemoryEntryInput): Promise<MemoryEntry>;
/**
* Semantic search by content string
*/
semanticSearch(content: string, k?: number, threshold?: number): Promise<SearchResult[]>;
private queryByPrefix;
private queryByTags;
private querySemanticWithFilters;
private queryWithFilters;
private applyFilters;
private updateAccessStats;
private estimateMemoryUsage;
private estimateEntrySize;
private checkStorageHealth;
private checkIndexHealth;
private checkCacheHealth;
private loadFromDisk;
private saveToDisk;
}
export default AgentDBAdapter;
//# sourceMappingURL=agentdb-adapter.d.ts.map