<style>
table, th, td {
	border: 1px solid;
}
table th:first-of-type {
	width: 30%;
}
table th:nth-of-type(2) {
	width: 70%;
}
</style>

# CompleteContextQuestionProcessor

The `CompleteContextQuestionProcessor` class enables you to ask questions about a Word document and receive answers based on the entire document content. This processor sends the complete document text to the AI model. It is suitable for smaller documents or when you need to ensure that the AI model has access to all the information in the document. This class inherits from the abstract `AIProcessorBase` class, which provides common features for all AI processors.

The `CompleteContextQuestionProcessor` is ideal for the following scenarios:

* **Small Documents**—When the document is small enough to fit within the token limit of the AI model.
* **Holistic Understanding**—When the question requires understanding the entire document context.
* **No Embedding Required**—When you do not need the advanced embedding features of [PartialContextQuestionProcessor](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/gen-ai-powered-document-insights/partial-context-question-processor).

However, if you work with larger documents or want to optimize token usage, use the [PartialContextQuestionProcessor](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/gen-ai-powered-document-insights/partial-context-question-processor#when-to-use-partialcontextquestionprocessor) instead.

## Public API

| Property   | Description                                                                                                                                                                                                                                                                                                          |
| ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Settings` | Gets the settings for the AI question-answering process. Returns [CompleteContextProcessorSettings](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/gen-ai-powered-document-insights/complete-context-question-processor#completecontextprocessorsettings). |

| Method                                                                             | Description                                                                                                                                                                                                                                                                |
| ---------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `public Task<string> AnswerQuestion(SimpleTextDocument document, string question)` | Answers a question using the provided document. Parameters: `document` - The document containing the text to process, `question` - The question to answer. Returns a task that represents the asynchronous operation. The task result contains the answer to the question. |

> caution **Security Warning:** The output produced by this API is generated by a Large Language Model (LLM). The content must be considered untrusted and may include unexpected or unsafe data. Properly sanitize or encode all output before displaying it in a user interface, logging, or using it in any security-sensitive context.

## CompleteContextProcessorSettings

The `CompleteContextProcessorSettings` class defines configuration options for the question-answering process. You set the following read-only properties only through the constructor:

| Property                      | Description                                                                                                                         |
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| `ModelMaxInputTokenLimit`     | The maximum input token limit the model allows.                                                                                     |
| `ModelId`                     | The ID of the model.                                                                                                                |
| `TokenizationEncoding`        | The tokenization encoding.                                                                                                          |
| `ProduceJsonFormattedContext` | Determines whether the context sent to the model is in JSON or plain text format, if JSON format is applicable. Default is `false`. |

## Usage Example

The following example demonstrates how to use the `CompleteContextQuestionProcessor` to ask questions about a Word document, including working with specific document pages. For setting up the AI client as shown in this example, see the [AI Provider Setup](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/gen-ai-powered-document-insights/prerequisites#ai-provider-setup) section:

**Example 1: Load a DOCX file, configure Azure OpenAI, and ask full-document questions with CompleteContextQuestionProcessor**

```C#

public async Task AskQuestionUsingCompleteContext()
{
    // Load the Docx document
    string filePath = @"path\to\your\document.docx";
    DocxFormatProvider formatProvider = new DocxFormatProvider();
    RadFlowDocument flowDocument;

    using (FileStream fs = File.OpenRead(filePath))
    {
        flowDocument = formatProvider.Import(fs, TimeSpan.FromSeconds(10));
    }

    // Set up the AI client (Azure OpenAI in this example)
    string key = "AZUREOPENAI_KEY";
    string endpoint = "AZUREOPENAI_ENDPOINT";
    string model = "gpt-4o-mini";

    Azure.AI.OpenAI.AzureOpenAIClient azureClient = new AzureOpenAIClient(
        new Uri(endpoint),
        new Azure.AzureKeyCredential(key),
        new Azure.AI.OpenAI.AzureOpenAIClientOptions());
    ChatClient chatClient = azureClient.GetChatClient(model);

    IChatClient iChatClient = (IChatClient)chatClient;
    int maxTokenCount = 128000;
    string tokenizationEncoding = "cl100k_base";

    // Create the processor
    CompleteContextProcessorSettings settings = new CompleteContextProcessorSettings(maxTokenCount, model, tokenizationEncoding, false);

    using (CompleteContextQuestionProcessor processor = new CompleteContextQuestionProcessor(iChatClient, settings))
    {
        // Example 1: Process full document
        // Convert the document to a simple text representation
        SimpleTextDocument plainDoc = flowDocument.ToSimpleTextDocument(TimeSpan.FromSeconds(10));

        // Ask a question about the full document
        string question = "What is the main subject of this document?";
        string answer = await processor.AnswerQuestion(plainDoc, question);

        Console.WriteLine($"Question: {question}");
        Console.WriteLine($"Answer: {answer}");

        // Ask another question
        string question2 = "What are the key conclusions drawn in this document?";
        string answer2 = await processor.AnswerQuestion(plainDoc, question2);

        Console.WriteLine($"Question: {question2}");
        Console.WriteLine($"Answer: {answer2}");              
    }
}

```

## See Also

* [GenAI-powered Document Insights Overview](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/gen-ai-powered-document-insights/overview)
* [Prerequisites](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/gen-ai-powered-document-insights/prerequisites)
* [SummarizationProcessor](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/gen-ai-powered-document-insights/summarization-processor)
* [PartialContextQuestionProcessor](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/gen-ai-powered-document-insights/partial-context-question-processor)
