Files
xSaherElmAiApi/Interfaces/IXAiRAGService.cs
T
saherelm ad8ea9c1dd 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.
2026-10-30 19:46:20 +03:30

100 lines
3.9 KiB
C#

using xAiApi.Models;
using System.Threading;
using xAiModels.Models.Dtos;
using System.Threading.Tasks;
using xIdentityModels.Models;
using Microsoft.AspNetCore.Http;
using System.Collections.Generic;
namespace xAiApi.Interfaces
{
/// <summary>
/// Persistent RAG Service over XAiVector Table:
/// Ingest (Extract -> Chunk -> Embed -> Store) and Ask (Embed -> Search -> Generate) ...
/// Isolation is Scope Based (Conversation / Project / User / Global) ...
/// </summary>
public interface IXAiRAGService
{
/// <summary>
/// Ingest Files into Specified Knowledge Scope:
/// Extract -> Chunk -> Embed -> Store (XAiVector) ...
/// </summary>
/// <param name="files"></param>
/// <param name="scope">Target Scope (Null = User Scope)</param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <param name="replaceExisting"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XAiKnowledgeIngestResult> IngestAsync(
IFormFileCollection files,
XAiKnowledgeScopeDescriptor scope = null,
XUserClaimsInfoDto userInfo = null,
string connectionId = null,
bool replaceExisting = true,
CancellationToken cancellationToken = default
);
/// <summary>
/// Embed Prompt and Retrieve Relevant Chunks (Tiered: Conversation -> Project -> User -> Global) ...
/// </summary>
/// <param name="request"></param>
/// <param name="userInfo"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IList<XAiVectorSearchResult>> RetrieveAsync(
XAiKnowledgeAskRequest request,
XUserClaimsInfoDto userInfo = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// List Ingested Documents of Specified Scope ...
/// </summary>
/// <param name="scope">Target Scope (Null = User Scope)</param>
/// <param name="userInfo"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IList<XAiKnowledgeDocumentInfo>> LoadDocumentsAsync(
XAiKnowledgeScopeDescriptor scope = null,
XUserClaimsInfoDto userInfo = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Remove All Vectors of a Document in Specified Scope ...
/// </summary>
/// <param name="fileName"></param>
/// <param name="scope">Target Scope (Null = User Scope)</param>
/// <param name="userInfo"></param>
/// <param name="cancellationToken"></param>
/// <returns>Count of Removed Vectors</returns>
Task<int> RemoveDocumentAsync(
string fileName,
XAiKnowledgeScopeDescriptor scope = null,
XUserClaimsInfoDto userInfo = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Migrate Legacy Vectors of Owner ("{ownerId}/{fileName}#i") into User Scope ("user/{ownerId}/{fileName}#i") ...
/// Idempotent: Returns 0 when Nothing Left to Migrate ...
/// </summary>
/// <param name="userInfo"></param>
/// <param name="cancellationToken"></param>
/// <returns>Count of Migrated Vectors</returns>
Task<int> MigrateLegacyVectorsAsync(
XUserClaimsInfoDto userInfo = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Map Search Results to Public Sources ...
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
IList<XAiDocumentSource> ToSources(
IEnumerable<XAiVectorSearchResult> context
);
}
}