- RAG: real scopes with identifiers conversation/{id}/, project/{id}/, user/{ownerId}/, global/;
- RAG: ownership checks via GetProject/GetConversation; Global write requires admin role;
- RAG: tiered retrieval Conversation -> Project -> User -> Global (single embedding, dedup, TopK fill);
- RAG: apply Type filter, sanitize file names, enforce MaxFilesPerIngest/MaxFileSizeBytes/MaxDocumentsPerScope;
- RAG: store scope/scopeId/type/ownerId metadata; return it in documents and sources;
- RAG: add MigrateLegacyVectorsAsync + POST /Knowledge/MigrateLegacy ({ownerId}/... -> user/{ownerId}/...);
- Knowledge API: scope/scopeId on Ingest, Documents, DELETE Documents;
- Remove ProxyController (root route "{modelName}/{path}" + AllowAnonymous hijacked all 2-segment paths);
- Startup: ExceptionHandler("/error") + HSTS outside Development; Swagger only in Development;
static files before routing; CORS before model proxy; add /error endpoint;
- SSE: all stream endpoints use xHttpService XSseExtensions; validate before streaming;
pre-stream errors return proper HTTP status; remove "Connection: keep-alive";
- Use xAiModels.Constants for XAiKnowledgeScope / Knowledge constants / XOpenAINoKey;
- Register XAiVectorEntityRegisterar in XAiApiDbContext;
- XCodeFileContentExtractor: actually read stream content; drop hard-coded "book.epub".
BREAKING: AskTextStream emits data: {"text":"..."}; AskStream emits data: {json}; both end with event: done.
127 lines
4.9 KiB
C#
127 lines
4.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>
|
|
/// Ask a Question with RAG (Retrieve from DB then Generate) ...
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
Task<XAiDocumentAnswer> AskWithRAGAsync(
|
|
XAiKnowledgeAskRequest request,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
CancellationToken cancellationToken = default
|
|
);
|
|
|
|
/// <summary>
|
|
/// Ask a Question with RAG and Stream Response ...
|
|
/// First Item Carries Sources, Next Items Carry Text Deltas, Last Item has IsFinal = true ...
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
IAsyncEnumerable<XAiDocumentAnswerChunk> AskWithRAGAsEnumerable(
|
|
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
|
|
);
|
|
}
|
|
} |