Learn how to use inference-time strategies like dynamic in-context learning (DICL) and best-of-N sampling to optimize LLM performance.
experimental_best_of_n
type.
Here’s a simple example configuration:
best_of_n
variant that uses two different variants (promptA
and promptB
) to generate candidates.
It generates two candidates using promptA
and one candidate using promptB
.evaluator
block specifies the model and instructions for selecting the best response.experimental_best_of_n
variant type in Configuration Reference.
experimental_chain_of_thought
variant type is only available for non-streaming requests to JSON functions.
For chat functions, we recommend using reasoning models instead (e.g. OpenAI o3, DeepSeek R1).
To use CoT in TensorZero, you need to configure a variant with the experimental_chain_of_thought
type.
It uses the same configuration as a chat_completion
variant.
Under the hood, TensorZero will prepend an additional field to the desired output schema to include the chain-of-thought reasoning and remove it from the final output.
The reasoning is stored in the database for downstream observability and optimization.
experimental_dynamic_in_context_learning
type.
Here’s a simple example configuration:
dicl
variant that uses the experimental_dynamic_in_context_learning
type.embedding_model
field specifies the model used to embed inputs for similarity search.
We also need to define this model in the embedding_models
section.k
parameter determines the number of similar examples to retrieve and incorporate into the prompt.DynamicInContextLearningExample
table in your ClickHouse database.
These examples will be used by the DICL variant to enhance the context of your prompts at inference time.
The process of adding these examples to the database is crucial for DICL to function properly.
We provide a sample recipe that simplifies this process: Dynamic In-Context Learning with OpenAI.
This recipe supports selecting examples based on boolean metrics, float metrics, and demonstrations.
It helps you populate the DynamicInContextLearningExample
table with high-quality, relevant examples from your historical data.
For more information on the DynamicInContextLearningExample
table and its role in the TensorZero data model, see Data Model.
For a comprehensive list of configuration options for the experimental_dynamic_in_context_learning
variant type, see Configuration Reference.
experimental_mixture_of_n
type.
Here’s a simple example configuration:
mixture_of_n
variant that uses two different variants (promptA
and promptB
) to generate candidates.
It generates two candidates using promptA
and one candidate using promptB
.fuser
block specifies the model and instructions for combining the candidates into a single response.experimental_mixture_of_n
variant type in Configuration Reference.