Introducing a new way to review your PRs.

Read the announcement

eventual-inc / daft

High-performance data engine for AI and multimodal workloads. Process images, audio, video, and structured data at any scale

View on GitHub

19 documents · Updated Nov 11, 2026

docs / ai-and-multimodal-workloads

AI and multimodal workloads

Daft AI expressions add model inference to a DataFrame workflow. They turn text, images, files, and mixed message inputs into generated responses, embeddings, or labels while the DataFrame engine manages row alignment and execution. A provider layer keeps these expressions separate from the service or model that performs the work.

Workload model

AI expressions

AI expressions are column operations that apply one model action to each input row. They fit into the same lazy workflow as other Daft expressions, so a result can be selected, filtered, joined, or written as part of a larger data flow. See Expressions and functions for the wider expression model.

The public AI function set covers four kinds of work:

WorkInputResult
PromptingOne message expression or a list of message expressionsGenerated text or a structured result
Text embeddingText expressionFixed-size embedding vector
Image embeddingImage expressionFixed-size embedding vector
ClassificationText or image expression plus candidate labelsOne selected label per row

An expression resolves a provider, asks it for a model descriptor, and uses that descriptor to define the result type and execution settings. Empty input batches produce empty results. This preserves the row-oriented contract between inference work and the surrounding DataFrame operation.

References: daft/…/__init__.py• L34-40 daft/…/__init__.py• L72-154 daft/…/__init__.py• L157-242 daft/…/__init__.py• L250-326 daft/…/__init__.py• L329-421

Multimodal prompting

Multimodal prompting lets one prompt combine text with content from another modality. A message can be plain text, an image, a URL, raw bytes, or a File object. The selected provider converts each value to the provider's input form before it sends one user request.

The supported input meaning depends on the provider:

Provider familyPrompt input scope
OpenAI-compatibleText, images, image and video URLs, and non-text files. Text files become text content.
GoogleText, images, and binary files such as images or PDFs. Text files become text content.
TransformersText and text-like bytes or files. Non-text media is not supported by this prompt path.
vLLM prefix cachingOne text expression. It does not support a message list, system message, or structured return format.

OpenAI-compatible prompting can use either the Chat Completions or Responses protocol. The selected protocol changes the wire format for text, images, video URLs, and files, but not the DataFrame-facing prompt contract. Google converts bytes and non-text files to typed content and can convert image arrays when its optional image dependency is present.

Prompt results can remain plain text. When the provider supports it, a Pydantic model can define a structured return shape. Provider-specific input rules therefore matter when a workload moves from text-only data to images, documents, audio, or video.

References: daft/…/__init__.py• L453-476 daft/…/__init__.py• L572-652 daft/…/prompter.py• L160-221 daft/…/prompter.py• L262-302 daft/…/prompter.py• L100-174 daft/…/prompter.py• L113-169 daft/…/prompter.py• L27-72

Provider layer

Provider resolution

The provider layer is the boundary between a Daft expression and a model service or runtime. A provider describes which model actions it can supply and creates a serializable descriptor that carries the provider name, model identity, and options into execution. The common provider contract exposes prompting, embedding, and classification capabilities; unsupported actions fail as provider-specific not-implemented operations.

Provider selection follows a clear order:

  1. Use a provider instance passed to the expression.
  2. Use a named provider attached to the active session.
  3. Load a named provider from the built-in provider registry.
  4. Use the active session's current provider.
  5. Load the expression's default provider.

Applications can attach a configured provider to a session or set a known provider by name. This allows several provider configurations to coexist and lets a workload choose a provider per expression without changing its data flow.

flowchart LR
    E[AI expression] --> R{Provider specified?}
    R -->|instance| P[Provider]
    R -->|name in session| P
    R -->|name not in session| L[Provider registry]
    R -->|not specified| C{Current session provider?}
    C -->|yes| P
    C -->|no| D[Expression default]
    L --> P
    D --> P
    P --> X[Model descriptor]
    X --> U[DataFrame execution]

References: daft/…/__init__.py• L43-65 daft/…/provider.py• L33-101 daft/…/provider.py• L104-155 daft/session.py• L219-232 daft/session.py• L742-769

Provider protocols

A protocol is the small capability contract that a model implementation must satisfy. The expression layer uses the same protocol for local models and remote services, while descriptors report model properties before the model runs.

ProtocolModel actionMain contract
PrompterGenerate a response from messagesAsync prompt result of any supported output type
TextEmbedderMap text to vectorsOne vector for each input text
ImageEmbedderMap images to vectorsOne vector for each input image
TextClassifierSelect a label for textOne label for each input text
ImageClassifierSelect a label for an imageOne label for each input image

Descriptors add the information needed to plan the call. For embeddings, that includes vector size and data type. For all protocols, the descriptor can expose model options and DataFrame execution options such as batch size, retry behavior, concurrency, and GPU use.

References: daft/…/protocols.py• L14-91 daft/…/typing.py• L16-37 daft/…/typing.py• L94-187 daft/…/_expressions.py• L25-117

Supported providers

The built-in registry currently names five provider families. A check mark means that the provider exposes the capability through the current public AI expressions; an em dash means that the provider is registered but does not provide that capability.

CapabilityOpenAIGooglevLLM prefix cachingLM StudioTransformers
PromptYesYesYesYesYes
Text embeddingYesNoNoYesYes
Image embeddingNoNoNoNoYes
Text classificationNoNoNoNoYes
Image classificationNoNoNoNoYes

OpenAI-compatible providers include OpenAI itself and LM Studio. LM Studio uses the OpenAI protocol against a local server. Its embedding path can use a supplied vector size or discover the size from the loaded model. The same discovery path supports custom OpenAI-compatible embedding servers when the server accepts a dimension probe. The Transformers provider supplies local model support for embeddings and classification. Google and OpenAI provide remote prompt paths, including multimodal input handling in their prompt implementations. vLLM prefix caching is a specialized prompt path for local inference.

Provider packages are optional. If the package needed by a chosen provider is not installed, provider loading reports an install hint instead of making the base Daft import require every AI dependency.

References: daft/…/provider.py• L33-101 daft/…/provider.py• L20-72 daft/…/provider.py• L19-65 daft/…/provider.py• L19-58 daft/…/text_embedder.py• L23-103 daft/…/text_embedder.py• L88-176 daft/…/provider.py• L33-141 daft/…/provider.py• L20-63 docs/…/ai.md• L3-10

Model execution

Descriptor and model lifecycle

The descriptor is the hand-off point between planning and inference. It carries model identity and options through the DataFrame plan, then creates the concrete model inside the UDF or specialized execution path that will use it.

For a standard AI expression, execution follows this sequence:

  1. Resolve the provider and request a capability descriptor.
  2. Read the descriptor's result shape and execution options.
  3. Instantiate the model in the worker that runs the expression.
  4. Send row values in batches to the model protocol.
  5. Return responses, vectors, or labels as a new DataFrame column.

Provider options configure the model client. API options configure a request. Daft UDF options control how the DataFrame engine runs the work. The provider helpers keep these groups separate so client settings do not become worker settings and worker settings do not leak into provider requests. See UDFs and aggregations for the wider UDF execution model.

The expression chooses synchronous or asynchronous model calls when the protocol supports both. OpenAI-compatible prompt and embedding clients handle their own retries, so their descriptors prevent the same failed request from also being retried by the UDF layer.

References: daft/…/__init__.py• L127-154 daft/…/__init__.py• L215-242 daft/…/__init__.py• L304-326 daft/…/__init__.py• L399-421 daft/…/typing.py• L128-187 daft/…/utils.py• L64-76 daft/…/prompter.py• L40-63 daft/…/text_embedder.py• L88-176

Batch and resource execution

AI work is executed as batched DataFrame work rather than as one unmanaged model call per row. Batch size limits the values sent to a model call. Concurrency controls the number of active model instances or calls, and GPU settings place model work on GPU-backed workers when the provider supports them.

Provider behavior can add another level of batching. OpenAI-compatible text embedding uses an estimated token budget for each request and a model-specific limit for one input. A long input is split and its chunk vectors are combined into one normalized vector so the output still has one vector for the source row. If a batch request is rate-limited, the embedding path falls back to individual requests.

Failures follow the UDF policy carried by the descriptor. The default is to raise. A workload can instead choose logging or ignoring errors where the provider and expression expose that option. Remote clients may also apply their own retry rules, so the provider path can consume retries before Daft sees a failed call. Google rate-limit and temporary-service responses can carry a Retry-After delay into Daft's retry handling when the response provides a valid delay.

References: daft/…/typing.py• L16-37 daft/…/typing.py• L40-107 daft/…/typing.py• L177-187 daft/…/utils.py• L19-61 daft/…/utils.py• L79-120 daft/…/__init__.py• L132-149 daft/…/text_embedder.py• L179-330 daft/…/prompter.py• L191-216

Local and distributed inference

Standard provider expressions run through Daft's UDF execution model. The vLLM prefix-caching provider is different: the prompt expression sends its request to a vLLM execution path that can keep repeated prompt prefixes near the same model actor.

The vLLM path can use several local or Ray-backed model actors. A router spreads work by load and can prefer actors that recently saw the same prefix. This is useful when many rows share a system prompt or another long prefix, but the provider is marked experimental and supports a narrower prompt contract than the standard provider path.

sequenceDiagram
    participant DF as DataFrame execution
    participant R as Prefix router
    participant A as Model actors
    participant M as vLLM model
    DF->>R: Submit prompt batch
    R->>A: Choose actor by load and prefix
    A->>M: Run local generation
    M-->>A: Generated output
    A-->>DF: Poll output with source rows

References: daft/…/__init__.py• L587-617 daft/…/prompter.py• L27-72 daft/…/vllm.py• L235-263 daft/…/vllm.py• L266-333

AI metrics

Token usage

AI metrics record model request counts and token use as execution metrics. Each metric is tagged with the protocol, provider, and model, so an operator can compare cost and load across model choices instead of seeing only one aggregate count. See Observability and dashboard for the wider runtime metrics view.

The AI layer records these counters when the provider response includes usage data:

CounterMeaning
requestsA completed AI request path reported by the provider implementation
input tokensTokens consumed by the input
output tokensTokens produced by the model
total tokensTotal tokens reported by the provider

Metrics are emitted inside UDF execution through the current operator-metrics context. A direct call to the metric helper outside a UDF does not attach the counter to a workload and produces a warning instead.

OpenAI prompt calls support both Chat Completions and Responses usage shapes. OpenAI embedding calls record input and total tokens. Google prompt calls record the token counts supplied in its response metadata. For thinking models, reasoning tokens are added to output tokens because the total token count includes them. Providers that do not return usage data do not add token counters through this layer.

References: daft/…/metrics.py• L6-26 daft/…/prompter.py• L304-317 daft/…/prompter.py• L319-390 daft/…/text_embedder.py• L269-326 daft/…/prompter.py• L176-216 daft/…/metrics.py• L19-65

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the provider capability matrix aligned with both the provider registry and each provider's get_* methods.
  • Keep protocol result contracts aligned with descriptor result types, especially embedding dimensions and structured prompt outputs.
  • Keep multimodal input rules aligned across the public prompt function and each provider's message conversion path.
  • Keep provider options, request options, and UDF options separated when adding a new option. A key in the wrong group can reach the wrong client or worker.
  • Keep provider client retry behavior distinct from Daft UDF retry behavior so one request is not retried more times than intended.
  • Keep embedding token limits and dimension discovery aligned with custom OpenAI-compatible and LM Studio servers.
  • Keep Retry-After parsing aligned with provider error handling so a valid service delay reaches Daft's retry policy.
  • Keep token metric names and attribute keys stable for dashboard and downstream metric consumers.

Important failure modes

TriggerConsequenceGuard
A requested provider is not in the provider registryExpression construction fails before inference startsUse one of the registered provider names or attach a provider instance
A provider's optional package is missingProvider loading raises an install hint for the provider extraInstall the extra that matches the selected provider
A prompt sends media to the Transformers providerThe prompt path rejects the non-text inputUse OpenAI-compatible or Google prompting for media inputs
A vLLM prompt uses a message list, system message, or structured return formatThe specialized vLLM path rejects the unsupported optionSend one text expression and use the standard provider path for those features
A provider does not implement the requested protocolThe provider raises a not-implemented error before model executionSelect a provider with the required capability
A custom OpenAI-compatible embedding service cannot answer a dimension probe and no dimensions are suppliedThe descriptor cannot define a stable embedding result typeSpecify the embedding dimensions or use a server that supports the probe
A provider option is passed as a request-only option or a UDF option is sent to the provider clientThe client can reject the request or apply a setting at the wrong layerKeep provider, API, and UDF options in their defined groups
A Google rate-limit or temporary-service response has no valid Retry-After valueDaft receives the original provider error without a service delayConfigure provider retries or handle the original error when no delay is supplied
Metrics are emitted outside UDF executionCounters are not attached to an operatorInspect AI metrics during DataFrame execution

Key files

FileWhy to read it
daft/…/__init__.pyPublic AI expressions, provider resolution, result typing, and the standard versus vLLM execution split
daft/…/provider.pyProvider registry, optional provider loading, and the common capability boundary
daft/…/protocols.pyShared contracts for prompting, embeddings, and classification
daft/…/typing.pyDescriptor, embedding shape, request option, and UDF execution concepts
daft/…/utils.pySeparation of provider and request options, resource selection, and retry-delay handling
daft/…/prompter.pyOpenAI-compatible text and multimodal prompt behavior, protocol selection, and usage metrics
daft/…/prompter.pyGoogle prompt input conversion, retry-delay handling, and usage reporting
daft/…/text_embedder.pyOpenAI-compatible embedding dimensions, token-aware batching, long-input handling, and usage metrics
daft/…/text_embedder.pyLM Studio embedding dimension discovery and its reuse of the OpenAI-compatible embedding path
daft/…/provider.pyLocal model capability coverage for embeddings and classification
daft/…/prompter.pySpecialized prefix-caching prompt contract and its limits
daft/…/vllm.pyLocal and Ray-backed vLLM actor execution and prefix-aware routing
daft/…/metrics.pyAI token and request metric names and dimensions