Integrate RAG into Chat Pipeline and Decouple Embedding Service

- AskAsync: accept Guid? projectId / conversationId; resolve defaults;
- AskAsync: ingest attached files into Conversation scope (replaceExisting)
  via IXAiRAGService instead of Upload + Extract + raw content attachment;
- AskAsync: retrieve context (Conversation -> Project -> User -> Global)
  and build a single System message: Introduction + ChatWithDocuments prompt
  + Context block (+ Project prompt);
- XAIServiceBase / XDefaultAiService / XDefaultThinkingAiService:
  inject IXAiRAGService instead of IXFileProvider;
- Add IXAiEmbeddingService + XAiEmbeddingService; remove
  IXDefaultEmbeddingService + XDefaultEmbeddingService;
- XAiEmbeddingServiceBase no longer inherits XAIServiceBase;
  IXAiEmbeddingServiceBase / IXAiEmbeddingServiceControllerBase no longer
  extend chat interfaces; XAiEmbeddingServiceControllerBase derives from
  XBaseIdentityApiV1Controller;
- XAiRAGService: drop IXDefaultAiService dependency (removes circular
  dependency); remove AskWithRAGAsync / AskWithRAGAsEnumerable; add file
  reference (AddReference) for scoped ingests;
- KnowledgeController: remove POST Ask and POST AskStream;
- DI: add AddXRagService() and call it from Startup before AddXAiServices();
- Add XAiApiRagPromptName = "ChatWithDocuments";
- Knowledge scope factories default Type to XAiDefaultKnowledgeType;
- ChatWithDocuments ask request: TopK and MinScore are now required.
BREAKING: /Knowledge/Ask and /Knowledge/AskStream removed;
          IXDefaultEmbeddingService replaced by IXAiEmbeddingService.
This commit is contained in:
2026-10-30 19:46:20 +03:30
parent 37d4e622e9
commit ad8ea9c1dd
22 changed files with 343 additions and 655 deletions
+11 -13
View File
@@ -17,7 +17,6 @@ using xAiModels.Interfaces;
using xAiApi.Configurations;
using xExceptions.Constants;
using System.Threading.Tasks;
using xFileService.Interfaces;
using Microsoft.Extensions.AI;
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
@@ -29,28 +28,23 @@ namespace xAiApi.Providers
/// <summary>
/// Base Embedding Provider Service ...
/// </summary>
public abstract class XAiEmbeddingServiceBase : XAIServiceBase, IXAiEmbeddingServiceBase
public abstract class XAiEmbeddingServiceBase : IXAiEmbeddingServiceBase
{
private readonly IXFileProvider fileProvider;
private readonly string embeddingModelName;
private readonly XAiModelDescriptor descriptor;
private readonly IXAiDataProvider dataProvider;
private readonly XAiApiConfiguration configuration;
private readonly XValidationProvider validationProvider;
private readonly ILogger<XAiEmbeddingServiceBase> logger;
private readonly IXFileContentExtractor fileContentExtractor;
protected XAiEmbeddingServiceBase(
IXFileProvider fileProvider,
IXAiDataProvider dataProvider,
XAiApiConfiguration configuration,
XValidationProvider validationProvider,
ILogger<XAiEmbeddingServiceBase> logger,
IXFileContentExtractor fileContentExtractor,
string embeddingModelName = XAiApiConstants.XAiEmbeddingModelName
) : base(
fileProvider,
dataProvider,
logger,
configuration,
validationProvider,
fileContentExtractor,
null
)
{
//
@@ -61,10 +55,14 @@ namespace xAiApi.Providers
XException.InvalidConfiguration.Throw();
}
this.fileProvider = fileProvider;
this.dataProvider = dataProvider;
this.configuration = configuration;
this.validationProvider = validationProvider;
//
this.logger = logger;
this.fileContentExtractor = fileContentExtractor;
this.embeddingModelName = embeddingModelName;
}
/// <summary>