mem0ai/mem0 · error · Error

LM Studio embedder failed: ${message}

Error message

LM Studio embedder failed: ${message}

What it means

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.

Source

Thrown at mem0-ts/src/oss/src/embeddings/lmstudio.ts:33

    const baseURL = config.baseURL ?? config.url ?? DEFAULT_BASE_URL;
    const apiKey = config.apiKey || DEFAULT_LMSTUDIO_API_KEY;
    this.openai = new OpenAI({ apiKey, baseURL: String(baseURL) });
    this.model = config.model || DEFAULT_MODEL;
  }

  async embed(text: string): Promise<number[]> {
    const normalized =
      typeof text === "string" ? text.replace(/\n/g, " ") : String(text);
    try {
      const response = await this.openai.embeddings.create({
        model: this.model,
        input: normalized,
        encoding_format: "float",
      });
      return response.data[0].embedding;
    } catch (err) {
      const message = err instanceof Error ? err.message : String(err);
      throw new Error(`LM Studio embedder failed: ${message}`);
    }
  }

  async embedBatch(texts: string[]): Promise<number[][]> {
    const normalized = texts.map((t) =>
      typeof t === "string" ? t.replace(/\n/g, " ") : String(t),
    );
    try {
      const response = await this.openai.embeddings.create({
        model: this.model,
        input: normalized,
        encoding_format: "float",
      });
      return response.data
        .sort((a, b) => a.index - b.index)
        .map((item) => item.embedding);
    } catch (err) {
      const message = err instanceof Error ? err.message : String(err);

View on GitHub (pinned to 001c235229)

Solutions

  1. Read the appended suffix — ECONNREFUSED means the server is down, 'model not found' means a name/load issue
  2. 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
  3. Set config.model to the exact identifier shown by /v1/models, or leave it default if the server has one model loaded
  4. For long inputs, chunk text below the model's context length before calling embed()

Example fix

// before
embedder: { provider: 'lmstudio', config: { model: 'llama-3-8b' } } // chat model, no embeddings

// after
// 1. In LM Studio: load 'nomic-embed-text-v1.5' and start the server on port 1234
embedder: { provider: 'lmstudio', config: { model: 'nomic-embed-text-v1.5' } }
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight the local server before building Memory
const res = await fetch('http://localhost:1234/v1/models');
if (!res.ok) throw new Error('LM Studio server is not reachable on :1234');
const { data } = await res.json();
if (!data.some((m: any) => m.id === config.model)) {
  throw new Error(`Model ${config.model} not loaded in LM Studio`);
}

Try / catch

try {
  vec = await embedder.embed(text);
} catch (e) {
  if (e instanceof Error && e.message.startsWith('LM Studio embedder failed:')) {
    const cause = e.message.slice('LM Studio embedder failed:'.length).trim();
    if (/ECONNREFUSED|fetch failed/i.test(cause)) throw new Error('Start the LM Studio server');
    if (/not found/i.test(cause)) throw new Error('Load the embedding model in LM Studio first');
    throw e;
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/e67750e82828cf9d. Report an issue: GitHub.