Skip to main content
All docs
V26.1
  • IAIDocProcessingService.AskAIAsync(RichEditDocumentServer, String, RagOptions, CancellationToken) Method

    SECURITY-RELATED CONSIDERATIONS

    This API includes automatic prompt-injection protection for text and document-based AI-powered extensions. The system appends security instructions to each AI request to ensure that external or user-provided content is treated as untrusted data.

    Prompt Injection Protection in AI Extensions

    Returns a response to a custom question about the document content.

    Namespace: DevExpress.AIIntegration.Docs

    Assembly: DevExpress.AIIntegration.Docs.v26.1.dll

    Declaration

    Task<string> AskAIAsync(
        RichEditDocumentServer wordProcessor,
        string question,
        RagOptions options,
        CancellationToken cancellationToken = default(CancellationToken)
    )

    Parameters

    Name Type Description
    wordProcessor RichEditDocumentServer

    The RichEditDocumentServer instance that contains the content to be questioned.

    question String

    The question about the document content.

    options RagOptions

    An object that contains retrieval-augmented generation (RAG) options.

    Optional Parameters

    Name Type Default Description
    cancellationToken CancellationToken null

    The token that cancels the task.

    Returns

    Type Description
    Task<String>

    The response that contains an AI-generated answer.

    Example

    How to: Ask Contextual Question about a Word Document

    The following code snippet asks a question about the document content, configures RAG options (chunk size, collection name, chunk count), and inserts the AI‑generated answer as a comment about the first paragraph:

    using DevExpress.AIIntegration;
    using DevExpress.AIIntegration.Docs;
    using DevExpress.XtraRichEdit;
    using Microsoft.Extensions.AI;
    
    // See "Register AI extension service" section for implementation code
    var docProcessingService = 
        defaultAIExtensionsContainer.CreateAIDocProcessingService();
    
    var options = new RagOptions {
        VectorCollectionName = "document_embeddings",
        ChunkSize = 800,
        AugmentationChunkCount = 8
    };
    
    using (var wordProcessor = new RichEditDocumentServer()) {
        wordProcessor.LoadDocument(@"Documents/Document1.docx");
        string answer = await docProcessingService.AskAIAsync(
            wordProcessor,
            "Does this document contain any confidential information?",
            options
        );
    
        wordProcessor.Document.Comments.Create(
            wordProcessor.Document.Paragraphs[0].Range, 
            "AI Summary:\n" + answer);
        wordProcessor.SaveDocument("Documents/Document_commented.docx", DocumentFormat.Docx);
    }
    
    See Also