Skip to main content
Most applications only need a small part of the package. The Inference, Embeddings, and Decision facades provide fluent, immutable interfaces that hide provider wire differences.

Inference

The Inference class is the main entry point for LLM interactions. It encapsulates provider complexities behind a unified, fluent interface. Namespace: Cognesy\Polyglot\Inference\Inference

Creating an Instance

Polyglot offers several ways to create an Inference instance depending on how much control you need:
You can also pass a custom driver registry to using() or fromConfig() if you have registered custom drivers:

Building a Request

All request methods return a new immutable instance, so you can safely branch configurations:
Available request methods:

Executing and Reading Results

Shortcuts execute the request and return results directly:
For lower-level control, create() returns a PendingInference without triggering execution:

Working with Responses

The InferenceResponse envelope carries the assistant message and execution metadata:

Working with Streams

The InferenceStream provides several ways to consume streaming data:

Embeddings

The Embeddings class provides a unified interface for generating vector embeddings across providers. Namespace: Cognesy\Polyglot\Embeddings\Embeddings

Creating an Instance

Building a Request

Available request methods:

Executing and Reading Results

For lower-level control, create() returns a PendingEmbeddings:

Working with Responses

The EmbeddingsResponse object provides access to the embedding vectors:

Decision

Decision evaluates text or structured state against typed questions and returns typed answers rather than generated text. Namespace: Cognesy\Polyglot\Decision\Decision
Its immutable request methods are withInput(), withQuestions(), withModel(), withRetryPolicy(), withRequest(), withRuntime(), and the combined with(). get() returns Answers; response() returns the complete DecisionResponse; and create() returns a lazy PendingDecision.
Start with Structured Decisions, then use Question design and Response handling for the complete typed surface.

Registering Custom Drivers

Inference Drivers

Custom inference drivers are registered through the InferenceDriverRegistry and passed to the runtime:

Embeddings Drivers

Custom embeddings drivers are registered through the EmbeddingsDriverRegistry and passed to the runtime:

Decision Drivers

Custom Decision drivers implement CanProcessDecisionRequest and are registered through DecisionDriverRegistry. See Decision custom drivers for the constructor and factory contracts. See the Providers page for details on driver registration and factory patterns.