/** * Vector Service * * Main service class for vector database operations. * Provides a unified interface for multiple vector database providers. */ 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'; import { BaseVectorAdapter } from './adapters'; /** * Logging context for vector operations */ export interface IVectorLoggingContext { /** Log service instance */ logService: any; /** Product tag for logging */ productTag: string; /** Workspace ID */ workspaceId: string; /** Vector config tag */ vectorTag: string; /** Environment slug */ env: string; } /** * Vector service configuration */ export interface IVectorServiceOptions { /** Vector database type */ type: VectorDBType; /** API endpoint URL */ endpoint?: string; /** API key */ apiKey?: string; /** Index/collection name */ index: string; /** Default namespace */ namespace?: string; /** Vector dimensions */ dimensions: number; /** Distance metric */ metric?: DistanceMetric; /** Cloud region (for hosted services) */ region?: string; /** Request timeout in milliseconds */ timeout?: number; /** Additional provider-specific options */ options?: Record; /** Optional logging context for operations */ loggingContext?: IVectorLoggingContext; } /** * Main Vector Service class * * Provides a unified API for working with vector databases. * * @example * ```typescript * const vectorService = new VectorService({ * type: VectorDBType.PINECONE, * apiKey: process.env.PINECONE_API_KEY, * endpoint: 'https://my-index.svc.pinecone.io', * index: 'my-index', * dimensions: 1536, * }); * * await vectorService.connect(); * * // Upsert vectors * await vectorService.upsert({ * vectors: [ * { id: 'doc1', values: [...], metadata: { title: 'Hello' } }, * { id: 'doc2', values: [...], metadata: { title: 'World' } }, * ], * }); * * // Query similar vectors * const results = await vectorService.query({ * vector: [...], * topK: 10, * filter: { field: 'category', operator: '$eq', value: 'tech' }, * }); * ``` */ export declare class VectorService { private adapter; private config; private _initialized; private loggingContext?; constructor(config: IVectorServiceOptions); /** * Set logging context for operations */ setLoggingContext(context: IVectorLoggingContext): void; /** * Create base log object for an operation */ private createBaseLogs; /** * Log operation start */ private logStart; /** * Log operation success */ private logSuccess; /** * Log operation failure */ private logFailure; /** * Get the underlying adapter */ get rawAdapter(): BaseVectorAdapter; /** * Get database type */ get dbType(): VectorDBType; /** * Check if connected */ get connected(): boolean; /** * Get current namespace */ get namespace(): string | undefined; /** * Get configured dimensions */ get dimensions(): number; /** * Get configured metric */ get metric(): DistanceMetric; /** * Connect to the vector database */ connect(): Promise; /** * Disconnect from the vector database */ disconnect(): Promise; /** * Test connection health */ testConnection(): Promise; /** * Upsert vectors (insert or update) */ upsert(options: IUpsertVectorsOptions): Promise; /** * Upsert a single vector */ upsertOne(id: string, values: number[], metadata?: Record, namespace?: string): Promise; /** * Query vectors by similarity */ query(options: IQueryVectorsOptions): Promise; /** * Find similar vectors to a given vector */ findSimilar(vector: number[], topK?: number, options?: Partial): Promise; /** * Fetch vectors by ID */ fetch(options: IFetchVectorsOptions): Promise; /** * Fetch a single vector by ID */ fetchOne(id: string, namespace?: string): Promise; /** * Update a single vector */ update(options: IUpdateVectorOptions): Promise; /** * Update vector metadata */ updateMetadata(id: string, metadata: Record, options?: { merge?: boolean; namespace?: string; }): Promise; /** * Delete vectors */ delete(options: IDeleteVectorsOptions): Promise; /** * Delete vectors by IDs */ deleteByIds(ids: string[], namespace?: string): Promise; /** * Delete all vectors in a namespace */ deleteAll(namespace?: string): Promise; /** * List vector IDs */ list(options?: IListVectorsOptions): Promise; /** * List all vector IDs (paginated) */ listAll(options?: { namespace?: string; prefix?: string; }): Promise; /** * List available namespaces */ listNamespaces(): Promise; /** * Delete a namespace */ deleteNamespace(namespace: string): Promise; /** * Describe the current index */ describeIndex(): Promise; /** * Get index statistics */ getStats(): Promise; /** * Create a new index */ createIndex(options: ICreateIndexOptions): Promise; /** * Delete an index */ deleteIndex(options: IDeleteIndexOptions): Promise; /** * List all indexes */ listIndexes(): Promise; /** * Check if a feature is supported */ supportsFeature(feature: VectorFeature): boolean; /** * Get all supported features */ getSupportedFeatures(): VectorFeature[]; /** * Count vectors in the index */ count(namespace?: string): Promise; /** * Check if a vector exists */ exists(id: string, namespace?: string): Promise; /** * Create the appropriate adapter based on database type */ private createAdapter; /** * Ensure the service is connected */ private ensureConnected; } /** * Create a vector service instance * * Factory function for creating vector service instances. * * @example * ```typescript * const vectors = createVectorService({ * type: VectorDBType.MEMORY, * index: 'test', * dimensions: 384, * }); * await vectors.connect(); * ``` */ export declare function createVectorService(options: IVectorServiceOptions): VectorService; /** * Create an in-memory vector service (for development/testing) * * @example * ```typescript * const vectors = createMemoryVectorService('test', 384); * await vectors.connect(); * ``` */ export declare function createMemoryVectorService(index: string, dimensions: number, metric?: DistanceMetric): VectorService; export default VectorService;