Inference,
Embeddings, and Decision facades provide fluent, immutable interfaces that
hide provider wire differences.
Inference
TheInference 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 anInference instance depending on how much control you need:
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:Executing and Reading Results
Shortcuts execute the request and return results directly:create() returns a PendingInference without triggering execution:
Working with Responses
TheInferenceResponse envelope carries the assistant message and execution metadata:
Working with Streams
TheInferenceStream provides several ways to consume streaming data:
Embeddings
TheEmbeddings class provides a unified interface for generating vector embeddings across providers.
Namespace: Cognesy\Polyglot\Embeddings\Embeddings
Creating an Instance
Building a Request
Executing and Reading Results
create() returns a PendingEmbeddings:
Working with Responses
TheEmbeddingsResponse 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
withInput(), withQuestions(),
withModel(), withRetryPolicy(), withRequest(), withRuntime(), and the
combined with(). get() returns Answers; response() returns the complete
DecisionResponse; and create() returns a lazy PendingDecision.
Registering Custom Drivers
Inference Drivers
Custom inference drivers are registered through theInferenceDriverRegistry and passed to the runtime:
Embeddings Drivers
Custom embeddings drivers are registered through theEmbeddingsDriverRegistry and passed to the runtime:
Decision Drivers
Custom Decision drivers implementCanProcessDecisionRequest 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.