Class TemplateContextBuilder
IContextBuilder that uses a user-defined template with {context} and {question} placeholders.
public class TemplateContextBuilder : IContextBuilder
- Inheritance
-
TemplateContextBuilder
- Implements
- Inherited Members
Constructors
TemplateContextBuilder(string)
Creates a template-based context builder.
public TemplateContextBuilder(string template)
Parameters
templatestringTemplate string with placeholders: {context} โ replaced with numbered search results. {question} โ replaced with the user query.
Methods
BuildContext(string, IReadOnlyList<VectorSearchResult>)
Builds a context string from the user query and retrieved search results. The returned string is typically prepended to the LLM prompt as reference material.
public string BuildContext(string query, IReadOnlyList<VectorSearchResult> searchResults)
Parameters
querystringThe original user query.
searchResultsIReadOnlyList<VectorSearchResult>The top-K search results from the vector store.
Returns
- string
A formatted context string for the LLM.