{"record":{"id":"e67750e82828cf9d","repo":"mem0ai/mem0","slug":"lm-studio-embedder-failed-message","errorCode":null,"errorMessage":"LM Studio embedder failed: ${message}","messagePattern":"LM Studio embedder failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/embeddings/lmstudio.ts","lineNumber":33,"sourceCode":"    const baseURL = config.baseURL ?? config.url ?? DEFAULT_BASE_URL;\n    const apiKey = config.apiKey || DEFAULT_LMSTUDIO_API_KEY;\n    this.openai = new OpenAI({ apiKey, baseURL: String(baseURL) });\n    this.model = config.model || DEFAULT_MODEL;\n  }\n\n  async embed(text: string): Promise<number[]> {\n    const normalized =\n      typeof text === \"string\" ? text.replace(/\\n/g, \" \") : String(text);\n    try {\n      const response = await this.openai.embeddings.create({\n        model: this.model,\n        input: normalized,\n        encoding_format: \"float\",\n      });\n      return response.data[0].embedding;\n    } catch (err) {\n      const message = err instanceof Error ? err.message : String(err);\n      throw new Error(`LM Studio embedder failed: ${message}`);\n    }\n  }\n\n  async embedBatch(texts: string[]): Promise<number[][]> {\n    const normalized = texts.map((t) =>\n      typeof t === \"string\" ? t.replace(/\\n/g, \" \") : String(t),\n    );\n    try {\n      const response = await this.openai.embeddings.create({\n        model: this.model,\n        input: normalized,\n        encoding_format: \"float\",\n      });\n      return response.data\n        .sort((a, b) => a.index - b.index)\n        .map((item) => item.embedding);\n    } catch (err) {\n      const message = err instanceof Error ? err.message : String(err);","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/embeddings/lmstudio.ts#L15-L51","documentation":"Thrown by the LMStudioEmbedder when the local LM Studio server's /embeddings call fails for a single text. The original error message is appended after 'LM Studio embedder failed: ' and names the root cause — typically model not loaded, wrong model identifier, connection refused, or context-length overflow. Input text is normalized (newlines replaced with spaces) before the request, so formatting issues are already excluded.","triggerScenarios":"LM Studio server not running or listening on a different port (fetch failed / ECONNREFUSED); the configured model name not matching a loaded model ('model not found'); input longer than the loaded model's context; LM Studio started without --cors or without the embeddings endpoint enabled.","commonSituations":"Local-first setups pointing at http://localhost:1234/v1 where the developer forgot to start the server or load the embedding model; using a chat-only model (e.g. a llama chat GGUF) that has no embeddings endpoint; embedding long transcripts that exceed the model's context window.","solutions":["Read the appended suffix — ECONNREFUSED means the server is down, 'model not found' means a name/load issue","Start LM Studio's local server and load an embedding-capable model (e.g. nomic-embed-text), then verify: curl http://localhost:1234/v1/models","Set config.model to the exact identifier shown by /v1/models, or leave it default if the server has one model loaded","For long inputs, chunk text below the model's context length before calling embed()"],"exampleFix":"// before\nembedder: { provider: 'lmstudio', config: { model: 'llama-3-8b' } } // chat model, no embeddings\n\n// after\n// 1. In LM Studio: load 'nomic-embed-text-v1.5' and start the server on port 1234\nembedder: { provider: 'lmstudio', config: { model: 'nomic-embed-text-v1.5' } }","handlingStrategy":"try-catch","validationCode":"// Pre-flight the local server before building Memory\nconst res = await fetch('http://localhost:1234/v1/models');\nif (!res.ok) throw new Error('LM Studio server is not reachable on :1234');\nconst { data } = await res.json();\nif (!data.some((m: any) => m.id === config.model)) {\n  throw new Error(`Model ${config.model} not loaded in LM Studio`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  vec = await embedder.embed(text);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('LM Studio embedder failed:')) {\n    const cause = e.message.slice('LM Studio embedder failed:'.length).trim();\n    if (/ECONNREFUSED|fetch failed/i.test(cause)) throw new Error('Start the LM Studio server');\n    if (/not found/i.test(cause)) throw new Error('Load the embedding model in LM Studio first');\n    throw e;\n  }\n  throw e;\n}","preventionTips":["Start the LM Studio server and load an embedding model (e.g. nomic-embed-text) before constructing Memory","Take config.model from the /v1/models listing verbatim","Chunk long texts below the model's context length; chat-only GGUF models have no embeddings endpoint"],"tags":["lmstudio","embeddings","local","runtime","network"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}