Turn application content into data

Generate embedding vectors and validate structured output against your app’s schema.

On this pageSource-backed Markdown

Generate an embedding

Load and authorize the source content in your app, then call generateEmbedding(text). The result contains a vector, its model and the tracked request ID. The default model is text-embedding-3-small.

Store the vector with its model and source revision in your application’s search index. Embed queries with the same model and keep tenant filters on retrieval. This API generates vectors; your app chooses the index, similarity search and retrieval policy.

Inside your server feature
ts
const result = await app().ai.generateEmbedding(note.body);
console.log(result.vector, result.model, result.aiRequestId);

Generate schema-validated output

Use generateStructured() when your feature needs data instead of prose. Supply a Zod schema and a stable schema name. The service sends the JSON schema to the provider, parses its output and validates it before returning data.

The result also includes text and tracking IDs. A schema validates structure, not factual accuracy; check domain constraints before saving or acting on generated values. Agent subclasses can also override outputType() for structured final output.

Extract a typed title
ts
import { z } from 'zod';

const result = await app().ai.generateStructured({
	instructions: 'Extract a short title from the supplied note.',
	input: note.body,
	schemaName: 'note',
	schema: z.object({ title: z.string() }),
});
console.log(result.data.title);