{"record":{"id":"f67c5fcade97bd45","repo":"mem0ai/mem0","slug":"failed-to-search-vectors-error-instanceof-error","errorCode":null,"errorMessage":"Failed to search vectors: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Failed to search vectors: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/vectorize.ts","lineNumber":121,"sourceCode":"        {\n          account_id: this.accountId,\n          vector: query,\n          filter: filters,\n          returnMetadata: \"all\",\n          topK: topK,\n        },\n      );\n\n      return (\n        (result?.matches?.map((match) => ({\n          id: match.id,\n          payload: match.metadata,\n          score: match.score,\n        })) as VectorStoreResult[]) || []\n      ); // Return empty array if result or matches is null/undefined\n    } catch (error) {\n      console.error(\"Error searching vectors:\", error);\n      throw new Error(\n        `Failed to search vectors: ${error instanceof Error ? error.message : String(error)}`,\n      );\n    }\n  }\n\n  async get(vectorId: string): Promise<VectorStoreResult | null> {\n    await this.initialize();\n    try {\n      const result = (await this.client?.vectorize.indexes.getByIds(\n        this.indexName,\n        {\n          account_id: this.accountId,\n          ids: [vectorId],\n        },\n      )) as any;\n\n      if (!result?.length) return null;\n","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/vectorize.ts#L103-L139","documentation":"Catch-all around Cloudflare Vectorize similarity search: any failure while querying the index (auth, missing index, network, malformed request) is logged and rethrown wrapped as 'Failed to search vectors: <message>'. The inner message carries the actual Cloudflare error text.","triggerScenarios":"memory.search() against a deleted or renamed index; expired API token; account_id mismatch; dimension of the query vector differing from the index dims (Cloudflare rejects the query); network failure from the runtime.","commonSituations":"Index recreated after a config change while old code still references the prior indexName; token permissions narrowed to write-only; embeddings model changed without recreating the index.","solutions":["Read the inner message and map it: 404 -> indexName/accountId wrong; 401 -> token; 400 dimension -> align embedding model with index dims.","Verify the index exists: wrangler vectorize list, and compare with config indexName.","For transient failures, retry the search — reads are idempotent."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if (query.length !== indexDims) throw new Error(`Query vector is ${query.length} dims; index expects ${indexDims}`);","typeGuard":null,"tryCatchPattern":"try { return await memory.search(q, opts); } catch (e) { const m = e instanceof Error ? e.message : ''; if (m.startsWith('Failed to search vectors:')) { if (isTransientInner(m)) return retryWithBackoff(() => memory.search(q, opts), 3); throw new Error(m); } throw e; }","preventionTips":["Searches are read-only and safe to retry with backoff","Validate query embedding dimension before search","Cache the index metadata (dims) at startup"],"tags":["cloudflare","vectorize","search","error-wrapping"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}