Class AgentKnowledge
Knowledge sources an agent or a conversation grounds its answers in: a retriever, when to search it, and how the model must cite what it finds.
public sealed class AgentKnowledge
- Inheritance
-
AgentKnowledge
- Inherited Members
Examples
var knowledge = new AgentKnowledge(ragEngine)
{
MaxResults = 5,
CitationPolicy = KnowledgeCitationPolicy.Required,
WhenNoEvidence = KnowledgeNoEvidenceBehavior.Abstain,
};
var chat = new MultiTurnConversation(model) { Knowledge = knowledge };
var result = await chat.SubmitAsync("What is the refund window?");
Console.WriteLine(result.Content);
foreach (var source in result.Grounding.Citations)
{
Console.WriteLine($"[{source.CitationId}] {source.Title}, page {source.PageNumber}");
}
Remarks
Attach it to a MultiTurnConversation through
Knowledge, or to an agent through
WithKnowledge(AgentKnowledge). With
Always every user turn is searched (a follow-up is first
rewritten into a self-contained query) and the passages found are presented to the model as
reference context; with OnDemand the model searches through a
knowledge_search tool when it decides to.
Every passage gets a citation number assigned by the runtime, and every answer carries a KnowledgeGrounding verdict (Grounding, Grounding): the passages presented, the passages cited, and any cited number that was never presented. Passages are presented as data: an instruction written inside a passage is never followed.
One instance can serve several conversations: it holds settings only, and each conversation keeps its own citation state.
Constructors
- AgentKnowledge(IKnowledgeRetriever, KnowledgeRetrievalMode)
Creates knowledge backed by any retriever.
- AgentKnowledge(RagEngine, KnowledgeRetrievalMode)
Creates knowledge backed by a RagEngine (or a DocumentRag).
Properties
- CitationPolicy
Gets or sets how strictly the model must cite. Default Required.
- ContextualizationOptions
Gets the options of the follow-up rewrite.
- ContextualizeFollowUps
Gets or sets whether a follow-up question is rewritten into a self-contained query before the search (Always), so "and for orders over 100?" searches for what it means. Costs one short completion per follow-up. Default
true.
- MaxResults
Gets or sets the most passages one search returns. Clamped to [1, 50]. Default 5.
- MaximumTokens
Gets or sets the most tokens of passage text presented for one turn (Always). The best passages are kept first and none is cut, except a single passage larger than the whole budget. At least 64. Default 2048.
- MinScore
Gets or sets the relevance floor a passage must clear, or
nullfor the retriever's own default.
- Mode
Gets when the source is searched.
- Retriever
Gets the source of passages.
- WhenNoEvidence
Gets or sets what the model is told when a search finds nothing. Default Abstain.