new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

AI SDK · Providers · all subjects

ai-sdk/embeddings

6 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

embedMany and embed functions are part of the AI SDK

The embedMany and embed functions are imported from the 'ai' package, which is the Vercel AI SDK. These functions provide a unified interface for creating embeddings across different providers.

embedMany function creates embeddings for multiple text chunks

The embedMany function takes a model identifier and an array of text values, and returns an array of embedding vectors. It is called with model 'openai/text-embedding-3-small' and an array of text chunks, returning { embeddings } where embeddings is an array of numeric vectors corresponding to each input value in order.

embed function creates an embedding for a single text value

The embed function takes a model identifier and a single text value, and returns an embedding vector. It is called with model 'openai/text-embedding-3-small' and returns { embedding } where embedding is a numeric vector.

cosineSimilarity function compares two embedding vectors

The cosineSimilarity function takes two embedding vectors and returns a similarity score. It is used to measure how similar one embedding is to another, with higher values indicating greater similarity.

RAG retrieval workflow example

This example demonstrates a complete RAG workflow: text is split into chunks, each chunk is embedded using an embedding model, a user query is embedded with the same model, chunk embeddings are compared to query embedding using cosine similarity, the top 3 most similar chunks are retrieved and joined as context, and the context is passed to a language model along with the query to generate an answer. The example uses OpenAI models openai/text-embedding-3-small for embeddings and openai/gpt-4o for text generation.

embed with provider registry embedding model

Use embed with model: registry.embeddingModel('openai:text-embedding-3-small') to generate embeddings using an embedding model accessed from a provider registry.

Give your agent this brain