embedding
import { embedding } from '@routecraft/ai'
Generate vector embeddings from text. Requires embeddingPlugin() in your context plugins.
import { embedding } from '@routecraft/ai'
craft()
.id('embed-document')
.from(source)
.enrich(embedding('openai:text-embedding-3-small', {
using: (ex) => ex.body.content,
}))
.to(vectorStore)
// Result replaces the body: { embedding: [0.123, -0.456, ...] }
// (use only() to keep the document, e.g. only((r) => r.embedding, 'embedding'))
// Embed a combination of fields
.enrich(embedding('ollama:nomic-embed-text', {
using: (ex) => `${ex.body.title} ${ex.body.description}`,
}))
Model ID format: "provider:model-name" (e.g., "huggingface:all-MiniLM-L6-v2", "ollama:nomic-embed-text").
Supported providers: huggingface (local ONNX, no API key), ollama, openai, mock (deterministic test vectors)
Options:
Result shape (replaces the body in bare .enrich() / .to(); pass an aggregator such as only() to merge):
Provider credentials are configured once in embeddingPlugin() and shared across all embedding() calls. See Plugins reference.