Anvia
Retrieval

Embeddings

Create embedding models for retrieval workflows.

Embeddings turn text into vectors so you can search by meaning instead of exact keywords. Retrieval starts by choosing an embedding model.

1. Create an Embedding Model

import { OpenAIClient } from "@anvia/openai";

const client = new OpenAIClient({ apiKey });
const embeddings = client.embeddingModel("text-embedding-3-small");

Use the same embedding model for indexing documents and searching with user queries.

2. Embed One Text

import { embedText } from "@anvia/core";

const embedding = await embedText(embeddings, "Password reset links expire after 30 minutes.");

console.log(embedding.vector.length);

3. Embed Many Texts

import { embedTexts } from "@anvia/core";

const results = await embedTexts(embeddings, [
  "Password reset links expire after 30 minutes.",
  "Enterprise customers receive priority support.",
]);

Anvia respects the model's batch size when available.

4. Use Embeddings Through Higher-Level Helpers

Most retrieval workflows should use Embed Documents instead of calling embedText(...) directly. Document embedding preserves ids, metadata, and the original document shape.