Files
saherelm 888f20ea63 - 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.
2026-10-30 19:46:42 +03:30

671 lines
23 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!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>