Table of Contents

Class SemanticRetrieverChatSession

Namespace
GenerativeAI
Assembly
GenerativeAI.dll

Represents a chat session that interacts with a semantic retriever model to generate answers based on user queries. Includes functionality for maintaining session history, managing configurations, and handling responses from the model.

public class SemanticRetrieverChatSession
Inheritance
SemanticRetrieverChatSession
Inherited Members
Extension Methods

Constructors

SemanticRetrieverChatSession(SemanticRetrieverModel, string, AnswerStyle?, List<Content>?, List<SafetySetting>?)

Represents a chat session that utilizes the semantic retriever model to generate answers.

public SemanticRetrieverChatSession(SemanticRetrieverModel model, string corpusId, AnswerStyle? answerStyle = AnswerStyle.VERBOSE, List<Content>? history = null, List<SafetySetting>? safetySettings = null)

Parameters

model SemanticRetrieverModel
corpusId string
answerStyle AnswerStyle?
history List<Content>
safetySettings List<SafetySetting>

Properties

History

Gets or sets the history of the current chat session, representing a collection of user and model interactions recorded throughout the session. Updates to this property will reset both LastRequestContent and LastResponseContent.

public List<Content> History { get; set; }

Property Value

List<Content>

Remarks

Assigning a new value to this property effectively resets the session, clearing any previously tracked request or response content. The history contains instances of Content that represent messages exchanged between the user and the model.

LastRequestContent

Gets the content of the last request made in the current chat session, allowing access to the most recently sent message or query. This property is updated each time a request is successfully made within the session.

public Content? LastRequestContent { get; }

Property Value

Content

Remarks

The value of this property is null if no request has been made or if the session was reset by assigning a new history to the History property.

LastResponseContent

Gets the content of the last response received in the current chat session, providing access to the most recently generated reply or output from the model. This property is updated each time a response is successfully received within the session.

public Content? LastResponseContent { get; }

Property Value

Content

Remarks

The value of this property is null if no response has been received or if the session was reset by assigning a new history to the History property.

Methods

GenerateAnswerAsync(string, CancellationToken)

Asynchronously generates an answer for the specified user query using the semantic retriever model. Updates the session history with the request and response contents.

public Task<GenerateAnswerResponse> GenerateAnswerAsync(string query, CancellationToken cancellationToken = default)

Parameters

query string

The user's query for which an answer is to be generated.

cancellationToken CancellationToken

Optional cancellation token to cancel the operation.

Returns

Task<GenerateAnswerResponse>

A GenerateAnswerResponse containing the model's response to the query.