Core Fundamentals ⏱ 8 min read 📁 examples/09_memory_and_todos.mjs

Lesson 06: Embeddings and Model Tiers

Turn text into vectors without hardcoding a model id: the embedding surface, the three model tiers, and what each wire actually returns.

1. Why This Feature Exists

Vector features — memory recall, retrieval over a knowledge corpus, semantic dedup — all need an embedding. The SDK ships no hardcoded model ids: each model comes from an environment key resolved per provider, so the same call works against OpenAI, Gemini, Vertex or a local server without a code change.

2. Key Symbols and Exports

client.embed({ input, model })
One vector for a string; an ordered array for an array input, where a failed item is null. A graceful whole-call failure returns null.
getEmbeddingModel({ provider })
Resolves DEFAULT_<PROVIDER>_EMBEDDING_MODEL, falling back to DEFAULT_EMBEDDING_MODEL.
getDefaultModel / getToolModel
The other two tiers: the conversational default and the cheaper model the tool loop and subagents use.

3. Implementation Walkthrough

import {
    initializeClient,
    loadCredentials,
    resolveProvider,
    getEmbeddingModel
} from 'merci-sdk';

const provider = resolveProvider();
const { client } = await initializeClient({ provider, options: loadCredentials({ provider }) });

// One string in, one vector out.
const vector = await client.embed({
    input: 'the scheduler claims one item at a time',
    model: getEmbeddingModel({ provider })
});
if (!vector) throw new Error('No embedding model configured');

// An array in, an ordered array out (a failed item is null).
const batch = await client.embed({
    input: ['first document', 'second document'],
    model: getEmbeddingModel({ provider })
});

4. Wire and Telemetry Mechanics

oai posts to /embeddings; gai calls embedContent, and Vertex fans a batch out into one request per item; aai has no embedding endpoint at all, so embed() throws a typed ConfigurationError that names the providers which do. A missing model id is not an error: the client warns once and returns null, so vector features disable themselves instead of failing a run.

5. Run the Example

Execute the runnable example directly from the repository root:

node examples/09_memory_and_todos.mjs

Read the full example: examples/09_memory_and_todos.mjs →

Expected Output: Builds a persistent memory bank with embeddings, exercises lazy vs preloaded recall, and shows the todos that survive a restart.