{"record":{"id":"f267fb83083421fa","repo":"mastra-ai/mastra","slug":"embedder-returned-no-vector-for-knowledge-search-q","errorCode":null,"errorMessage":"Embedder returned no vector for knowledge search query.","messagePattern":"Embedder returned no vector for knowledge search query\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/memory/src/processors/observational-memory/subconscious/semantic-index.ts","lineNumber":73,"sourceCode":"  async drain(scope?: KnowledgeScope): Promise<number> {\n    const key = scope?.join('\\u001f') ?? '*';\n    const active = this.#draining.get(key);\n    if (active) return active;\n    const draining = this.#drain(scope).finally(() => {\n      this.#draining.delete(key);\n    });\n    this.#draining.set(key, draining);\n    return draining;\n  }\n\n  async search(query: string, scope: KnowledgeScope, limit = 10) {\n    await this.drain(scope);\n    const result = await this.#embedder.doEmbed({\n      values: [query],\n      ...(this.#embedderOptions ?? {}),\n    } as never);\n    const embedding = result.embeddings[0];\n    if (!embedding?.length) throw new Error('Embedder returned no vector for knowledge search query.');\n\n    const indexName = this.#indexName(embedding.length);\n    if (!(await this.#knowledgeIndexes()).includes(indexName)) {\n      throw new StaleKnowledgeSemanticIndexError(\n        `Knowledge semantic index ${indexName} is unavailable. Capture or index knowledge before searching.`,\n      );\n    }\n\n    const visibleScopeKeys = scope.map((_, index) => scope.slice(0, index + 1).join('\\u001f'));\n    const batches = await Promise.all(\n      visibleScopeKeys.map(scopeKey =>\n        this.#vector.query({\n          indexName,\n          queryVector: embedding,\n          topK: limit,\n          filter: { scope_key: scopeKey },\n        }),\n      ),","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/memory/src/processors/observational-memory/subconscious/semantic-index.ts#L55-L91","documentation":"`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.","triggerScenarios":"`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.","commonSituations":"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.","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."],"exampleFix":"// before (broken stub)\nconst fakeEmbedder = { doEmbed: async () => ({ embeddings: [] }) };\n// after\nconst fakeEmbedder = { doEmbed: async ({ values }) => ({ embeddings: values.map(() => Array(1536).fill(0.1)) }) };","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function hasEmbedding(result) {\n  return Array.isArray(result?.embeddings) && Array.isArray(result.embeddings[0]) && result.embeddings[0].length > 0;\n}","tryCatchPattern":"try {\n  return await knowledgeSearch(scope, query);\n} catch (e) {\n  if (e.message === 'Embedder returned no vector for knowledge search query.') {\n    // fall back to lexical-only search or surface embedder misconfiguration\n    return lexicalFallbackSearch(scope, query);\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["embeddings","semantic-search","integration"],"backgroundTag":"empty-embedding-response","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}