UNPKG

crewai-ts

Version:

TypeScript port of crewAI for agent-based workflows

153 lines 3.83 kB
/** * FastText Embedder Implementation * * Optimized embedder using FastText models for efficient multilingual embeddings * with minimal memory footprint and fast execution */ import { BaseEmbedder, BaseEmbedderOptions } from './BaseEmbedder.js'; /** * FastText Embedder Options */ export interface FastTextEmbedderOptions extends BaseEmbedderOptions { /** * Model name */ model: string; /** * Path to FastText model file (.bin or .ftz format) * If not provided, will attempt to download a default model */ modelPath: string; /** * Dimensions of the embeddings */ dimensions: number; /** * Maximum sequence length */ maxLength?: number; /** * Whether to use average pooling */ useAveragePooling?: boolean; /** * Request timeout in milliseconds */ timeout?: number; /** * Whether to use quantized models for memory efficiency * Quantized models (.ftz) use significantly less memory * @default true */ useQuantized?: boolean; /** * Language for the pre-trained model * Only used if modelPath is not provided * @default 'en' */ language?: string; /** * Whether to remove out-of-vocabulary words * @default false */ removeOOV?: boolean; /** * Maximum vocabulary size to load * Smaller values improve memory usage * @default 100000 */ maxVocabSize?: number; /** * Whether to preload the model during initialization * @default true */ preload?: boolean; } /** * Let TypeScript know about optional dependencies */ declare global { var FastText: any; } /** * FastText Embedder * * Memory-efficient text embeddings using FastText models * Optimized for multilingual support and minimal resource usage */ export declare class FastTextEmbedder extends BaseEmbedder<FastTextEmbedderOptions> { /** * FastText model instance (lazy loaded) */ private _modelInstance; /** * Whether the model is ready */ private _modelReady; /** * Model initialization promise (for concurrent calls) */ private _initializationPromise; /** * Path to FastText model file */ private _modelPath; /** * Whether to use quantized models */ private _useQuantized; /** * Language for pre-trained model */ private _language; /** * Whether to remove OOV words */ private _removeOOV; /** * Maximum vocabulary size */ private _maxVocabSize; /** * Word vectors cache for performance * Uses a Map for O(1) lookup performance */ private _vectorCache; /** * Dimensions of the embeddings */ private _dimensions; /** * Constructor for FastTextEmbedder */ constructor(options: FastTextEmbedderOptions); /** * Initialize the FastText model * @returns Promise resolving when model is loaded */ private initializeModel; /** * Internal initialization logic */ private _initializeModel; /** * Get word vector from FastText model * @param word Word to get vector for * @returns Promise resolving to word vector */ private getWordVector; /** * Embed text using FastText * Optimized average word embedding approach * @param text Text to embed * @returns Promise resolving to Float32Array of embeddings */ protected embedText(text: string): Promise<Float32Array>; embed(text: string): Promise<Float32Array>; embedBatch(texts: string[]): Promise<Float32Array[]>; /** * Clean up resources when the embedder is no longer needed */ close(): Promise<void>; } //# sourceMappingURL=FastTextEmbedder.d.ts.map