Skip to content
1 min read · 123 words

Function: applyEmbeddingPrefix() ​

ts
function applyEmbeddingPrefix(
  texts: readonly string[],
  kind: EmbeddingKind,
  options: Pick<BaseEmbeddingsAdapterOptions, "queryPrefix" | "documentPrefix">,
): string[];

Defined in: src/batteries/embeddings/openai/helpers.ts:27

Applies the configured query/document instruction prefix to a batch of inputs.

Parameters ​

ParameterTypeDescription
textsreadonly string[]The raw inputs to embed.
kindEmbeddingKindWhether these are queries or documents.
optionsPick<BaseEmbeddingsAdapterOptions, "queryPrefix" | "documentPrefix">Carries queryPrefix / documentPrefix.

Returns ​

string[]

A new array with prefixes applied (never mutates the input).

Remarks ​

kind: 'query' → prepend queryPrefix (if set); kind: 'document' → prepend documentPrefix (if set). When the relevant prefix is unset, inputs pass through verbatim. This is the single source of truth for prefix handling shared by both batteries.