mastra-ai/mastra · error
Embedder returned no vector for knowledge search query.
Error message
Embedder returned no vector for knowledge search query.
What it means
`search` in packages/memory/src/processors/observational-memory/subconscious/semantic-index.ts:73 embeds the knowledge-search query via `this.#embedder.doEmbed`. The library throws when the embedder resolves successfully but returns an empty or missing `result.embeddings[0]`, since a query vector is mandatory to search the vector index.
Source
Thrown at packages/memory/src/processors/observational-memory/subconscious/semantic-index.ts:73
async drain(scope?: KnowledgeScope): Promise<number> {
const key = scope?.join('\u001f') ?? '*';
const active = this.#draining.get(key);
if (active) return active;
const draining = this.#drain(scope).finally(() => {
this.#draining.delete(key);
});
this.#draining.set(key, draining);
return draining;
}
async search(query: string, scope: KnowledgeScope, limit = 10) {
await this.drain(scope);
const result = await this.#embedder.doEmbed({
values: [query],
...(this.#embedderOptions ?? {}),
} as never);
const embedding = result.embeddings[0];
if (!embedding?.length) throw new Error('Embedder returned no vector for knowledge search query.');
const indexName = this.#indexName(embedding.length);
if (!(await this.#knowledgeIndexes()).includes(indexName)) {
throw new StaleKnowledgeSemanticIndexError(
`Knowledge semantic index ${indexName} is unavailable. Capture or index knowledge before searching.`,
);
}
const visibleScopeKeys = scope.map((_, index) => scope.slice(0, index + 1).join('\u001f'));
const batches = await Promise.all(
visibleScopeKeys.map(scopeKey =>
this.#vector.query({
indexName,
queryVector: embedding,
topK: limit,
filter: { scope_key: scopeKey },
}),
),View on GitHub (pinned to 75dd419e61)
Solutions
- Fix the embedder so it returns `embeddings: number[][]` with at least one non-empty vector per input value.
- If using a mock/stub, update it to return a realistic vector (e.g. `[[0.1, 0.2, ...]]`).
- Verify embedder credentials/model configuration; switch to a known-good embedder implementation.
- Log raw doEmbed results to confirm the provider actually returns vectors for your query text.
Example fix
// before (broken stub)
const fakeEmbedder = { doEmbed: async () => ({ embeddings: [] }) };
// after
const fakeEmbedder = { doEmbed: async ({ values }) => ({ embeddings: values.map(() => Array(1536).fill(0.1)) }) }; Defensive patterns
Strategy: try-catch
Type guard
function hasEmbedding(result) {
return Array.isArray(result?.embeddings) && Array.isArray(result.embeddings[0]) && result.embeddings[0].length > 0;
} Try / catch
try {
return await knowledgeSearch(scope, query);
} catch (e) {
if (e.message === 'Embedder returned no vector for knowledge search query.') {
// fall back to lexical-only search or surface embedder misconfiguration
return lexicalFallbackSearch(scope, query);
}
throw e;
} Prevention
- Unit-test that your embedder wrapper returns { embeddings: number[][] } with matching length.
- Validate embedder credentials and model IDs at startup with a smoke embed call.
- Never let embedder adapters swallow API errors into empty results.
When it happens
Trigger: `doEmbed({ values: [query] })` resolves with `{ embeddings: [] }` or an empty first vector — a custom/mock embedder that never populates embeddings, an adapter that swallows API failures and resolves with empty results, or provider-side filtering returning no embedding for the query text.
Common situations: Misconfigured custom embedder wrappers; revoked API keys where the SDK resolves empty instead of rejecting; test doubles returning the wrong shape; provider content filtering of the query.
Related errors
- MastraFactory: duplicate integration id '${integration.id}'
- MastraFactory: integration tool '${name}' from '${ownerId}'
- MastraFactory: integrations [${channelRegistrations.map(({ i
- Version-control repository not found.
- Version-control installation not found.
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/f267fb83083421fa.
Report an issue: GitHub.