Abstract interface for text-to-vector embedding models.
Allows a consuming database or application to accept an embedding model
without taking a dependency on the FFI-heavy betto_inferencing package.
The concrete implementation (OnnxEmbeddingModel) lives in this package
and implements this interface.
Usage
Supply an EmbeddingModel to your database's open call when configuring vector indexes:
// Load the model using the concrete implementation in this package.
final model = await OnnxEmbeddingModel.load(
cacheDir: '/path/to/cache',
);
// Pass it to your database or retrieval pipeline.
// await myDatabase.open(embeddingModel: model);
Contract
- embed is called once per document field during indexing and once per query. Implementations must be safe to call from the main isolate.
- The returned Float32List must have exactly dimensions elements.
- If
textis longer than the model's context window, the implementation truncates and setstruncated = truein the returned record. - Implementations must not throw on empty
text. Behaviour for empty input is otherwise implementation-defined — for example,OnnxEmbeddingModelproduces a real[CLS][SEP]-only embedding (not a zero vector), withtruncated = false. A model with a mandatory EmbeddingKind prefix (e.g.multilingual-e5-small's"passage: "/"query: ") never actually tokenises truly empty content, since the prefix is prepended before emptytextis checked.
- Implementers
Properties
- dimensions → int
-
Embedding vector length produced by this model.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- modelId → String
-
Stable identifier of the model that produced these embeddings.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
dispose(
) → void - Releases any native resources held by this model.
-
embed(
String text, {EmbeddingKind kind = EmbeddingKind.document}) → Future< (Float32List, bool)> -
Embeds
textinto a dense float vector. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited