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:
@@ -11,15 +11,16 @@ 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 Owner's Knowledge Base:
|
||||
/// Ingest Files into Specified Knowledge Scope:
|
||||
/// Extract -> Chunk -> Embed -> Store (XAiVector) ...
|
||||
/// </summary>
|
||||
/// <param name="files"></param>
|
||||
/// <param name="knowledgeType"></param>
|
||||
/// <param name="scope">Target Scope (Null = User Scope)</param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="replaceExisting"></param>
|
||||
@@ -27,7 +28,7 @@ namespace xAiApi.Interfaces
|
||||
/// <returns></returns>
|
||||
Task<XAiKnowledgeIngestResult> IngestAsync(
|
||||
IFormFileCollection files,
|
||||
string knowledgeType = null,
|
||||
XAiKnowledgeScopeDescriptor scope = null,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null,
|
||||
bool replaceExisting = true,
|
||||
@@ -35,21 +36,15 @@ namespace xAiApi.Interfaces
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Embed Prompt and Retrieve Relevant Chunks from Owner's Knowledge Base ...
|
||||
/// Embed Prompt and Retrieve Relevant Chunks (Tiered: Conversation -> Project -> User -> Global) ...
|
||||
/// </summary>
|
||||
/// <param name="prompt"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="topK"></param>
|
||||
/// <param name="minScore"></param>
|
||||
/// <param name="fileName">Optional: Restrict to a Specific File</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IList<XAiVectorSearchResult>> RetrieveAsync(
|
||||
string prompt,
|
||||
XAiKnowledgeAskRequest request,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
int? topK = null,
|
||||
float? minScore = null,
|
||||
string fileName = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
@@ -81,25 +76,41 @@ namespace xAiApi.Interfaces
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// List Ingested Documents of Owner ...
|
||||
/// 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 ...
|
||||
/// 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
|
||||
);
|
||||
@@ -113,4 +124,4 @@ namespace xAiApi.Interfaces
|
||||
IEnumerable<XAiVectorSearchResult> context
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user