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
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.mjsRead the full example: examples/09_memory_and_todos.mjs →