@page "/intelligence" @attribute [Authorize] @using NexusReader.Application.DTOs.AI @using NexusReader.Application.Abstractions.Services @using NexusReader.Application.DTOs.User @using System.Net.Http.Json @inject HttpClient Http @inject IKnowledgeService KnowledgeService @inject AuthenticationStateProvider AuthStateProvider

Global AI Q&A

Search, interrogate, and extract grounded facts from your library using Polyglot KM-RAG

@if (_isLoading) {
Analyzing conceptual graph and synthesizing response...
} else if (_response != null) {

Answer

@_response.Answer
@if (_response.Citations != null && _response.Citations.Any()) {

Grounded Citations

@foreach (var citation in _response.Citations) {
@citation.SourceBook @if (!string.IsNullOrEmpty(citation.CitationId) && citation.CitationId.Length > 8) { ID: @citation.CitationId.Substring(0, Math.Min(8, citation.CitationId.Length)) }
"@citation.Snippet"
}
}
} else if (_hasSearched) {

No answers generated. Try adjusting your question.

} else {

Start Interrogating Your Library

Ask complex questions across all your books. The system will search vectors, pull concept graph relations, and formulate a grounded answer with precise citations.

}
@code { private string _question = string.Empty; private string _selectedBookId = string.Empty; private bool _isLoading; private bool _hasSearched; private GroundedResponseDto? _response; private List? _books; protected override async Task OnInitializedAsync() { try { _books = await Http.GetFromJsonAsync>("api/library/books"); } catch (Exception ex) { Console.WriteLine($"[Intelligence] Failed to load books for scope selector: {ex.Message}"); } } private async Task HandleKeyUp(KeyboardEventArgs e) { if (e.Key == "Enter" && !string.IsNullOrWhiteSpace(_question) && !_isLoading) { await AskQuestionAsync(); } } private async Task AskQuestionAsync() { if (string.IsNullOrWhiteSpace(_question) || _isLoading) return; _isLoading = true; _hasSearched = true; _response = null; StateHasChanged(); try { Guid? ebookId = null; if (!string.IsNullOrEmpty(_selectedBookId) && Guid.TryParse(_selectedBookId, out var parsedId)) { ebookId = parsedId; } var authState = await AuthStateProvider.GetAuthenticationStateAsync(); var tenantId = authState.User.FindFirst("TenantId")?.Value ?? "global"; var result = await KnowledgeService.AskQuestionAsync(_question, tenantId, ebookId); if (result.IsSuccess) { _response = result.Value; } else { _response = new GroundedResponseDto { Answer = $"Error: {result.Errors.FirstOrDefault()?.Message ?? "An error occurred."}", Citations = new List() }; } } catch (Exception ex) { _response = new GroundedResponseDto { Answer = $"Network/API Error: {ex.Message}", Citations = new List() }; } finally { _isLoading = false; StateHasChanged(); } } }