org.llm4s.rag.RAGAnswerContext
See theRAGAnswerContext companion object
@Experimental
How RAG turns the retrieved chunks into the prompt an answer is generated from (#3024): which near-duplicates it drops, how many tokens the prompt may take, how many it counts with, and how each chunk is written.
In order, for queryWithAnswer, queryWithPermissionsAndAnswer and their streaming forms:
- deduplication drops a chunk whose text repeats a higher-ranked one's (
RAGAnswerResult.droppedAsDuplicates); - the formatter writes each remaining chunk, and the pipeline fences what it writes as data;
- the budget drops chunks, lowest-ranked first, until the system prompt, the history, the question and the chunks fit (
RAGAnswerResult.droppedForBudget). When not even the highest-ranked chunk fits, the answer is aContextError(tokenBudget) and the model is not called.
val config = RAGConfig.default.withAnswerContext(
RAGAnswerContext.default
.withTokenBudget(ContextTokenBudget.Tokens(6000))
.withDeduplication(ContextDeduplication.ExactText)
)
Value parameters
- deduplication
-
which repeated chunks are dropped before budgeting
- formatter
-
how each chunk is written into the prompt
- tokenBudget
-
how many tokens the prompt may take; by default the model's context window less the reply
- tokenizer
-
the vocabulary the prompt's tokens are counted in:
cl100k_baseby default, the common approximation for a model whose tokenizer is not public. The budget's headroom absorbs the difference from the model's own count.
Attributes
- Companion
- object
- Source
- RAGAnswerContext.scala
- Graph
-
- Supertypes
Members list
In this article
