ContextTokenBudget

org.llm4s.rag.ContextTokenBudget
@Experimental

How many tokens an answer's prompt may take (#3024): the system prompt, the history, the contexts and the question.

Attributes

Source
RAGAnswerContext.scala
Graph
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Type members

Enum entries

The model's: the client's context window less the reply it must leave room for, less the standard 8% headroom (HeadroomPercent.Standard) for the tokenizer's approximation and the message framing. The reply is the call's maxTokens when it sets one; otherwise the client's reserveCompletion, capped at a quarter of the window, since the registry reports some models' whole window as their output limit (Ollama's llama3: 8192 of 8192). The budget is at least 1 token for a positive window. The client reads its window from the model registry, so a model the registry knows gets its own.

The model's: the client's context window less the reply it must leave room for, less the standard 8% headroom (HeadroomPercent.Standard) for the tokenizer's approximation and the message framing. The reply is the call's maxTokens when it sets one; otherwise the client's reserveCompletion, capped at a quarter of the window, since the registry reports some models' whole window as their output limit (Ollama's llama3: 8192 of 8192). The budget is at least 1 token for a positive window. The client reads its window from the model registry, so a model the registry knows gets its own.

Attributes

Source
RAGAnswerContext.scala
final case class Tokens(max: Int)

At most max tokens, counted with the configured tokenizer, without headroom.

At most max tokens, counted with the configured tokenizer, without headroom.

Attributes

Source
RAGAnswerContext.scala

No limit: every context is sent, and an overlong prompt fails at the provider.

No limit: every context is sent, and an overlong prompt fails at the provider.

Attributes

Source
RAGAnswerContext.scala