applyPrefix static method
- String text,
- EmbeddingKind kind,
- ModelSpec spec
Prepends the kind-appropriate prefix from spec.meta to text, if
one is configured.
Looks up spec.meta['queryPrefix'] for EmbeddingKind.query or
spec.meta['documentPrefix'] for EmbeddingKind.document. If the
corresponding key is absent, text is returned unchanged — this is a
deliberate no-op default so models that don't need a prefix (e.g.
bge-small-en-v1.5) are byte-for-byte unaffected by kind.
Exposed (rather than kept private) so this pure, spec-driven logic can
be unit-tested directly without needing a live ORT session — see this
package's coverage notes for why embed itself is coverage:ignored.
Implementation
@visibleForTesting
static String applyPrefix(String text, EmbeddingKind kind, ModelSpec spec) {
final key = kind == EmbeddingKind.query ? 'queryPrefix' : 'documentPrefix';
final prefix = spec.meta[key];
return prefix is String ? '$prefix$text' : text;
}