Implement Chat With Documents (In-Memory RAG) ...

- Add XAiDocumentModels (IngestResult, AskRequest, Answer, AnswerChunk, Source, SessionInfo, RAGDescriptor DTOs);
- Add AskWithContextAsync and AskWithContextAsEnumerable (Context Actions) to IXAiServiceBase and XAIServiceBase;
- Add GetContextHistory and BuildContextBlock Helpers for Building RAG Chat History without Persisting;
- Rewrite ChatWithDocumentsController with Ingest, Ask, AskStream (SSE), Get Session and Delete Session Endpoints;
- Add XInMemoryVectorStoreCleanupService (BackgroundService) for Removing Expired Sessions Periodically;
- Add AddXAiChatWithDocuments DI Extension, Register Cleanup HostedService and use it in Startup;
- Add RAGDescriptor Property to XAiApiConfiguration and its Section to appsettings.Development.json;
- Add ChatWithDocuments System Prompt to Prompts in appsettings.Development.json;
- Add IsValid Extension Method for XAiDocumentAskRequest;
- Optimize XInMemoryVectorStore.Search (Query Embedding Converted once) and Refactor Formatting;
- Remove Unused Usings in XAIServiceBase and IXAiServiceBase;
- ...
This commit is contained in:
2026-10-25 22:24:39 +03:30
parent 47d8a19423
commit 47da04a594
11 changed files with 1349 additions and 171 deletions
+20 -1
View File
@@ -2,6 +2,7 @@ using System;
using OpenAI;
using System.Linq;
using OllamaSharp;
using xAiApi.Models;
using System.Net.Http;
using xAiApi.Constants;
using xAiModels.Models;
@@ -15,7 +16,6 @@ using xExceptions.Constants;
using Microsoft.Extensions.AI;
using System.Collections.Generic;
using System.ClientModel.Primitives;
using xAiApi.Models;
namespace xAiApi.Extensions
{
@@ -62,6 +62,25 @@ namespace xAiApi.Extensions
return result;
}
/// <summary>
/// Check Document Ask Request is Valid or not ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static bool IsValid(this XAiDocumentAskRequest source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.Prompt.IsNullOrEmpty() &&
!source.SessionId.IsDefaultGuid() &&
(!source.TopK.HasValue || source.TopK.Value > 0) &&
(!source.MinScore.HasValue || (source.MinScore.Value >= -1f && source.MinScore.Value <= 1f));
//
return result;
}
/// <summary>
/// Extract Default Model Descriptor ...
/// </summary>