Implement RAG Scopes, Remove ProxyController, Fix Pipeline Order and SSE Format

- 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.
This commit is contained in:
2026-10-29 19:59:18 +03:30
parent d3ecc8feea
commit 37d4e622e9
15 changed files with 940 additions and 610 deletions
+58 -13
View File
@@ -1,10 +1,5 @@
using xAiApi.Constants;
using xAiApi.Constants;
using System;
using xAiApi.Constants;
using xAiModels.Constants;
using System.Collections.Generic;
namespace xAiApi.Models
@@ -17,10 +12,10 @@ namespace xAiApi.Models
/// <summary>
/// Scope Kind ...
/// </summary>
public XAiKnowledgeScope Scope { get; set; }
public XAiKnowledgeScope Scope { get; set; } = XAiKnowledgeScope.User;
/// <summary>
/// Scope Identifier (ProjectId / ConversationId) - Null for Global ...
/// Scope Identifier (ProjectId / ConversationId) - Null for Global and User ...
/// </summary>
public Guid? ScopeId { get; set; }
@@ -29,20 +24,60 @@ namespace xAiApi.Models
/// </summary>
public string Type { get; set; }
//
public static XAiKnowledgeScopeDescriptor Global(string type = null) => new()
/// <summary>
/// Create User Scope Knowledge Descriptor ...
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public static XAiKnowledgeScopeDescriptor User(
string type = null
) => new()
{
Type = type,
ScopeId = null,
Scope = XAiKnowledgeScope.User,
};
/// <summary>
/// Create Global Scope Knowledge Descriptor ...
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public static XAiKnowledgeScopeDescriptor Global(
string type = null
) => new()
{
Type = type,
ScopeId = null,
Scope = XAiKnowledgeScope.Global,
};
public static XAiKnowledgeScopeDescriptor Project(Guid projectId, string type = null) => new()
/// <summary>
/// Create Project Scope Knowledge Descriptor ...
/// </summary>
/// <param name="projectId"></param>
/// <param name="type"></param>
/// <returns></returns>
public static XAiKnowledgeScopeDescriptor Project(
Guid projectId,
string type = null
) => new()
{
Type = type,
ScopeId = projectId,
Scope = XAiKnowledgeScope.Project,
};
public static XAiKnowledgeScopeDescriptor Conversation(Guid conversationId, string type = null) => new()
/// <summary>
/// Create Conversational Scope Knowledge Descriptor ...
/// </summary>
/// <param name="conversationId"></param>
/// <param name="type"></param>
/// <returns></returns>
public static XAiKnowledgeScopeDescriptor Conversation(
Guid conversationId,
string type = null
) => new()
{
Type = type,
ScopeId = conversationId,
@@ -98,7 +133,7 @@ namespace xAiApi.Models
/// <summary>
/// Ask Request over Persistent Knowledge Base ...
/// Retrieval is Tiered: Conversation -> Project -> Global (Each Tier Fills Remaining TopK) ...
/// Retrieval is Tiered: Conversation -> Project -> User -> Global (Each Tier Fills Remaining TopK) ...
/// </summary>
public class XAiKnowledgeAskRequest
{
@@ -118,6 +153,16 @@ namespace xAiApi.Models
/// </summary>
public Guid? ProjectId { get; set; }
/// <summary>
/// Include Personal (User) Knowledge Tier (default true) ...
/// </summary>
public bool IncludeUser { get; set; } = true;
/// <summary>
/// Include Global Knowledge Tier (default true) ...
/// </summary>
public bool IncludeGlobal { get; set; } = true;
/// <summary>
/// Optional: Restrict Retrieval to a Knowledge Type / Domain ...
/// </summary>