PromptBuilder class

Builds a grounded prompt from a question and the retrieved context.

The default template instructs the model to answer using only the supplied context and to admit when the answer is not present, which is the core mechanism RAG uses to reduce hallucination. Provide a custom template to change the instructions; the placeholders {context} and {question} are substituted.

Constructors

PromptBuilder({String template = defaultTemplate, int? maxContextChars, String? sourceKey})
Creates a prompt builder.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
maxContextChars → int?
Maximum total characters of context to include, or null for no limit.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
sourceKey → String?
Metadata key whose value labels each context chunk, e.g. 'source'.
final
template → String
The prompt template containing {context} and {question} placeholders.
final

Methods

build(String question, List<RagDocument> context) → String
Builds the final prompt string from question and context documents.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Constants

defaultTemplate → const String
The built-in grounded template.