crewai-ts
Version:
TypeScript port of crewAI for agent-based workflows
138 lines • 3.77 kB
TypeScript
/**
* Base Embedder Abstract Class
*
* Defines the interface and common functionality for all embedders
* with optimized performance and memory characteristics
*/
/**
* Base Embedder Options
*/
export interface BaseEmbedderOptions {
/**
* Model to use for embeddings
*/
model?: string;
/**
* Provider of the embedding service
*/
provider?: string;
/**
* Cache size for embeddings (number of items)
* @default 1000
*/
cacheSize?: number;
/**
* Cache TTL in milliseconds
* @default 3600000 (1 hour)
*/
cacheTTL?: number;
/**
* Maximum batch size for embedding requests
* @default 16
*/
batchSize?: number;
/**
* Maximum concurrent requests
* @default 4
*/
maxConcurrency?: number;
/**
* API key for provider-specific authentication
*/
apiKey?: string;
/**
* API URL for HuggingFace
*/
apiUrl?: string;
/**
* Whether to use local inference
*/
useLocal?: boolean;
/**
* Local model path
*/
localModelPath?: string;
/**
* Maximum sequence length
* @default 512
*/
maxLength?: number;
/**
* Whether to use average pooling
* @default true
*/
useAveragePooling?: boolean;
/**
* Request timeout in milliseconds
* @default 30000
*/
timeout?: number;
/**
* Retry configuration
*/
retry?: {
/**
* Maximum number of retries
* @default 3
*/
maxRetries?: number;
/**
* Initial backoff time in milliseconds
* @default 1000
*/
initialBackoff?: number;
/**
* Maximum backoff time in milliseconds
* @default 30000
*/
maxBackoff?: number;
};
/**
* Whether to enable debug logging
* @default false
*/
debug?: boolean;
/**
* Embedding function to use
*/
embeddingFunction?: (text: string) => Promise<Float32Array>;
/**
* Whether to normalize the embeddings
* @default false
*/
normalize?: boolean;
/**
* Dimensions of the embeddings
*/
dimensions?: number;
}
/**
* Abstract base class for all embedders
* Implements common functionality with optimized performance
*/
export declare abstract class BaseEmbedder<T extends BaseEmbedderOptions = BaseEmbedderOptions> {
readonly options: T;
protected client: any;
protected _model: string;
protected retryOptions: Required<{
maxRetries: number;
initialBackoff: number;
maxBackoff: number;
}>;
protected cache: Map<string, Float32Array>;
constructor(options: T);
abstract embed(text: string): Promise<Float32Array>;
abstract embedBatch(texts: string[]): Promise<Float32Array[]>;
protected executeWithRetry<T>(operation: () => Promise<T>, maxRetries?: number, initialBackoff?: number, maxBackoff?: number): Promise<T>;
protected executeBatchWithRetry<T>(operation: () => Promise<T>, maxRetries?: number, initialBackoff?: number, maxBackoff?: number): Promise<T>;
protected isTransientError(error: Error): boolean;
protected normalizeVector(vector: Float32Array): Float32Array;
clearCache(): void;
getCacheSize(): number;
protected generateCacheKey(text: string): string;
protected embedText(text: string): Promise<Float32Array>;
protected embedTexts(texts: string[]): Promise<Float32Array[]>;
protected getCachedEmbedding(cacheKey: string): Float32Array | null;
protected batchProcess<T>(items: string[], batchSize: number, processFn: (batch: string[]) => Promise<T[]>): Promise<T[]>;
}
//# sourceMappingURL=BaseEmbedder.d.ts.map