model2vec 1.2.0
model2vec: ^1.2.0 copied to clipboard
A high-performance Dart wrapper for model2vec-rs using Rust FFI. Generate fast, local, and static text embeddings with minimal memory footprint using Native Assets.
1.2.0 #
- Lowered minimum Dart SDK requirement to
3.10.0to support a wider range of environments.
1.1.0 #
New Features:
-
getRecommendedModels()no longer calls FFI — now returns a hardcoded list of 7 models -
Removed
get_model_listfrom FFI bindings (Rust, Dart,.h) -
generateEmbedding()now acceptsmaxLengthparameter — signature changed -
generateBatchEmbeddings()now acceptsmaxLengthandbatchSizeparameters — signature changed -
Streaming API —
generateEmbeddingStream()for processing large datasets with batching and optional worker isolate -
Async API —
generateEmbeddingAsync()andgenerateBatchEmbeddingsAsync()withmaxLength/batchSizesupport -
Advanced init —
initEmbedderAdvanced()withhfToken,cacheDirectory,normalize,subfolder -
In-memory init —
initEmbedderFromBytes()for loading models from raw bytes -
boot()— manual initialization with a customDynamicLibrary -
isNormalized— getter for L2-normalization check -
medianTokenLength— getter for median token length -
maxLength— token truncation parameter forgenerateEmbedding() -
batchSize— internal batching control forgenerateBatchEmbeddings() -
Model2VecUtils— vector math:cosineSimilarity,dotProduct,euclideanDistance,similaritySearch,similaritySearchWithThreshold,cosineDistance,normalize,meanPooling,quantizeToInt8,toBase64,fromBase64,pairwiseSimilarity
Improvements:
- Streaming API Performance:
generateEmbeddingStream()now utilizes a single long-lived worker isolate instead of spawning one per batch, dramatically reducing IPC and memory overhead for large datasets. - Inter-Isolate Communication: Switched from
Map<String, dynamic>to Dart 3 Records for significantly faster and strictly typed isolate communication. - FFI Optimization:
generateEmbedding()in Rust rewritten to avoid array pointer allocations and correctly respectmax_length. - Refactored
quantizeToInt8()to use Dart's native.clamp(). - Added clear documentation for zero-vector handling in
cosineSimilarityandnormalize. - Added documentation warning about IPC overhead in
generateEmbeddingStreamfor CLI/Server applications. - Better error messages when loading the native library fails, explaining possible missing Rust builds.
- Cleaned up FFI bindings: removed dead
get_model_listsymbol from.hand bindings. generate_embeddingin Rust now returns-5on empty results instead of silently corrupting data.generate_batch_embeddings_advancedvalidates result count matches input count.- Benchmark updated to run all 5 models.
- README fully rewritten with API reference and accurate model dimensions.
1.0.0 #
- Initial version.