SmartDocumentAdapter
Overview
The SmartDocumentAdapter is like the SmartChatBoxAdapter but focuses on a single document and does not connect to a vector database. It can function either with or without a chat box, making it suitable for console or service applications where direct document querying is required.
Properties
In addition to the properties inherited from the SmartAdapter, the SmartDocumentAdapter exposes the following additional properties.
AutoReset
Determines whether the conversation history is cleared after each response. Preserves the messages in the connected ChatBox.
Default is false.
User
Represents the AI user in the ChatBox as an instance of the ChatBox.User class. This property is read-only and identifies the AI participant within the chat interface. To customize the AI’s display name or avatar, use the BotName and BotAvatar properties, respectively. The property itself cannot be reassigned, but you can modify the AI user's appearance through these options.
BotName
The BotName property specifies the display name of the AI bot within the ChatBox. By default, this name is set to "Wisej." You can use this property to assign a custom name to your bot, allowing you to better personalize the chat experience for your application’s users.
BotAvatar
The BotAvatar property specifies the image that represents the AI bot in the ChatBox. You can set this property to either the name of a built-in image or the URL of a custom image. This allows you to personalize the bot's appearance by displaying a specific avatar in the chat interface.
ChatBox
The ChatBox property is read-only and returns the instance of the ChatBox control associated with the adapter. This association is established when you call this.smartHub.GetAI(this.chatBox)
and assign the adapter using this.smartHub.GetAI(this.chatBox).Adapter = this.smartChatBoxAdapter
. The property provides access to the specific ChatBox control that is linked to the current AI adapter instance.
FilePath
The file path of the document.
Stream
This refers to the data stream that contains the entire content of the document.
FileType
Gets or sets the file type. i.e. .docx, .pdf, .txt. If null (default) it will be detected automatically.
TopN
TopN specifies the maximum number of qualifying chunks that are utilized to construct the RAG (Retrieval-Augmented Generation) context. A chunk is deemed qualified if its similarity score exceeds the threshold defined by MinSimilarity
. By setting the TopN
value, you determine how many of these high-similarity chunks will be included in the context for further processing, allowing you to balance between performance and accuracy according to your application's requirements.
MaxClusters
MaxClusters determines the upper limit on the number of clusters that can be generated by the summarization function, which utilizes the K-means clustering algorithm.
Default is 5.
MinSimilarity
The minimum similarity threshold is the lowest value at which the system will consider the user query and the documents chunks to be sufficiently similar to be included in the RAG context.
This threshold determines whether a match is recognized and can influence how strict or lenient the matching process is. By adjusting the minimum similarity threshold, you can control the sensitivity of the matching algorithm in identifying relevant or related content.
Default value is 0.25.
RerankingEnabled
This setting indicates whether reranking is enabled. When set to true, the system uses the current IRerankingService to reorder and, if necessary, truncate the document chunks that have been qualified through the vector similarity search.
Default is false.
ChatBox
The ChatBox property is read-only and returns the instance of the ChatBox control associated with the adapter. This association is established when you call this.smartHub.GetAI(this.chatBox)
and assign the adapter using this.smartHub.GetAI(this.chatBox).Adapter = this.smartDocumentAdapter
. The property provides access to the specific ChatBox control that is linked to the current AI adapter instance.
n addition to the events inherited from the SmartAdapter, the SmartChatBoxAdapter exposes the following additional events.
Methods
When using the SmartDocumentAdapter without a ChatBox, you can use the AskAsync event to query the connected document directly.
AskAsync
Sends a query to the AI model, utilizing the connected document to generate a Retrieval-Augmented Generation (RAG) context.
var adapter = new SmartDocumentAdapter
{
Hub = new SmartHub {
Endpoint = new OpenAIEndpoint { ApiKey = "..." }
},
FilePath = Application.MapPath("OperationalManual.pdf");
};
// The adapter will index the document once, on first use.
Console.WriteLine((await adapter.AskAsync("Steps to resolve error -663")).Text);
Console.WriteLine((await adapter.AskAsync("Where is the purge valve?")).Text);
ResetSession
Clears the history in the current session. The adapter will create a new session when it processes the next question.
Events
AnswerReceived
The AnswerReceived
event provides all the information related to the answer generated by the AI. Using this event, you can access the source text used to generate the answer or apply custom formatting to the response before it is displayed to the user.
e.Message
The agent message, includes the full text of the answer and the usage.
e.Answer
The original answer from the AI model. Can be changed.
e.SourceText
The text snipped used by the AI model to create its answer.
Last updated