mastra-ai/mastra · error · Error
No embeddings generated
Error message
No embeddings generated
What it means
generateEmbeddings() consumes the async iterable of batch embeddings from the fastembed model; if no results arrive at all (allResults.length === 0), it throws 'No embeddings generated'. This indicates the underlying model produced zero batches for the given input.
Source
Thrown at packages/fastembed/src/index.ts:44
export async function warmup() {
await warmupFastEmbedModels();
}
// Shared function to generate embeddings using fastembed
async function generateEmbeddings(values: string[], modelType: FastEmbedModelType) {
const model = await getCachedModel(modelType);
// model.embed() returns an AsyncGenerator that processes texts in batches (default size 256)
const embeddings = model.embed(values);
const allResults = [];
for await (const result of embeddings) {
// result is an array of embeddings, one for each text in the batch
// We convert each Float32Array embedding to a regular number array
allResults.push(...result.map(embedding => Array.from(embedding)));
}
if (allResults.length === 0) throw new Error('No embeddings generated');
return {
embeddings: allResults,
};
}
// E5 models are asymmetric: queries and passages must be embedded with different prefixes.
async function generatePrefixedEmbeddings(
values: string[],
modelType: FastEmbedModelType,
prefix: 'query' | 'passage',
) {
return generateEmbeddings(
values.map(value => `${prefix}: ${value}`),
modelType,
);
}
View on GitHub (pinned to 75dd419e61)
Solutions
- Check the input: ensure the texts/embeddings request contains at least one non-empty item before calling embed.
- Add a guard in your calling code to skip or error early on empty input arrays.
- If input is non-empty, verify the fastembed model initialized correctly (model files loaded) — a misloaded model can yield no batches.
Example fix
// before
await model.embed([]);
// after
const texts = getInputTexts();
if (texts.length === 0) return { embeddings: [] };
const { embeddings } = await model.embed(texts); Defensive patterns
Strategy: validation
Validate before calling
function assertNonEmptyInputs(texts) {
if (!Array.isArray(texts) || texts.length === 0) {
throw new Error('embed() requires at least one input text');
}
} Type guard
function hasItems(x) {
return Array.isArray(x) && x.length > 0;
} Try / catch
try {
const { embeddings } = await model.embed(texts);
return embeddings;
} catch (e) {
if (e.message === 'No embeddings generated') {
return { embeddings: [] }; // or skip this batch
}
throw e;
} Prevention
- Guard empty input arrays before calling embed; short-circuit with an empty result.
- Filter inputs upstream and track counts so an all-filtered batch is detected early.
- Add a unit test for the empty-batch path in your embedding pipeline.
When it happens
Trigger: Calling embed/generatePrefixedEmbeddings (via doEmbed) with an empty input array, or with a model/embedder that silently yields nothing for the batch.
Common situations: Empty texts array passed to an AI provider's embed call; upstream filtering removed all inputs; integration where a zero-length batch slips through validation at a higher layer.
Related errors
- RUN_EXPERIMENT_FAILED_NO_DATA_PROVIDED
- Knowledge scope cannot be empty
- Input and output messages cannot be null or empty
- For custom model, modelAbsoluteDirPath is required in FlagEm
- For custom model, modelName is required in FlagEmbedding.ini
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/9109b129266d119f.
Report an issue: GitHub.