@ever_cheng/memory-task-mcp
Version:
Memory and task management MCP Server
145 lines (144 loc) • 3.49 kB
TypeScript
/**
* Vector Store for MemTask
*
* ChromaDB integration for semantic search and vector similarity operations.
* Handles storage and retrieval of memory chunk embeddings.
*/
import { MemoryChunk } from './chunking';
import { Disposable } from './resource_manager';
/**
* Vector Store Configuration
*/
export interface VectorStoreConfig {
collectionName: string;
maxResults: number;
similarityThreshold: number;
distanceMetric: 'cosine' | 'euclidean' | 'manhattan';
}
/**
* Default vector store configuration
*/
export declare const DEFAULT_VECTOR_STORE_CONFIG: VectorStoreConfig;
/**
* Search Result Interface
*/
export interface VectorSearchResult {
chunkId: string;
memoryId: string;
similarity: number;
distance: number;
metadata: ChunkMetadata;
content?: string;
}
/**
* Chunk Metadata Interface
*/
export interface ChunkMetadata {
memoryId: string;
chunkIndex: number;
totalChunks: number;
created_at: string;
originalLength: number;
chunkLength: number;
[key: string]: any;
}
/**
* Batch Operations Interface
*/
export interface BatchOperationResult {
success: boolean;
processed: number;
failed: number;
errors: string[];
}
/**
* Vector Store Statistics
*/
export interface VectorStoreStats {
totalChunks: number;
uniqueMemories: number;
collectionSize: number;
avgSimilarityScore: number;
metadata: {
[key: string]: any;
};
}
/**
* Vector Store Class
*/
export declare class VectorStore implements Disposable {
private client;
private collection;
private config;
private initialized;
constructor(config?: VectorStoreConfig);
/**
* 初始化 ChromaDB 客戶端和集合
*/
initialize(): Promise<void>;
/**
* 添加單個 memory chunk
*/
addMemoryChunk(chunk: MemoryChunk): Promise<void>;
/**
* 批量添加 memory chunks
*/
addMemoryChunks(chunks: MemoryChunk[]): Promise<BatchOperationResult>;
/**
* 向量相似度搜尋
*/
searchSimilar(queryEmbedding: number[], limit?: number, filters?: {
tags?: string[];
memoryIds?: string[];
}): Promise<VectorSearchResult[]>;
/**
* 根據 memory ID 搜尋相關 chunks
*/
getChunksByMemoryId(memoryId: string): Promise<VectorSearchResult[]>;
/**
* 刪除 memory 的所有 chunks
*/
deleteMemoryChunks(memoryId: string): Promise<boolean>;
/**
* 更新 memory chunks(先刪除再添加)
*/
updateMemoryChunks(memoryId: string, newChunks: MemoryChunk[]): Promise<boolean>;
/**
* 獲取 vector store 統計信息
*/
getStats(): Promise<VectorStoreStats>;
/**
* 清空整個集合
*/
clearCollection(): Promise<boolean>;
/**
* 將距離轉換為相似度 (0-1)
*/
private distanceToSimilarity;
/**
* 健康檢查
*/
healthCheck(): Promise<{
status: 'healthy' | 'unhealthy';
initialized: boolean;
collectionExists: boolean;
error?: string;
}>;
/**
* 更新配置
*/
updateConfig(newConfig: Partial<VectorStoreConfig>): void;
/**
* 獲取當前配置
*/
getConfig(): VectorStoreConfig;
/**
* 清理資源 (實現 Disposable 介面)
*/
dispose(): Promise<void>;
/**
* 清理資源 (向後兼容)
* @deprecated Use dispose() instead
*/
cleanup(): Promise<void>;
}