/** * Base Vector Adapter * * Abstract base class for vector database adapters. * All adapters (Pinecone, Qdrant, Weaviate, etc.) extend this class. */ import { VectorDBType, DistanceMetric, VectorFeature, IVectorConnectionResult, IVector, IUpsertVectorsOptions, IUpsertVectorsResult, IQueryVectorsOptions, IQueryVectorsResult, IFetchVectorsOptions, IFetchVectorsResult, IUpdateVectorOptions, IUpdateVectorResult, IDeleteVectorsOptions, IDeleteVectorsResult, IListVectorsOptions, IListVectorsResult, IListNamespacesResult, IVectorIndexInfo, ICreateIndexOptions, ICreateIndexResult, IDeleteIndexOptions, IDeleteIndexResult, IVectorIndexStats } from '../types'; /** * Adapter connection options */ export interface IAdapterConnectionOptions { /** API endpoint URL */ endpoint: string; /** API key */ apiKey?: string; /** Index/collection name */ index: string; /** Namespace (for multi-tenancy) */ namespace?: string; /** Vector dimensions */ dimensions: number; /** Distance metric */ metric?: DistanceMetric; /** Cloud region */ region?: string; /** Additional options */ options?: Record; } /** * Abstract base adapter for vector databases */ export declare abstract class BaseVectorAdapter { /** Database type */ abstract readonly type: VectorDBType; /** Whether connected */ protected _connected: boolean; /** Connection options */ protected connectionOptions: IAdapterConnectionOptions | null; /** Maximum retry attempts for auto-reconnection */ protected maxRetries: number; /** Flag to indicate if a reconnection is in progress */ private reconnecting; /** * Get connected status */ get connected(): boolean; /** * Execute an operation with automatic retry on connection errors. * This handles transient connection timeouts and disconnects silently. */ protected executeWithRetry(operation: () => Promise, retries?: number): Promise; /** * Check if an error is a connection-related error */ protected isConnectionError(error: any): boolean; /** * Attempt to reconnect to the vector database */ protected attemptReconnect(): Promise; /** * Get current namespace */ get namespace(): string | undefined; /** * Get configured dimensions */ get dimensions(): number; /** * Get configured metric */ get metric(): DistanceMetric; /** * Connect to the vector database */ abstract connect(options: IAdapterConnectionOptions): Promise; /** * Disconnect from the vector database */ abstract disconnect(): Promise; /** * Test connection health */ abstract testConnection(): Promise; /** * Upsert vectors (insert or update) */ abstract upsert(options: IUpsertVectorsOptions): Promise; /** * Query vectors by similarity */ abstract query(options: IQueryVectorsOptions): Promise; /** * Fetch vectors by ID */ abstract fetch(options: IFetchVectorsOptions): Promise; /** * Update a single vector */ abstract update(options: IUpdateVectorOptions): Promise; /** * Delete vectors */ abstract delete(options: IDeleteVectorsOptions): Promise; /** * List vector IDs */ abstract list(options: IListVectorsOptions): Promise; /** * List available namespaces */ abstract listNamespaces(): Promise; /** * Delete a namespace */ abstract deleteNamespace(namespace: string): Promise; /** * Describe the current index */ abstract describeIndex(): Promise; /** * Get index statistics */ abstract getIndexStats(): Promise; /** * Create a new index */ abstract createIndex(options: ICreateIndexOptions): Promise; /** * Delete an index */ abstract deleteIndex(options: IDeleteIndexOptions): Promise; /** * List all indexes */ abstract listIndexes(): Promise; /** * Check if a feature is supported */ abstract supportsFeature(feature: VectorFeature): boolean; /** * Validate vector dimensions */ protected validateDimensions(vectors: IVector[]): void; /** * Normalize a vector to unit length (for cosine similarity) */ protected normalizeVector(vector: number[]): number[]; /** * Calculate cosine similarity between two vectors */ protected cosineSimilarity(a: number[], b: number[]): number; /** * Calculate Euclidean distance between two vectors */ protected euclideanDistance(a: number[], b: number[]): number; /** * Calculate dot product between two vectors */ protected dotProduct(a: number[], b: number[]): number; /** * Calculate similarity based on configured metric */ protected calculateSimilarity(a: number[], b: number[]): number; /** * Generate a unique ID */ protected generateId(): string; } export default BaseVectorAdapter;