- Update submodule pointers: xAiApi, Modules/xAiModels;

- Kanban: move "R&D about MCP Servers" to Test, check "Test Rag Documents
  by Chat", add "Adding MCP Support ...";
- Authenticate.json: refresh sample tokens/session and add ask samples;
- Add Documents/Codes/*.BKP.cs (pre-refactor backups);
- Add Documents/Docs/ChangeLogs/1405-08-08-v01.html and this file.
This commit is contained in:
2026-10-30 19:46:42 +03:30
parent e6f8e649ac
commit 888f20ea63
13 changed files with 4619 additions and 709 deletions
+19 -10
View File
@@ -471,15 +471,6 @@
"labels": [],
"checkboxes": [],
"comments": []
},
{
"id": "7785aecc-0b27-4428-a50b-03c046c5a0d6",
"listId": "1706107f-ace2-4240-aa32-3d2031264a41",
"title": "R&D about MCP Servers and how i can Use them ?",
"description": "",
"labels": [],
"checkboxes": [],
"comments": []
}
]
},
@@ -562,7 +553,7 @@
{
"id": "5814763a-fb4f-45d6-bef4-730d67be00aa",
"title": "Test Rag Documents by Chat ...",
"checked": false
"checked": true
},
{
"id": "51e10834-6ff5-4f29-8bda-70edf9f0206f",
@@ -635,6 +626,15 @@
"labels": [],
"checkboxes": [],
"comments": []
},
{
"id": "affe9030-49a3-4937-813a-35f81189039c",
"listId": "171f43f3-ae73-49b7-9239-9f3fb695cc2b",
"title": "Adding MCP Support ...",
"description": "",
"labels": [],
"checkboxes": [],
"comments": []
}
]
},
@@ -642,6 +642,15 @@
"id": "8c15334f-3b2e-4eca-999e-4c887cb628e9",
"title": "Test",
"cards": [
{
"id": "7785aecc-0b27-4428-a50b-03c046c5a0d6",
"listId": "8c15334f-3b2e-4eca-999e-4c887cb628e9",
"title": "R&D about MCP Servers and how i can Use them ?",
"description": "",
"labels": [],
"checkboxes": [],
"comments": []
},
{
"id": "c4633423-da53-4942-a9b4-d5f23b5759b3",
"listId": "8c15334f-3b2e-4eca-999e-4c887cb628e9",
+146
View File
@@ -0,0 +1,146 @@
/// <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>
/// 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>
public async Task<XAiDocumentAnswer> AskWithRAGAsync(
XAiKnowledgeAskRequest request,
XUserClaimsInfoDto userInfo = null,
CancellationToken cancellationToken = default
)
{
//
// Retrieve (Validates Request) ...
var context = await RetrieveAsync(
request: request,
userInfo: userInfo,
cancellationToken: cancellationToken
);
//
var result = new XAiDocumentAnswer
{
Sources = ToSources(context)
};
if (!context.HasChild())
{
//
result.NoContextFound = true;
return result;
}
//
// Generate ...
result.Answer = await aiService.AskWithContextAsync(
context: context,
prompt: request.Prompt,
cancellationToken: cancellationToken
);
//
return result;
}
/// <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>
public async IAsyncEnumerable<XAiDocumentAnswerChunk> AskWithRAGAsEnumerable(
XAiKnowledgeAskRequest request,
XUserClaimsInfoDto userInfo = null,
[EnumeratorCancellation]
CancellationToken cancellationToken = default
)
{
//
// Retrieve (Validates Request) ...
var context = await RetrieveAsync(
request: request,
userInfo: userInfo,
cancellationToken: cancellationToken
);
//
// First Item: Sources ...
var hasContext = context.HasChild();
yield return new XAiDocumentAnswerChunk
{
Text = string.Empty,
IsFinal = !hasContext,
NoContextFound = !hasContext,
Sources = ToSources(context)
};
if (!hasContext)
{
yield break;
}
//
// Stream Deltas ...
var enumerable = aiService.AskWithContextAsEnumerable(
context: context,
prompt: request.Prompt,
cancellationToken: cancellationToken
);
await foreach (var delta in enumerable)
{
//
if (cancellationToken.IsCancellationRequested)
{
yield break;
}
//
if (delta.IsNullOrEmpty())
{
continue;
}
//
yield return new XAiDocumentAnswerChunk { Text = delta };
}
//
// Final Item ...
yield return new XAiDocumentAnswerChunk
{
Text = string.Empty,
IsFinal = true
};
}
+369
View File
@@ -0,0 +1,369 @@
using System;
using xAiApi.Models;
using System.Threading;
using xAiApi.Interfaces;
using xCommons.Providers;
using xAiModels.Constants;
using xCommons.Extensions;
using xExceptions.Constants;
using System.Threading.Tasks;
using xHttpService.Extensions;
using xCommons.Configurations;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using System.Collections.Generic;
using xIdentityService.Interfaces;
using xIdentityService.Controllers;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Authorization;
namespace xAiApi.Controllers
{
/// <summary>
/// Knowledge (Persistent RAG over XAiVector Table) Controller ...
/// Flow: Ingest Files -> Ask / AskStream (Retrieve from DB -> Generate) -> Documents / Delete
/// </summary>
[Authorize]
[Route("[controller]")]
public class KnowledgeController : XBaseIdentityApiV1Controller
{
/// <summary>
/// Persistent RAG Service ...
/// </summary>
private readonly IXAiRAGService ragService;
private readonly IXAiServiceBase aiServiceBase;
public KnowledgeController(
IXAiRAGService ragService,
IXAiServiceBase aiServiceBase,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
ILogger<KnowledgeController> logger,
XValidationProvider validationProvider
) : base(logger, appConfiguration, identityProvider, validationProvider)
{
//
this.ragService = ragService;
this.aiServiceBase = aiServiceBase;
}
//
#region Ingest ...
/// <summary>
/// Ingest Files into a Knowledge Scope:
/// Extract -> Chunk -> Embed -> Store in XAiVector Table ...
/// </summary>
/// <param name="files"></param>
/// <param name="scope">Target Scope: User (default) / Project / Conversation / Global (Admin)</param>
/// <param name="scopeId">ProjectId or ConversationId (Required for Project / Conversation)</param>
/// <param name="knowledgeType">Optional Knowledge Type / Domain</param>
/// <param name="replaceExisting">Replace Previously Stored Vectors of Same File (default true)</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("Ingest")]
[Consumes("multipart/form-data")]
public async Task<ActionResult<XAiKnowledgeIngestResult>> Ingest(
[FromForm] IFormFileCollection files,
[FromForm] XAiKnowledgeScope scope = XAiKnowledgeScope.Global,
[FromForm] Guid? scopeId = null,
[FromForm] string knowledgeType = null,
[FromForm] bool replaceExisting = true,
CancellationToken cancellationToken = default
)
{
//
try
{
//
// Validate ...
if (!files.HasChild())
{
XException.InvalidArgs.Throw();
}
//
var userInfo = await GetUserInfo();
var connectionId = GetConnectionId();
//
var result = await ragService.IngestAsync(
files: files,
userInfo: userInfo,
connectionId: connectionId,
replaceExisting: replaceExisting,
cancellationToken: cancellationToken,
scope: BuildScope(scope, scopeId, knowledgeType)
);
//
return Ok(result);
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
#endregion
//
#region Ask ...
/// <summary>
/// Ask a Question over Knowledge Base (RAG) ...
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("Ask")]
public async Task<ActionResult<XAiDocumentAnswer>> Ask(
[FromBody] XAiKnowledgeAskRequest request,
CancellationToken cancellationToken = default
)
{
//
try
{
//
// Validate ...
if (request.IsNullOrDefault() || request.Prompt.IsNullOrEmpty())
{
XException.InvalidArgs.Throw();
}
//
var userInfo = await GetUserInfo();
//
var result = await aiServiceBase.AskWithRAGAsync(
request: request,
userInfo: userInfo,
cancellationToken: cancellationToken
);
//
return Ok(result);
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Ask a Question over Knowledge Base and Stream Response (SSE) ...
/// First Event Carries Sources, Next Events Carry Text Deltas, Last Event has isFinal = true ...
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("AskStream")]
public async Task AskStream(
[FromBody] XAiKnowledgeAskRequest request,
CancellationToken cancellationToken = default
)
{
//
// Validate (before Stream Starts -> Proper Http Error) ...
if (request.IsNullOrDefault() || request.Prompt.IsNullOrEmpty())
{
Response.StatusCode = StatusCodes.Status400BadRequest;
Response.ContentType = "application/json; charset=utf-8";
await Response.WriteAsync(XException.InvalidArgs.ToXError().ToJSON());
return;
}
//
try
{
//
var userInfo = await GetUserInfo();
//
await using var enumerator = ragService
.AskWithRAGAsEnumerable(
request: request,
userInfo: userInfo,
cancellationToken: cancellationToken
)
.GetAsyncEnumerator(cancellationToken);
//
// Pull First Item before Starting Stream, so Scope / Ownership /
// Retrieval Errors are Returned as Regular Http Errors ...
var hasItem = await enumerator.MoveNextAsync();
//
// Configure SSE Response ...
Response.PrepareSseResponse();
//
while (hasItem)
{
//
var chunk = enumerator.Current;
if (!chunk.IsNullOrDefault())
{
await WriteChunk(chunk, cancellationToken);
}
//
hasItem = await enumerator.MoveNextAsync();
}
//
await Response.WriteSseDoneAsync(cancellationToken);
}
catch (Exception ex) when (ex.IsClientCancellation(cancellationToken))
{
// Client Disconnected ...
}
catch (Exception ex)
{
//
Logger.LogError(ex, "Knowledge: AskStream Failed");
if (!Response.HasStarted)
{
//
var result = GetExceptionActionResult(ex);
await result.ExecuteResultAsync(ControllerContext);
return;
}
//
await Response.WriteSseErrorAsync(ex.Message);
}
}
#endregion
//
#region Documents ...
/// <summary>
/// List Ingested Documents of a Knowledge Scope ...
/// </summary>
/// <param name="scope">User (default) / Project / Conversation / Global</param>
/// <param name="scopeId">ProjectId or ConversationId (Required for Project / Conversation)</param>
/// <param name="knowledgeType">Optional Knowledge Type Filter</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("Documents")]
public async Task<ActionResult<IList<XAiKnowledgeDocumentInfo>>> Documents(
[FromQuery] XAiKnowledgeScope scope = XAiKnowledgeScope.User,
[FromQuery] Guid? scopeId = null,
[FromQuery] string knowledgeType = null,
CancellationToken cancellationToken = default
)
{
//
try
{
//
var userInfo = await GetUserInfo();
//
var result = await ragService.LoadDocumentsAsync(
userInfo: userInfo,
cancellationToken: cancellationToken,
scope: BuildScope(scope, scopeId, knowledgeType)
);
//
return Ok(result);
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Remove All Vectors of a Document in a Knowledge Scope ...
/// </summary>
/// <param name="fileName"></param>
/// <param name="scope">User (default) / Project / Conversation / Global (Admin)</param>
/// <param name="scopeId">ProjectId or ConversationId (Required for Project / Conversation)</param>
/// <param name="cancellationToken"></param>
/// <returns>Count of Removed Vectors</returns>
[HttpDelete("Documents")]
public async Task<ActionResult<int>> DeleteDocument(
[FromQuery] string fileName,
[FromQuery] XAiKnowledgeScope scope = XAiKnowledgeScope.User,
[FromQuery] Guid? scopeId = null,
CancellationToken cancellationToken = default
)
{
//
try
{
//
// Validate ...
ValidationProvider.NotEmpty(fileName);
//
var userInfo = await GetUserInfo();
//
var result = await ragService.RemoveDocumentAsync(
fileName: fileName,
userInfo: userInfo,
cancellationToken: cancellationToken,
scope: BuildScope(scope, scopeId, null)
);
//
return Ok(result);
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
#endregion
//
#region Private ...
/// <summary>
/// Build Scope Descriptor from Request Params ...
/// </summary>
private XAiKnowledgeScopeDescriptor BuildScope(
XAiKnowledgeScope scope,
Guid? scopeId,
string knowledgeType
)
{
//
var result = new XAiKnowledgeScopeDescriptor
{
Scope = scope,
ScopeId = scopeId,
Type = knowledgeType,
};
//
return result;
}
/// <summary>
/// Write a SSE Event ...
/// </summary>
private Task WriteChunk(
XAiDocumentAnswerChunk chunk,
CancellationToken cancellationToken
)
{
//
return Response.WriteSseEventAsync(
data: chunk,
cancellationToken: cancellationToken
);
}
#endregion
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,670 @@
<!doctype html>
<html
lang="fa"
dir="rtl"
>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1"
/>
<title>ChangeLog ۱۴۰۵/۰۸/۰۸ v01 - RAG in Chat Pipeline</title>
<style>
body {
margin: 0;
padding: 24px;
background: #f4f7fb;
color: #172033;
font-family: Tahoma, 'Segoe UI', sans-serif;
line-height: 1.9;
}
.wrap {
max-width: 1180px;
margin: auto;
background: #fff;
border-radius: 16px;
box-shadow: 0 12px 40px #20386422;
overflow: hidden;
}
.hero {
padding: 38px;
background: linear-gradient(135deg, #173b78, #2563eb);
color: #fff;
}
.meta {
display: flex;
gap: 24px;
flex-wrap: wrap;
padding: 16px 30px;
background: #f8fafc;
color: #53627a;
}
main {
padding: 30px;
}
.section {
margin-bottom: 26px;
padding: 22px;
background: #f4f7fb;
border-right: 5px solid #2563eb;
border-radius: 10px;
}
.section h2 {
color: #173b78;
border-bottom: 1px solid #dbe3ef;
padding-bottom: 8px;
}
.section h3 {
color: #1e40af;
margin-bottom: 4px;
}
table {
width: 100%;
border-collapse: collapse;
background: #fff;
margin: 12px 0;
}
th,
td {
text-align: right;
vertical-align: top;
padding: 10px 12px;
border-bottom: 1px solid #dbe3ef;
}
th {
background: #173b78;
color: #fff;
}
code {
direction: ltr;
display: inline-block;
background: #e7edf6;
border-radius: 4px;
padding: 0 5px;
font-family: Consolas, monospace;
}
pre {
direction: ltr;
text-align: left;
overflow: auto;
background: #172033;
color: #e7eefc;
border-radius: 7px;
padding: 14px;
}
.note,
.warn {
padding: 13px 16px;
border-radius: 7px;
margin-top: 12px;
}
.note {
background: #eff6ff;
border-right: 4px solid #2563eb;
}
.warn {
background: #fff7ed;
border-right: 4px solid #b45309;
}
.badge {
display: inline-block;
color: #fff;
border-radius: 15px;
padding: 1px 10px;
font-size: 0.8em;
}
.mod {
background: #b45309;
}
.new {
background: #087f5b;
}
.del {
background: #b91c1c;
}
.sub {
background: #6d28d9;
}
footer {
text-align: center;
color: #68758a;
padding: 18px;
border-top: 1px solid #dbe3ef;
}
</style>
</head>
<body>
<div class="wrap">
<header class="hero">
<h1>گزارش تغییرات ساختار پروژه</h1>
<p>
xSaherelmWorkspace | تاریخ: ۱۴۰۵/۰۸/۰۸ (2026-10-30) | نسخه
مستند: <strong>v01</strong>
</p>
<p>
موضوع: ادغام RAG در جریان اصلی گفتگو (AskAsync)، جداسازی
سرویس Embedding از سرویس AI، حذف Ask/AskStream از
KnowledgeController و Nullable شدن Project/Conversation در
درخواست پاسخ
</p>
</header>
<div class="meta">
<span
><strong>دامنه:</strong> <code>xAiApi</code>،
<code>Modules/xAiModels</code>، ریشهٔ Workspace</span
>
<span><strong>Build:</strong> 0 Error(s)</span>
<span><strong>xAiApi:</strong> 21 فایل، +332 / −678 (+۲ فایل جدید)</span>
</div>
<main>
<section class="section">
<h2>۱. خلاصه</h2>
<p>
در این مرحله، بازیابی دانش (RAG) که تا قبل فقط از طریق
Endpointهای جداگانهٔ <code>/Knowledge/Ask</code> و
<code>/Knowledge/AskStream</code> در دسترس بود، مستقیماً
وارد جریان اصلی گفتگو (<code>XAIServiceBase.AskAsync</code>)
شد. فایل‌های پیوست یک پیام اکنون به‌جای آپلود ساده و تزریق
محتوای خام در پیام، در Scope همان Conversation
<b>Ingest</b> می‌شوند و Context بازیابی‌شده (Conversation →
Project → User → Global) در System Prompt قرار می‌گیرد.
</p>
<ul>
<li>
سرویس Embedding از سلسله‌مراتب سرویس AI جدا شد
(<code>IXAiEmbeddingService</code> /
<code>XAiEmbeddingService</code> جایگزین
<code>IXDefaultEmbeddingService</code>).
</li>
<li>
وابستگی چرخشی <code>XAiRAGService ↔ XDefaultAiService</code>
حذف شد؛ اکنون سرویس AI به RAG وابسته است و نه برعکس.
</li>
<li>
<code>ProjectId</code> و <code>ConversationId</code> در
<code>XAiResponseRequest</code> Nullable شدند.
</li>
<li>
اعتبارسنجی درخواست Chat With Documents سخت‌گیرانه‌تر شد
(TopK و MinScore اجباری).
</li>
</ul>
</section>
<section class="section">
<h2>۲. تغییرات معماری</h2>
<h3>قبل</h3>
<pre>
XAiEmbeddingServiceBase : XAIServiceBase (Embedding = نوعی سرویس چت)
XDefaultEmbeddingService(IXFileProvider, ...)
XAiRAGService(IXDefaultAiService, IXDefaultEmbeddingService, ...)
XAIServiceBase(IXFileProvider, ...) → Upload + Extract + Attach raw contents
KnowledgeController: Ingest / Retrieve / Ask / AskStream / Documents / ...</pre
>
<h3>بعد</h3>
<pre>
XAiEmbeddingServiceBase : IXAiEmbeddingServiceBase (مستقل، بدون ارث‌بری از XAIServiceBase)
XAiEmbeddingService(IXAiDataProvider, ...) (بدون IXFileProvider)
XAiRAGService(IXAiEmbeddingService, IXFileProvider, ...) (بدون IXDefaultAiService)
XAIServiceBase(IXAiRAGService, ...) → Ingest(Conversation scope) + RetrieveAsync + Context in System Prompt
KnowledgeController: Ingest / Retrieve / Documents / ... (Ask/AskStream حذف شد)</pre
>
<h3>جریان جدید AskAsync</h3>
<ol>
<li>
تعیین Project (پیش‌فرض اگر <code>null</code>/Empty) و
Conversation (پیش‌فرض اگر <code>null</code>/Empty).
</li>
<li>
اگر فایل ارسال شده باشد:
<code>ragProvider.IngestAsync</code> با
<code>XAiKnowledgeScopeDescriptor.Conversation(conversationId)</code>
و <code>replaceExisting: true</code>.
</li>
<li>
ساخت <code>XAiKnowledgeAskRequest</code> با
<code>IncludeUser = true</code>،
<code>IncludeGlobal = true</code>، ProjectId و
ConversationId و فراخوانی
<code>ragProvider.RetrieveAsync</code>.
</li>
<li>
بارگذاری تاریخچهٔ پیام‌ها و ساخت یک پیام System واحد:
<code>Introduction + ChatWithDocuments prompt + Context block
(+ Project prompt)</code>.
</li>
<li>
ذخیرهٔ پیام کاربر، ارسال به LLM و ذخیرهٔ پاسخ
Assistant.
</li>
</ol>
</section>
<section class="section">
<h2>۳. ساب‌ماژول <code>xAiApi</code></h2>
<table>
<tr>
<th>وضعیت</th>
<th>فایل</th>
<th>خطوط</th>
<th>شرح</th>
</tr>
<tr>
<td><span class="badge new">جدید</span></td>
<td><code>Interfaces/IXAiEmbeddingService.cs</code></td>
<td>+6</td>
<td>
اینترفیس Embedding پیش‌فرض (جایگزین
<code>IXDefaultEmbeddingService</code>)
</td>
</tr>
<tr>
<td><span class="badge new">جدید</span></td>
<td><code>Providers/XAiEmbeddingService.cs</code></td>
<td>+29</td>
<td>
پیاده‌سازی پیش‌فرض با مدل
<code>XAiApiConstants.XAiEmbeddingModelName</code>؛
بدون وابستگی به <code>IXFileProvider</code>
</td>
</tr>
<tr>
<td><span class="badge del">حذف</span></td>
<td><code>Interfaces/IXDefaultEmbeddingService.cs</code></td>
<td>−5</td>
<td>جایگزین با <code>IXAiEmbeddingService</code></td>
</tr>
<tr>
<td><span class="badge del">حذف</span></td>
<td><code>Providers/XDefaultEmbeddingService.cs</code></td>
<td>−32</td>
<td>جایگزین با <code>XAiEmbeddingService</code></td>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td><code>Providers/XAIServiceBase.cs</code></td>
<td>~308</td>
<td>
تزریق <code>IXAiRAGService</code> به‌جای
<code>IXFileProvider</code>؛ <code>AskAsync</code> با
<code>Guid?</code> برای Project/Conversation؛ Ingest
فایل‌ها در Scope گفتگو و <code>RetrieveAsync</code>؛
حذف منطق Upload/AddReference/Extract و پیوست
<code>fileContents</code> و MetaData شناسهٔ فایل‌ها؛
<code>PrepareMemory</code> با پارامتر
<code>context</code> و یک پیام System ترکیبی
(Introduction + RAG prompt + Context + Project)؛
انتقال <code>BuildContextBlock</code> از
<code>protected virtual</code> به <code>private</code>
</td>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td><code>Providers/XAiRAGService.cs</code></td>
<td>~382</td>
<td>
حذف وابستگی <code>IXDefaultAiService</code>؛ استفاده از
<code>IXAiEmbeddingService</code>؛ حذف
<code>AskWithRAGAsync</code> و
<code>AskWithRAGAsEnumerable</code>؛ پس از Upload، اگر
Scope دارای ScopeId باشد،
<code>fileProvider.AddReference</code> با
<code>providedFor = scope.Scope.GetStringValue()</code>
ثبت می‌شود؛ جابه‌جایی region «Private»
(<code>ExtractText</code>, <code>EmbedChunks</code>)؛
<code>NormalizeScope</code> دیگر static نیست
</td>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td><code>Providers/XAiEmbeddingServiceBase.cs</code></td>
<td>+14 / −10</td>
<td>
دیگر از <code>XAIServiceBase</code> ارث نمی‌برد؛
فیلدهای خودش (DataProvider، Configuration،
ValidationProvider، Extractor، ModelName) را نگه
می‌دارد؛ حذف <code>IXFileProvider</code>
</td>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td>
<code>Providers/XDefaultAiService.cs</code>،
<code>Providers/XDefaultThinkingAiService.cs</code>
</td>
<td>±5</td>
<td>
سازنده: <code>IXAiRAGService ragProvider</code> به‌جای
<code>IXFileProvider</code>
</td>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td><code>Controllers/KnowledgeController.cs</code></td>
<td>−132</td>
<td>
حذف Endpointهای <code>POST /Knowledge/Ask</code> و
<code>POST /Knowledge/AskStream</code>
</td>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td>
<code>Controllers/XAiEmbeddingServiceControllerBase.cs</code>
</td>
<td>±18</td>
<td>
ارث‌بری مستقیم از
<code>XBaseIdentityApiV1Controller</code>؛ پارامتر
Generic به <code>TEmbeddingService</code> تغییر نام
یافت؛ فیلد <code>embeddingService</code>
</td>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td><code>Controllers/DefaultEmbeddingController.cs</code></td>
<td>±14</td>
<td>
استفاده از <code>IXAiEmbeddingService</code> و
آرگومان‌های نام‌دار
</td>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td><code>Controllers/ChatWithDocumentsController.cs</code></td>
<td>±4</td>
<td>تزریق <code>IXAiEmbeddingService</code></td>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td><code>Controllers/XAiServiceControllerBase.cs</code></td>
<td>±4</td>
<td>
<code>AskStream</code>: ارسال
<code>request.ProjectId.Value</code> /
<code>request.ConversationId.Value</code> (به بخش
هشدارها مراجعه شود)
</td>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td>
<code>Interfaces/IXAiEmbeddingServiceBase.cs</code>،
<code>Interfaces/IXAiEmbeddingServiceControllerBase.cs</code>
</td>
<td>±9</td>
<td>
قطع ارث‌بری از <code>IXAiServiceBase</code> /
<code>IXAiServiceControllerBase</code>؛ حذف
<code>using OllamaSharp</code>
</td>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td><code>Interfaces/IXAiRAGService.cs</code></td>
<td>−27</td>
<td>
حذف امضای <code>AskWithRAGAsync</code> و
<code>AskWithRAGAsEnumerable</code>
</td>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td><code>Interfaces/IXAiServiceBase.cs</code></td>
<td>±4</td>
<td>
<code>AskAsync(Guid? projectId, Guid? conversationId, ...)</code>
</td>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td><code>DI/XDIHelperExtension.cs</code></td>
<td>+14 / −5</td>
<td>
متد جدید <code>AddXRagService()</code> (ثبت
<code>IXAiEmbeddingService</code> و
<code>IXAiRAGService</code>)؛ حذف ثبت‌های قدیمی از
<code>AddXAiServices()</code>
</td>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td><code>Startup.cs</code></td>
<td>+4</td>
<td>
فراخوانی <code>services.AddXRagService()</code> قبل از
<code>AddXAiServices()</code>
</td>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td><code>Constants/XAiApiConstants.cs</code></td>
<td>+1</td>
<td>
<code>XAiApiRagPromptName = "ChatWithDocuments"</code>
</td>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td><code>Models/XAiKnowledgeModels.cs</code></td>
<td>±9</td>
<td>
Factoryهای Scope (User/Global/Project/Conversation):
مقدار پیش‌فرض
<code>Type ?? XAiModelsConstants.XAiDefaultKnowledgeType</code>
</td>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td><code>Extensions/XModelsExtensions.cs</code></td>
<td>±4</td>
<td>
<code>IsValid</code> درخواست Chat With Documents:
<code>TopK</code> و <code>MinScore</code> اکنون
<b>اجباری</b> هستند (قبلاً اختیاری)
</td>
</tr>
</table>
</section>
<section class="section">
<h2>۴. ساب‌ماژول <code>Modules/xAiModels</code></h2>
<table>
<tr>
<th>وضعیت</th>
<th>فایل</th>
<th>خطوط</th>
<th>شرح</th>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td><code>Models/XAiResponseRequest.cs</code></td>
<td>±4</td>
<td>
<code>ProjectId</code> و <code>ConversationId</code> از
<code>Guid</code> به <code>Guid?</code> تغییر کردند
(ارسال‌نکردن = استفاده از Project/Conversation پیش‌فرض)
</td>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td><code>Extensions/XAiModelsExtensions.cs</code></td>
<td>±1</td>
<td>اصلاح تورفتگی در امضای <code>ToChatMessages</code></td>
</tr>
</table>
</section>
<section class="section">
<h2>۵. مخزن اصلی (Workspace)</h2>
<table>
<tr>
<th>وضعیت</th>
<th>مسیر</th>
<th>شرح</th>
</tr>
<tr>
<td><span class="badge sub">ساب‌ماژول</span></td>
<td><code>xAiApi</code>، <code>Modules/xAiModels</code></td>
<td>به‌روزرسانی Pointer پس از Commit ساب‌ماژول‌ها</td>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td><code>Documents/Boards/xDashboard.kanban</code></td>
<td>
کارت «R&amp;D about MCP Servers» به ستون Test منتقل شد؛
چک‌باکس «Test Rag Documents by Chat» تیک خورد؛ کارت جدید
«Adding MCP Support ...» اضافه شد
</td>
</tr>
<tr>
<td><span class="badge mod">تغییر</span></td>
<td><code>Documents/Resources/Json/Authenticate.json</code></td>
<td>
نمونه‌های تست: توکن/Session جدید و نمونه Body برای
<code>ChatWithDocuments/Ask</code> (topK=6,
minScore=3.5) و Ask بدون Project/Conversation
</td>
</tr>
<tr>
<td><span class="badge new">جدید</span></td>
<td>
<code>Documents/Codes/1.BKP.cs</code>،
<code>KnowledgeController.BKP.cs</code>،
<code>XAIServiceBase.BKP.cs</code>
</td>
<td>نسخهٔ پشتیبان کد پیش از Refactor</td>
</tr>
<tr>
<td><span class="badge new">جدید</span></td>
<td>
<code>Documents/Docs/ChangeLogs/1405-08-08-v01.html</code>،
<code>CommitMessage-1405-08-08-v01.txt</code>
</td>
<td>همین گزارش و پیام Commit</td>
</tr>
</table>
</section>
<section class="section">
<h2>۶. تغییرات ناسازگار (Breaking)</h2>
<ul>
<li>
<code>POST /Knowledge/Ask</code> و
<code>POST /Knowledge/AskStream</code> حذف شدند؛ Frontend
باید از <code>Ask</code>/<code>AskStream</code> کنترلر
سرویس AI استفاده کند (RAG به‌صورت خودکار اعمال می‌شود).
</li>
<li>
<code>IXDefaultEmbeddingService</code> /
<code>XDefaultEmbeddingService</code> حذف شدند؛ هر جای
دیگری که به آن‌ها ارجاع دارد باید به
<code>IXAiEmbeddingService</code> تغییر کند.
</li>
<li>
<code>IXAiEmbeddingServiceBase</code> دیگر متدهای
<code>IXAiServiceBase</code> (چت) را ندارد و
<code>DefaultEmbeddingController</code> دیگر Endpointهای
چت ارث‌بری‌شده را ارائه نمی‌کند.
</li>
<li>
درخواست <code>ChatWithDocuments/Ask</code> بدون
<code>topK</code> یا <code>minScore</code> اکنون
<code>InvalidArgs</code> برمی‌گرداند.
</li>
</ul>
</section>
<section class="section">
<h2>۷. هشدارها و موارد نیازمند بررسی (کشف‌شده در بازبینی)</h2>
<div class="warn">
<b>۱) <code>Ask</code> غیر Stream همیشه با InvalidArgs شکست
می‌خورد:</b> در <code>XAiServiceControllerBase.Ask</code>
(خط ~632) پارامتر <code>userInfo</code> به
<code>aiService.AskAsync</code> ارسال نمی‌شود، اما
<code>ragProvider.RetrieveAsync</code> در
<code>AskAsync</code> با <code>IsValidUser(userInfo)</code>
اعتبارسنجی می‌کند و برای <code>null</code>
<code>XException.InvalidArgs</code> پرتاب می‌کند. پیشنهاد:
افزودن <code>userInfo: userInfo</code> به فراخوانی.
</div>
<div class="warn">
<b>۲) <code>AskStream</code> با Project/Conversation خالی:</b>
پس از Nullable شدن، <code>request.ProjectId.Value</code> و
<code>request.ConversationId.Value</code> در صورت ارسال‌نشدن
<code>InvalidOperationException</code> می‌دهند. همچنین
<code>AskAsEnumerable</code> هنوز <code>Guid</code> می‌گیرد و
جریان RAG در آن اعمال نشده است.
</div>
<div class="warn">
<b>۳) بلعیدن خطای Ingest:</b> در <code>AskAsync</code> بلوک
<code>catch { }</code> خطای Ingest فایل‌ها را بدون لاگ نادیده
می‌گیرد و متغیر <code>ingestResult</code> استفاده نمی‌شود.
پیشنهاد: حداقل <code>logger.LogWarning</code>.
</div>
<div class="warn">
<b>۴) پرامپت <code>ChatWithDocuments</code>:</b>
<code>PrepareMemory</code> اکنون در نبود این پرامپت
<code>InvalidData</code> پرتاب می‌کند؛ این پرامپت فقط در
<code>appsettings.Development.json</code> یافت شد. باید در
تنظیمات Production نیز وجود داشته باشد.
</div>
<div class="warn">
<b>۵) جداکننده Project Prompt:</b> متن
<code>Project:</code> بدون خط جدید به انتهای Context بلوک
چسبانده می‌شود (<code>systemText += $"Project:..."</code>).
</div>
<div class="warn">
<b>۶) نمونه تست:</b> در <code>Authenticate.json</code> مقدار
<code>minScore: 3.5</code> با اعتبارسنجی جدید (بازهٔ −1 تا 1)
نامعتبر است. همچنین این فایل شامل AccessToken/RefreshToken
است؛ از Commit اطلاعات حساس مطمئن شوید.
</div>
</section>
<section class="section">
<h2>۸. اعتبارسنجی</h2>
<pre>
dotnet build xAiApi/xAiApi.csproj --nologo -v q
395 Warning(s) (MSB3277 / NU1900 — از قبل موجود)
0 Error(s)</pre
>
<div class="note">
تست Runtime / End-to-End (Ask با فایل پیوست، Retrieve چندسطحی،
AskStream) در این مرحله انجام نشده است.
</div>
</section>
<section class="section">
<h2>۹. ترتیب Commit</h2>
<ol>
<li><code>Modules/xAiModels</code> (وابستگی)</li>
<li><code>xAiApi</code></li>
<li>مخزن اصلی (Pointerها، Kanban، مستندات)</li>
</ol>
</section>
<section class="section">
<h2>۱۰. فایل‌های مستند</h2>
<p>
گزارش:
<code>Documents/Docs/ChangeLogs/1405-08-08-v01.html</code>
</p>
<p>
Commit message:
<code>Documents/Docs/ChangeLogs/CommitMessage-1405-08-08-v01.txt</code>
</p>
<p>
برای تغییرات بعدی همین تاریخ از پسوند <code>v02</code>
استفاده شود.
</p>
</section>
</main>
<footer>
تولیدشده در تاریخ ۱۴۰۵/۰۸/۰۸ (2026-10-30) | xSaherelmWorkspace |
ChangeLog v01
</footer>
</div>
</body>
</html>
@@ -0,0 +1,90 @@
===============================================================================
Commit Message - xSaherelmWorkspace
تاریخ: ۱۴۰۵/۰۸/۰۸ (2026-10-30)
نسخه مستند: v01
گزارش کامل: Documents/Docs/ChangeLogs/1405-08-08-v01.html
===============================================================================
هدف: ادغام RAG در جریان اصلی گفتگو (AskAsync)، جداسازی سرویس Embedding از
سرویس AI، حذف Ask/AskStream از KnowledgeController و Nullable شدن
Project/Conversation در XAiResponseRequest.
ترتیب Commit: [1] xAiModels -> [2] xAiApi -> [3] Root
[1] Modules/xAiModels
Make Project and Conversation Optional in XAiResponseRequest
- XAiResponseRequest: ProjectId / ConversationId changed from Guid to Guid?
(omitted => default project / default conversation);
- XAiModelsExtensions: fix indentation of ToChatMessages signature.
Files: M Models/XAiResponseRequest.cs; M Extensions/XAiModelsExtensions.cs
[2] xAiApi
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.
Files: A Interfaces/IXAiEmbeddingService.cs; A Providers/XAiEmbeddingService.cs;
D Interfaces/IXDefaultEmbeddingService.cs; D Providers/XDefaultEmbeddingService.cs;
M Constants/XAiApiConstants.cs; M Controllers/ChatWithDocumentsController.cs;
M Controllers/DefaultEmbeddingController.cs; M Controllers/KnowledgeController.cs;
M Controllers/XAiEmbeddingServiceControllerBase.cs;
M Controllers/XAiServiceControllerBase.cs; M DI/XDIHelperExtension.cs;
M Extensions/XModelsExtensions.cs; M Interfaces/IXAiEmbeddingServiceBase.cs;
M Interfaces/IXAiEmbeddingServiceControllerBase.cs; M Interfaces/IXAiRAGService.cs;
M Interfaces/IXAiServiceBase.cs; M Models/XAiKnowledgeModels.cs;
M Providers/XAIServiceBase.cs; M Providers/XAiEmbeddingServiceBase.cs;
M Providers/XAiRAGService.cs; M Providers/XDefaultAiService.cs;
M Providers/XDefaultThinkingAiService.cs; M Startup.cs
[3] Workspace (root)
- Update submodule pointers: xAiApi, Modules/xAiModels;
- Kanban: move "R&D about MCP Servers" to Test, check "Test Rag Documents
by Chat", add "Adding MCP Support ...";
- Authenticate.json: refresh sample tokens/session and add ask samples;
- Add Documents/Codes/*.BKP.cs (pre-refactor backups);
- Add Documents/Docs/ChangeLogs/1405-08-08-v01.html and this file.
Validation:
- dotnet build xAiApi/xAiApi.csproj --nologo -v q -> 0 Error(s),
395 pre-existing warnings (MSB3277/NU1900);
- Runtime / end-to-end tests not performed.
Known Issues (to fix before release):
- XAiServiceControllerBase.Ask does not pass userInfo to AskAsync ->
RetrieveAsync throws InvalidArgs;
- AskStream uses ProjectId.Value / ConversationId.Value -> throws when
omitted; AskAsEnumerable still takes Guid and has no RAG;
- AskAsync swallows ingest errors with empty catch (no logging);
- "ChatWithDocuments" prompt must exist in production appsettings;
- Project prompt appended without newline separator;
- Authenticate.json sample minScore 3.5 is outside [-1, 1] and the file
contains tokens.
Suggested root commit title:
Integrate RAG into Chat Pipeline, Decouple Embedding Service, Optional Project/Conversation (۱۴۰۵/۰۸/۰۸ v01)
For additional documentation use v02:
1405-08-08-v02.html
CommitMessage-1405-08-08-v02.txt
===============================================================================
File diff suppressed because it is too large Load Diff
@@ -1636,7 +1636,7 @@ namespace xAiModels.Extensions
/// <returns></returns>
public static ChatMessage ToChatMessages(
this XAiMessageDto source,
IList<AIContent> additionalContents = null
IList<AIContent> additionalContents = null
)
{
//
@@ -4409,12 +4409,12 @@ namespace xAiModels.Models
/// <summary>
/// Specified Project Id ...
/// </summary>
public Guid ProjectId { get; set; }
public Guid? ProjectId { get; set; }
/// <summary>
/// Specified Conversation Id ...
/// </summary>
public Guid ConversationId { get; set; }
public Guid? ConversationId { get; set; }
}
}
+21 -8
View File
@@ -4,18 +4,31 @@
}
{
"accessToken": "E8C7676F04D16F526B8F3C6F2844BB3101207F4B027DE550AAF5AB697B41E8A7",
"refreshToken": "5EA163B83E3299FDDD13EC3425F9E028EDF8002D92643F255BA120D6E7059B2F",
"expiresAt": 1792996696
"accessToken": "EE124E2A77328DC1F31421B95A5AE85D9C3A63F4923F9B11AEDABCE1F6FD1FC0",
"refreshToken": "EDD3C6C09C0DA61E18A04B6E77A20F45F161B63B6A544C52461A460BD400F443",
"expiresAt": 1793347477
}
{
"sessionId": "1accad72-0c3d-4801-b0d1-07d7c0b65f10",
"filesCount": 12,
"chunksCount": 274,
"totalVectorsCount": 274,
"sessionId": "7f871358-1f00-4444-a10f-d3aed06e5826",
"filesCount": 3,
"chunksCount": 128,
"totalVectorsCount": 128,
"skippedFiles": [],
"expiresAtUtc": "2026-10-26T06:10:41.9680924Z"
"expiresAtUtc": "2026-10-30T07:49:41.5926071Z"
}
{
"sessionId": "7f871358-1f00-4444-a10f-d3aed06e5826",
"prompt": "what is MCP ?",
"topK": 6,
"minScore": 3.5
}
{
"prompt": "who are you ?",
"projectId": "",
"conversationId": ""
}
IDS RPK:
+1 -1
Submodule xAiApi updated: 37d4e622e9...ad8ea9c1dd