Files
xSaherelmWorkspace/Documents/Docs/Developer/1405-08-09.Overview.html
T
2026-10-31 17:19:29 +03:30

1191 lines
60 KiB
HTML
Raw 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.0" />
<title>بازبینی پنجم و راستی‌آزمایی تغییرات | سامانه xAiApi</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&display=swap');
:root {
--primary: #1a365d;
--primary-light: #2c5282;
--accent: #c9a961;
--accent-dark: #a8893f;
--bg: #faf9f6;
--card-bg: #ffffff;
--text: #1a202c;
--text-muted: #4a5568;
--border: #e2e8f0;
--success: #38a169;
--danger: #e53e3e;
--warning: #dd6b20;
--info: #3182ce;
--shadow: 0 4px 6px rgba(0,0,0,0.05), 0 10px 30px rgba(26,54,93,0.08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Vazirmatn', Tahoma, sans-serif;
background: var(--bg);
color: var(--text);
line-height: 1.9;
font-size: 15px;
padding: 30px 15px;
}
.document-container {
max-width: 1050px;
margin: 0 auto;
background: var(--card-bg);
box-shadow: var(--shadow);
border-radius: 12px;
overflow: hidden;
}
.document-header {
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
color: white;
padding: 50px 40px 40px;
position: relative;
border-bottom: 4px solid var(--accent);
}
.document-header::before {
content: '';
position: absolute;
top: 0; right: 0;
width: 220px; height: 220px;
background: radial-gradient(circle, rgba(201,169,97,0.18) 0%, transparent 70%);
border-radius: 50%;
transform: translate(50%, -50%);
}
.header-top {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30px;
position: relative;
z-index: 1;
}
.company-badge { display: flex; align-items: center; gap: 12px; }
.company-logo {
width: 60px; height: 60px;
background: var(--accent);
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.doc-meta { text-align: left; font-size: 12px; opacity: 0.92; }
.doc-meta div { margin-bottom: 3px; }
.document-title { text-align: center; position: relative; z-index: 1; padding: 20px 0; }
.document-title .label {
display: inline-block;
background: rgba(201,169,97,0.2);
color: var(--accent);
padding: 4px 16px;
border-radius: 20px;
font-size: 12px;
font-weight: 600;
margin-bottom: 15px;
border: 1px solid rgba(201,169,97,0.4);
}
.document-title h1 { font-size: 28px; font-weight: 800; margin-bottom: 10px; letter-spacing: -0.5px; }
.document-title h2 { font-size: 16px; font-weight: 400; opacity: 0.9; }
.document-body { padding: 40px; }
.intro-text {
background: linear-gradient(to left, #f7fafc, #edf2f7);
border-right: 4px solid var(--accent);
padding: 20px 25px;
border-radius: 8px;
margin-bottom: 35px;
font-size: 14px;
color: var(--text-muted);
}
.section { margin-bottom: 40px; page-break-inside: avoid; }
.section-header {
display: flex;
align-items: center;
gap: 15px;
padding-bottom: 12px;
border-bottom: 2px solid var(--border);
margin-bottom: 20px;
}
.section-number {
width: 50px; height: 50px;
background: linear-gradient(135deg, var(--primary), var(--primary-light));
color: white;
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
font-weight: 800;
font-size: 20px;
flex-shrink: 0;
box-shadow: 0 4px 10px rgba(26,54,93,0.2);
}
.section-title { flex: 1; }
.section-title h3 { font-size: 19px; font-weight: 700; color: var(--primary); margin-bottom: 2px; }
.section-title .subtitle { font-size: 12px; color: var(--text-muted); }
.section-content { padding-right: 10px; }
.section-content p { margin-bottom: 12px; text-align: justify; text-indent: 20px; }
.section-content p.no-indent { text-indent: 0; }
.highlight-box,
.info-box,
.success-box,
.warning-box,
.danger-box {
padding: 18px 22px;
border-radius: 8px;
margin: 20px 0;
font-size: 14px;
}
.highlight-box {
background: linear-gradient(to left, #fffaf0, #fef5e7);
border: 1px solid #f6e05e;
border-right: 4px solid var(--accent);
}
.info-box {
background: linear-gradient(to left, #ebf8ff, #e6f6ff);
border: 1px solid #90cdf4;
border-right: 4px solid var(--primary-light);
}
.success-box {
background: linear-gradient(to left, #f0fff4, #e6fffa);
border: 1px solid #9ae6b4;
border-right: 4px solid var(--success);
}
.warning-box {
background: linear-gradient(to left, #fffaf0, #fef5e7);
border: 1px solid #fbd38d;
border-right: 4px solid var(--warning);
}
.danger-box {
background: linear-gradient(to left, #fff5f5, #fed7d7);
border: 1px solid #feb2b2;
border-right: 4px solid var(--danger);
}
.styled-table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
background: white;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.styled-table thead {
background: linear-gradient(135deg, var(--primary), var(--primary-light));
color: white;
}
.styled-table th { padding: 14px 16px; text-align: right; font-weight: 600; font-size: 13px; }
.styled-table td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: top; }
.styled-table tbody tr:last-child td { border-bottom: none; }
.styled-table tbody tr:nth-child(even) { background: #f8fafc; }
.styled-table .highlight-row { background: #fffaf0 !important; font-weight: 600; }
.stats-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 15px;
margin: 25px 0;
}
.stat-card {
background: linear-gradient(135deg, var(--primary), var(--primary-light));
color: white;
padding: 20px;
border-radius: 10px;
text-align: center;
box-shadow: 0 4px 12px rgba(26,54,93,0.2);
}
.stat-card.success { background: linear-gradient(135deg, #276749, var(--success)); }
.stat-card.danger { background: linear-gradient(135deg, #9b2c2c, var(--danger)); }
.stat-card.warning { background: linear-gradient(135deg, #9c4221, var(--warning)); }
.stat-card .stat-value {
font-size: 26px;
font-weight: 800;
margin-bottom: 5px;
color: var(--accent);
line-height: 1.3;
}
.stat-card.success .stat-value,
.stat-card.danger .stat-value,
.stat-card.warning .stat-value { color: white; }
.stat-card .stat-label { font-size: 12px; opacity: 0.95; }
.conclusion-box {
background: linear-gradient(135deg, var(--primary), var(--primary-light));
color: white;
padding: 30px;
border-radius: 12px;
margin: 30px 0;
text-align: center;
box-shadow: 0 8px 20px rgba(26,54,93,0.3);
}
.conclusion-box h3 { font-size: 22px; font-weight: 800; margin-bottom: 15px; color: var(--accent); }
.conclusion-box p { font-size: 14px; line-height: 1.8; text-indent: 0 !important; margin-bottom: 15px; }
.conclusion-box .highlight {
background: rgba(201,169,97,0.2);
padding: 15px 20px;
border-radius: 8px;
margin-top: 20px;
border: 1px solid rgba(201,169,97,0.4);
}
.document-footer {
background: var(--primary);
color: white;
padding: 25px 40px;
text-align: center;
font-size: 12px;
margin-top: 40px;
}
.document-footer .footer-brand {
font-weight: 700;
color: var(--accent);
margin-bottom: 5px;
font-size: 14px;
}
.footer-divider { width: 60px; height: 2px; background: var(--accent); margin: 10px auto; }
.page-info {
text-align: center;
padding: 15px;
font-size: 11px;
color: var(--text-muted);
border-top: 1px solid var(--border);
margin-top: 30px;
}
.badge {
display: inline-block;
padding: 2px 10px;
border-radius: 12px;
font-size: 11px;
font-weight: 600;
white-space: nowrap;
}
.badge-fixed { background: #c6f6d5; color: #22543d; }
.badge-partial { background: #feebc8; color: #7b341e; }
.badge-open { background: #fed7d7; color: #742a2a; }
.badge-new { background: #bee3f8; color: #2a4365; }
.badge-doc { background: #e9d8fd; color: #44337a; }
code {
background: #edf2f7;
padding: 2px 6px;
border-radius: 4px;
font-family: 'Consolas', 'Monaco', monospace;
font-size: 12px;
direction: ltr;
display: inline-block;
}
pre.code-block {
background: #1a202c;
color: #e2e8f0;
padding: 16px 18px;
border-radius: 8px;
direction: ltr;
text-align: left;
overflow-x: auto;
font-family: 'Consolas', 'Monaco', monospace;
font-size: 12px;
line-height: 1.6;
margin: 15px 0;
border-left: 4px solid var(--accent);
}
pre.code-block code {
background: transparent;
color: inherit;
padding: 0;
display: inline;
}
ul { padding-right: 20px; margin-top: 10px; }
li { margin-bottom: 8px; }
@media print {
body { background: white; padding: 0; }
.document-container { box-shadow: none; border-radius: 0; }
.section { page-break-inside: avoid; }
}
@media (max-width: 768px) {
.document-body { padding: 25px 20px; }
.document-header { padding: 30px 20px; }
.stats-grid { grid-template-columns: 1fr 1fr; }
.header-top { flex-direction: column; gap: 15px; }
.doc-meta { text-align: center; }
}
</style>
</head>
<body>
<div class="document-container">
<header class="document-header">
<div class="header-top">
<div class="company-badge">
<div class="company-logo"></div>
</div>
<div class="doc-meta">
<div>شماره مستند: ARCH-REV-1405-005</div>
<div>نسخه: ۵.۰</div>
<div>تاریخ تهیه: آبان ۱۴۰۵</div>
<div>طبقه‌بندی: محرمانه</div>
</div>
</div>
<div class="document-title">
<span class="label">CHANGES VERIFICATION &amp; REVIEW</span>
<h1>بازبینی پنجم و راستی‌آزمایی تغییرات سامانه xAiApi</h1>
<h2>بررسی کدهای به‌روزشده پس از بازطراحی لایه RAG، تفکیک Embedding و شناسایی موارد باقی‌مانده</h2>
</div>
</header>
<div class="document-body">
<div class="intro-text">
<strong>خلاصه مدیریتی:</strong><br />
این گزارش بر اساس مقایسه مستند بازبینی چهارم
(<code>ARCH-REV-1405-004</code>) با کدهای ارائه‌شده در
فایل‌های <code>xAiApi</code>، <code>xAiModels</code> و
<code>xAiService</code> تهیه شده است. مهم‌ترین نتیجه:
<strong>مورد N-01 برطرف شده است</strong> و مسیر
<code>AskAsEnumerable</code> اکنون RAG دارد. با این حال،
چند مورد بحرانی از قبل باقی مانده‌اند و دو یافته جدید مهم
نیز شناسایی شد: پیش‌فرض ناسازگار و پرخطر
<code>KnowledgeController.Ingest</code> روی
<code>Global</code>، و ذخیره پاسخ Streaming با نقش
<code>System</code> به‌جای <code>Assistant</code>.
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۱</div>
<div class="section-title">
<h3>خلاصه اجرایی و آمار وضعیت</h3>
<div class="subtitle">Executive Summary &amp; Status</div>
</div>
</div>
<div class="section-content">
<p>
تغییرات ساختاری نسخه فعلی در مجموع مثبت ارزیابی
می‌شود. تفکیک Embedding از Chat، انتقال RAG به
<code>XAIServiceBase</code>، حذف مسیرهای موازی
<code>AskWithRAG*</code> و ساده‌سازی
<code>KnowledgeController</code> همگی تأیید شدند.
اما وضعیت آمادگی Production همچنان ضعیف است، زیرا
مسیر <code>AskStream</code> با
<code>ProjectId/ConversationId</code> تهی کرش
می‌کند، اعتبارسنجی <code>XAiDocumentAskRequest</code>
بیش از حد سختگیرانه شده، خطاهای Ingest بی‌صدا
بلعیده می‌شوند و پیش‌فرض Ingest در
<code>KnowledgeController</code> روی
<code>Global</code> تنظیم شده است.
</p>
<div class="stats-grid">
<div class="stat-card success">
<div class="stat-value">۹</div>
<div class="stat-label">تغییر مثبت تأییدشده</div>
</div>
<div class="stat-card danger">
<div class="stat-value">۱۲</div>
<div class="stat-label">مورد باز / ناقص</div>
</div>
<div class="stat-card warning">
<div class="stat-value">۴</div>
<div class="stat-label">یافته جدید</div>
</div>
<div class="stat-card">
<div class="stat-value">۲</div>
<div class="stat-label">ریسک مهاجرت / مستندسازی</div>
</div>
</div>
<div class="success-box">
<strong>مهم‌ترین دستاورد:</strong> مورد
<code>N-01</code> اصلاح شده است. در
<code>XAIServiceBase.AskAsEnumerable</code> اکنون
پس از Ingest، درخواست
<code>XAiKnowledgeAskRequest</code> ساخته می‌شود،
<code>ragProvider.RetrieveAsync</code> فراخوانی
می‌شود و <code>context</code> به
<code>PrepareMemory</code> داده می‌شود. بنابراین
مسیر Streaming نیز از دانش ذخیره‌شده استفاده
می‌کند.
</div>
<div class="danger-box">
<strong>مهم‌ترین ریسک باقی‌مانده:</strong>
<code>XAiServiceControllerBase.AskStream</code>
همچنان از <code>request.ProjectId.Value</code> و
<code>request.ConversationId.Value</code> استفاده
می‌کند، در حالی که این فیلدها در
<code>XAiResponseRequest</code> از نوع
<code>Guid?</code> هستند. اگر کلاینت این مقادیر را
ارسال نکند، <code>NullReferenceException</code>
رخ می‌دهد. این مورد باید قبل از Production اصلاح
شود.
</div>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۲</div>
<div class="section-title">
<h3>راستی‌آزمایی تغییرات مثبت</h3>
<div class="subtitle">Verified Positive Changes</div>
</div>
</div>
<div class="section-content">
<table class="styled-table">
<thead>
<tr>
<th>#</th>
<th>محل / موضوع</th>
<th>نتیجه راستی‌آزمایی</th>
<th>وضعیت</th>
</tr>
</thead>
<tbody>
<tr>
<td>۱</td>
<td><strong>Startup.cs / DI</strong></td>
<td>
<code>services.AddXRagService()</code>
پیش از <code>AddXAiServices()</code>
فراخوانی می‌شود. ثبت Embedding و RAG
مستقل شده است.
</td>
<td><span class="badge badge-fixed">تأیید شد</span></td>
</tr>
<tr>
<td>۲</td>
<td><strong>XAiEmbeddingServiceBase</strong></td>
<td>
دیگر از <code>XAIServiceBase</code>
ارث نمی‌برد و تنها
<code>IXAiEmbeddingServiceBase</code>
را پیاده‌سازی می‌کند. تفکیک Embedding
از Chat انجام شده است.
</td>
<td><span class="badge badge-fixed">تأیید شد</span></td>
</tr>
<tr>
<td>۳</td>
<td><strong>XAIServiceBase.AskAsync</strong></td>
<td>
جریان کامل Ingest → Retrieve →
PrepareMemory → Generate پیاده‌سازی شده
است. RAG در مسیر غیر Streaming فعال
است.
</td>
<td><span class="badge badge-fixed">تأیید شد</span></td>
</tr>
<tr class="highlight-row">
<td>۴</td>
<td><strong>XAIServiceBase.AskAsEnumerable</strong></td>
<td>
برخلاف بازبینی چهارم، این مسیر اکنون
<code>ragProvider.RetrieveAsync</code>
را فراخوانی می‌کند و Context را به
<code>PrepareMemory</code> می‌دهد.
مورد <code>N-01</code> برطرف شده است.
</td>
<td><span class="badge badge-fixed">اصلاح شد</span></td>
</tr>
<tr>
<td>۵</td>
<td><strong>XAiRAGService</strong></td>
<td>
متدهای <code>AskWithRAGAsync</code> و
<code>AskWithRAGAsEnumerable</code>
حذف شده‌اند. تمرکز سرویس روی
Ingest/Retrieve/Documents است.
</td>
<td><span class="badge badge-fixed">تأیید شد</span></td>
</tr>
<tr>
<td>۶</td>
<td><strong>KnowledgeController</strong></td>
<td>
Endpointهای <code>Ask</code> و
<code>AskStream</code> حذف شده‌اند.
فقط Ingest، Documents و
DeleteDocument باقی مانده‌اند.
</td>
<td><span class="badge badge-fixed">تأیید شد</span></td>
</tr>
<tr>
<td>۷</td>
<td><strong>XAiResponseRequest</strong></td>
<td>
<code>ProjectId</code> و
<code>ConversationId</code> از
<code>Guid</code> به <code>Guid?</code>
تغییر کرده‌اند. امکان استفاده از
Default Project/Conversation فراهم شده
است.
</td>
<td><span class="badge badge-fixed">تأیید شد</span></td>
</tr>
<tr>
<td>۸</td>
<td><strong>XAiKnowledgeScopeDescriptor</strong></td>
<td>
Factory Methodها مقدار پیش‌فرض
<code>Type = XAiModelsConstants.XAiDefaultKnowledgeType</code>
را اعمال می‌کنند.
</td>
<td><span class="badge badge-fixed">تأیید شد</span></td>
</tr>
<tr>
<td>۹</td>
<td><strong>ChatWithDocumentsController</strong></td>
<td>
از <code>IXAiEmbeddingService</code>
به‌جای <code>IXDefaultEmbeddingService</code>
استفاده می‌کند و با DI جدید هماهنگ
است.
</td>
<td><span class="badge badge-fixed">تأیید شد</span></td>
</tr>
<tr>
<td>۱۰</td>
<td><strong>XAiEmbeddingServiceControllerBase</strong></td>
<td>
از <code>XAiServiceControllerBase</code>
ارث نمی‌برد و مستقیماً از
<code>XBaseIdentityApiV1Controller</code>
مشتق شده است. اما
<code>[AllowAnonymous]</code> هنوز روی
دو Endpoint اصلی باقی است.
</td>
<td><span class="badge badge-partial">جزئی</span></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۳</div>
<div class="section-title">
<h3>وضعیت موارد بازبینی چهارم</h3>
<div class="subtitle">Status of Previous Review Items</div>
</div>
</div>
<div class="section-content">
<table class="styled-table">
<thead>
<tr>
<th>شناسه</th>
<th>محل</th>
<th>وضعیت فعلی</th>
<th>توضیح</th>
</tr>
</thead>
<tbody>
<tr class="highlight-row">
<td>N-01</td>
<td><code>XAIServiceBase.AskAsEnumerable</code></td>
<td><span class="badge badge-fixed">اصلاح شد</span></td>
<td>
اکنون <code>RetrieveAsync</code> فراخوانی
می‌شود و Context در
<code>PrepareMemory</code> استفاده
می‌گردد. مسیر Streaming RAG دارد.
</td>
</tr>
<tr class="highlight-row">
<td>N-02</td>
<td><code>XAiServiceControllerBase.AskStream</code></td>
<td><span class="badge badge-open">باز</span></td>
<td>
همچنان از
<code>request.ProjectId.Value</code> و
<code>request.ConversationId.Value</code>
استفاده می‌شود. در صورت null بودن،
<code>NullReferenceException</code> رخ
می‌دهد.
</td>
</tr>
<tr class="highlight-row">
<td>N-03</td>
<td><code>XModelsExtensions.IsValid(XAiDocumentAskRequest)</code></td>
<td><span class="badge badge-open">باز</span></td>
<td>
<code>TopK</code> و <code>MinScore</code>
همچنان الزامی هستند. این یک Regression و
شکستن قرارداد با کلاینت‌های فعلی است.
</td>
</tr>
<tr class="highlight-row">
<td>N-04</td>
<td><code>XAIServiceBase.AskAsync / AskAsEnumerable</code></td>
<td><span class="badge badge-open">باز</span></td>
<td>
<code>catch { }</code> در بلوک Ingest
باقی مانده است. خطاهای Ingest بی‌صدا
بلعیده می‌شوند و متغیر
<code>ingestResult</code> استفاده
نمی‌شود.
</td>
</tr>
<tr>
<td>N-05</td>
<td><code>XAiRAGService.IngestAsync</code></td>
<td><span class="badge badge-open">باز</span></td>
<td>
<code>uploadedFile.Id</code> بدون بررسی
null استفاده می‌شود. در صورت null بودن
خروجی <code>fileProvider.Upload</code>،
NullReferenceException رخ می‌دهد.
</td>
</tr>
<tr>
<td>R-01</td>
<td><code>XAiApiConfiguration.IsValid</code></td>
<td><span class="badge badge-partial">جزئی</span></td>
<td>
برخلاف ادعای مستند قبلی، اعتبارسنجی
<code>Introduction</code> در کد فعلی
وجود دارد. اما وجود Prompt مربوط به
<code>ChatWithDocuments</code> در Startup
اعتبارسنجی نمی‌شود و اولین درخواست RAG
می‌تواند شکست بخورد.
</td>
</tr>
<tr>
<td>R-02</td>
<td><code>KnowledgeController</code></td>
<td><span class="badge badge-doc">نیازمند مستندسازی</span></td>
<td>
حذف <code>Ask</code> و
<code>AskStream</code> از
KnowledgeController تأیید می‌شود، اما
مهاجرت کلاینت‌ها به
<code>DefaultAi/Ask</code> باید مستند
شود.
</td>
</tr>
<tr>
<td>X-01</td>
<td><code>XAiDocumentRAGDescriptor.PromptName</code></td>
<td><span class="badge badge-partial">جزئی</span></td>
<td>
این فیلد کاملاً Dead نیست و در
<code>GetHistory(string, context)</code>
استفاده می‌شود؛ اما با
<code>XAiApiConstants.XAiApiRagPromptName</code>
در <code>PrepareMemory</code> هم‌راستا
نیست. بهتر است یک منبع واحد داشته باشند.
</td>
</tr>
<tr>
<td>X-02</td>
<td><code>XAIServiceBase.AskAsync / AskAsEnumerable</code></td>
<td><span class="badge badge-open">باز</span></td>
<td>
فایل‌های پیوست در هر بار ارسال مجدد با
<code>replaceExisting: true</code>
دوباره Ingest می‌شوند. نیاز به هش محتوا
یا شناسه فایل برای جلوگیری از Embedding
تکراری وجود دارد.
</td>
</tr>
<tr>
<td>F-10</td>
<td><code>XImageFileContentExtractor</code></td>
<td><span class="badge badge-open">باز</span></td>
<td>
اعتبارسنجی OCR حتی در حالت غیرفعال
(<code>EnableOcrFallback = false</code>)
انجام می‌شود.
</td>
</tr>
<tr>
<td>F-11</td>
<td><code>XAiEmbeddingServiceBase.GetEmbeddingGenerator</code></td>
<td><span class="badge badge-open">باز</span></td>
<td>
در حالت Ollama،
<code>OllamaApiClient</code> با URI
ساخته می‌شود و نام مدل
(<code>descriptor.LLM</code>) به آن
ارسال نمی‌شود.
</td>
</tr>
<tr>
<td>F-16</td>
<td><code>XAiEmbeddingServiceControllerBase</code></td>
<td><span class="badge badge-partial">جزئی</span></td>
<td>
<code>[AllowAnonymous]</code> هنوز روی
<code>Embedding</code> و
<code>Embeddings</code> باقی مانده
است.
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۴</div>
<div class="section-title">
<h3>یافته‌های جدید</h3>
<div class="subtitle">New Findings</div>
</div>
</div>
<div class="section-content">
<table class="styled-table">
<thead>
<tr>
<th>شناسه</th>
<th>محل</th>
<th>شدت</th>
<th>شرح</th>
</tr>
</thead>
<tbody>
<tr class="highlight-row">
<td>N-06</td>
<td><code>KnowledgeController.Ingest</code></td>
<td style="color: var(--danger); font-weight: 700;">بالا</td>
<td>
مقدار پیش‌فرض <code>scope</code> روی
<code>XAiKnowledgeScope.Global</code>
تنظیم شده است، در حالی که کامنت
Endpoint و الگوی سایر Endpointها
<code>User</code> را پیش‌فرض نشان
می‌دهد. برای کاربر غیر Admin، درخواست
بدون scope با خطای عدم دسترسی شکست
می‌خورد و برای Admin ممکن است به‌طور
ناخواسته دانش Global ایجاد کند.
</td>
</tr>
<tr class="highlight-row">
<td>N-07</td>
<td><code>XAIServiceBase.AskAsEnumerable</code></td>
<td style="color: var(--danger); font-weight: 700;">بالا</td>
<td>
پاسخ نهایی Streaming با نقش
<code>XAiChatRole.System</code> ذخیره
می‌شود، در حالی که در
<code>AskAsync</code> پاسخ Assistant با
نقش <code>XAiChatRole.Assistant</code>
ذخیره می‌گردد. این ناسازگاری باعث
تاریخچه نادرست پیام‌ها و رفتار متفاوت
در ادامه گفتگو می‌شود.
</td>
</tr>
<tr>
<td>N-08</td>
<td><code>XAIServiceBase.AskAsync / AskAsEnumerable</code></td>
<td style="color: var(--warning); font-weight: 700;">متوسط</td>
<td>
منطق RAG (Normalize → Project/Conversation
→ Ingest → Retrieve → PrepareMemory)
تقریباً به‌صورت تکراری در دو متد
پیاده‌سازی شده است. این تکرار باعث
واگرایی رفتار دو مسیر در آینده می‌شود.
</td>
</tr>
<tr>
<td>N-09</td>
<td><code>XAIServiceBase.PrepareMemory</code></td>
<td style="color: var(--text-muted); font-weight: 700;">پایین</td>
<td>
متد <code>private async Task&lt;IList&lt;ChatMessage&gt;&gt; PrepareMemory(...)</code>
هیچ <code>await</code> واقعی ندارد.
بهتر است synchronous باشد یا در صورت
نیاز به عملیات async، واقعاً await
داشته باشد.
</td>
</tr>
</tbody>
</table>
<div class="warning-box">
<strong>نکته درباره N-06:</strong>
اگر تصمیم بر این است که Ingest پیش‌فرض روی
<code>Global</code> باشد، باید این تصمیم صریحاً
مستند شود و سیاست دسترسی Admin برای Write روی
Global به‌وضوح اعلام گردد. در غیر این صورت،
پیش‌فرض باید <code>User</code> باشد تا با
<code>Documents</code> و <code>DeleteDocument</code>
هماهنگ بماند.
</div>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۵</div>
<div class="section-title">
<h3>تحلیل تفصیلی مهم‌ترین موارد</h3>
<div class="subtitle">Detailed Analysis</div>
</div>
</div>
<div class="section-content">
<p class="no-indent"><strong>۵-۱. N-01 اصلاح شده است</strong></p>
<p>
در <code>XAIServiceBase.AskAsEnumerable</code>، پس
از بررسی Project و Conversation، در صورت وجود فایل،
<code>ragProvider.IngestAsync</code> فراخوانی
می‌شود. سپس یک
<code>XAiKnowledgeAskRequest</code> ساخته می‌شود و
<code>ragProvider.RetrieveAsync</code> نتیجه را
برمی‌گرداند. در نهایت
<code>PrepareMemory(project, messages, context)</code>
Context را در System Message قرار می‌دهد. بنابراین
مسیر Streaming نیز به RAG متصل شده است.
</p>
<p class="no-indent"><strong>۵-۲. N-02 همچنان بحرانی است</strong></p>
<p>
در <code>XAiServiceControllerBase.AskStream</code>
کد زیر باقی مانده است:
</p>
<pre class="code-block"><code>var enumerable = aiService.AskAsEnumerable(
files: null,
userInfo: userInfo,
prompt: request.Prompt,
connectionId: connectionId,
projectId: request.ProjectId.Value,
cancellationToken: cancellationToken,
conversationId: request.ConversationId.Value
);</code></pre>
<p>
از آنجا که <code>ProjectId</code> و
<code>ConversationId</code> در
<code>XAiResponseRequest</code> از نوع
<code>Guid?</code> هستند، در صورت ارسال نشدن این
مقادیر، <code>.Value</code> باعث
<code>NullReferenceException</code> می‌شود. باید
مقدار nullable مستقیماً به
<code>AskAsEnumerable</code> پاس داده شود؛ زیرا
خود سرویس در صورت null بودن، Default
Project/Conversation را Resolve می‌کند.
</p>
<p class="no-indent"><strong>۵-۳. N-06: پیش‌فرض Global در Ingest</strong></p>
<p>
در <code>KnowledgeController.Ingest</code> امضای
متد به‌صورت زیر است:
</p>
<pre class="code-block"><code>[FromForm] XAiKnowledgeScope scope = XAiKnowledgeScope.Global,</code></pre>
<p>
در حالی که کامنت همان متد «User (default)» را ذکر
می‌کند و <code>Documents</code> و
<code>DeleteDocument</code> پیش‌فرض
<code>User</code> دارند. این ناسازگاری باید اصلاح
شود؛ در غیر این صورت تجربه کاربران غیر Admin و
سیاست جداسازی دانش (Isolation) مختل می‌شود.
</p>
<p class="no-indent"><strong>۵-۴. N-07: نقش نادرست پاسخ Streaming</strong></p>
<p>
در <code>AskAsEnumerable</code> هم پیام‌های Chunk و
هم پیام نهایی ذخیره‌شده با نقش
<code>XAiChatRole.System</code> ساخته می‌شوند:
</p>
<pre class="code-block"><code>Role = XAiChatRole.System,</code></pre>
<p>
این در حالی است که در <code>AskAsync</code> پاسخ
نهایی با <code>XAiChatRole.Assistant</code> ذخیره
می‌شود. پاسخ مدل باید در هر دو مسیر با نقش
<code>Assistant</code> ذخیره و ارسال شود تا
تاریخچه گفتگو و رفتار Memory در ادامه صحیح بماند.
</p>
<p class="no-indent"><strong>۵-۵. N-04: خطاهای Ingest بی‌صدا</strong></p>
<p>
در هر دو متد <code>AskAsync</code> و
<code>AskAsEnumerable</code> بلوک Ingest به‌صورت
زیر است:
</p>
<pre class="code-block"><code>try
{
ingestResult = await ragProvider.IngestAsync(...);
}
catch { }</code></pre>
<p>
اگر Ingest شکست بخورد (مثلاً فایل رمزدار یا فرمت
پشتیبانی‌نشده باشد)، LLM بدون Context پاسخ
می‌دهد و کاربر متوجه نمی‌شود که فایل‌هایش ایندکس
نشده‌اند. حداقل باید خطا لاگ شود و در پاسخ به
کاربر گزارش گردد.
</p>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۶</div>
<div class="section-title">
<h3>پیشنهادهای اصلاحی اولویت‌دار</h3>
<div class="subtitle">Prioritized Recommendations</div>
</div>
</div>
<div class="section-content">
<table class="styled-table">
<thead>
<tr>
<th>اولویت</th>
<th>اقدام</th>
<th>شناسه</th>
</tr>
</thead>
<tbody>
<tr class="highlight-row">
<td style="color: var(--danger); font-weight: 700;">P0</td>
<td>
حذف <code>.Value</code> در
<code>AskStream</code> یا هماهنگ‌سازی
امضای <code>AskAsEnumerable</code> با
<code>Guid?</code> و پاس دادن مستقیم
مقادیر nullable.
</td>
<td>N-02</td>
</tr>
<tr class="highlight-row">
<td style="color: var(--danger); font-weight: 700;">P0</td>
<td>
بازگرداندن اختیاری بودن
<code>TopK</code> و
<code>MinScore</code> در
<code>XAiDocumentAskRequest.IsValid</code>
برای حفظ قرارداد کلاینت‌های فعلی.
</td>
<td>N-03</td>
</tr>
<tr class="highlight-row">
<td style="color: var(--danger); font-weight: 700;">P0</td>
<td>
حذف <code>catch { }</code> در Ingest،
لاگ کردن خطا و گزارش
<code>SkippedFiles</code> یا شکست
Ingest به کاربر.
</td>
<td>N-04</td>
</tr>
<tr class="highlight-row">
<td style="color: var(--danger); font-weight: 700;">P0</td>
<td>
اصلاح پیش‌فرض <code>scope</code> در
<code>KnowledgeController.Ingest</code>
به <code>User</code> یا مستندسازی
صریح تصمیم Global و سیاست Admin.
</td>
<td>N-06</td>
</tr>
<tr class="highlight-row">
<td style="color: var(--danger); font-weight: 700;">P0</td>
<td>
استفاده از نقش
<code>XAiChatRole.Assistant</code> برای
پیام‌های پاسخ در
<code>AskAsEnumerable</code> و پیام
نهایی ذخیره‌شده.
</td>
<td>N-07</td>
</tr>
<tr>
<td style="color: var(--warning); font-weight: 700;">P1</td>
<td>
بررسی null برای
<code>uploadedFile</code> پیش از
استفاده از <code>uploadedFile.Id</code>
در <code>XAiRAGService</code>.
</td>
<td>N-05</td>
</tr>
<tr>
<td style="color: var(--warning); font-weight: 700;">P1</td>
<td>
افزودن اعتبارسنجی Startup برای وجود
Prompt مربوط به
<code>ChatWithDocuments</code> در
<code>XAiApiConfiguration.IsValid</code>.
</td>
<td>R-01</td>
</tr>
<tr>
<td style="color: var(--warning); font-weight: 700;">P1</td>
<td>
جلوگیری از Re-Ingest تکراری با هش
محتوا یا شناسه فایل در
<code>AskAsync</code> و
<code>AskAsEnumerable</code>.
</td>
<td>X-02</td>
</tr>
<tr>
<td style="color: var(--primary-light); font-weight: 700;">P2</td>
<td>
یکسان‌سازی منبع Prompt RAG بین
<code>XAiApiConstants.XAiApiRagPromptName</code>
و <code>XAiDocumentRAGDescriptor.PromptName</code>.
</td>
<td>X-01</td>
</tr>
<tr>
<td style="color: var(--primary-light); font-weight: 700;">P2</td>
<td>
اصلاح F-10 (اعتبارسنجی OCR در حالت
غیرفعال)، F-11 (ارسال نام مدل به
OllamaApiClient) و F-16
(<code>[AllowAnonymous]</code> روی
Embedding/Embeddings).
</td>
<td>F-*</td>
</tr>
<tr>
<td style="color: var(--primary-light); font-weight: 700;">P2</td>
<td>
مستندسازی مهاجرت حذف
<code>Ask/AskStream</code> از
<code>KnowledgeController</code> و
تغییرات <code>XAiResponseRequest</code>
برای کلاینت‌های موجود.
</td>
<td>R-02</td>
</tr>
<tr>
<td style="color: var(--primary-light); font-weight: 700;">P2</td>
<td>
ایجاد یک لایه مشترک مانند
<code>IXAiChatOrchestrator</code> برای
حذف تکرار منطق RAG بین
<code>AskAsync</code> و
<code>AskAsEnumerable</code>.
</td>
<td>N-08</td>
</tr>
</tbody>
</table>
<div class="info-box">
<strong>پیشنهاد بلندمدت:</strong>
جریان «Ingest → Retrieve → PrepareMemory →
Generate» باید در یک Orchestrator مشترک پیاده‌سازی
شود تا مسیرهای Ask و AskStream رفتار یکسان داشته
باشند و از واگرایی مجدد جلوگیری شود.
</div>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۷</div>
<div class="section-title">
<h3>جمع‌بندی نهایی</h3>
<div class="subtitle">Final Conclusion</div>
</div>
</div>
<div class="section-content">
<p>
بازطراحی انجام‌شده مسیر صحیحی را طی کرده است:
تفکیک Embedding از Chat، انتقال RAG به
<code>XAIServiceBase</code>، حذف مسیرهای موازی و
ساده‌سازی Controllerها. مهم‌ترین دستاورد این نسخه
اصلاح <code>N-01</code> و اتصال RAG به مسیر
Streaming است.
</p>
<p>
با این حال، سامانه در وضعیت فعلی برای Production
آماده نیست. موارد <code>N-02</code> (کرش
AskStream)، <code>N-03</code> (شکستن قرارداد
اعتبارسنجی)، <code>N-04</code> (بلعیدن خطاهای
Ingest)، <code>N-06</code> (پیش‌فرض Global در
Ingest) و <code>N-07</code> (نقش نادرست پاسخ
Streaming) باید قبل از استقرار برطرف شوند.
</p>
<div class="conclusion-box">
<h3>🎯 جمع‌بندی اجرایی بازبینی پنجم</h3>
<p>
معماری بهبود یافته و N-01 اصلاح شده است، اما
چند خطای بحرانی باقی‌مانده و دو یافته جدید
مهم، آمادگی Production را کاهش می‌دهد.
</p>
<div class="highlight">
<strong>اقدامات ضروری قبل از Production:</strong><br />
رفع NullReferenceException در AskStream + بازگرداندن
اختیاری بودن TopK/MinScore + لاگ‌کردن خطاهای Ingest
+ اصلاح پیش‌فرض Global در Ingest + اصلاح نقش پاسخ
Streaming + بررسی null برای uploadedFile
</div>
</div>
<div class="danger-box">
<strong>ارزیابی کلی:</strong> تغییرات ساختاری
مثبت هستند، اما وضعیت فعلی از نظر آمادگی Production
نیازمند اصلاحات P0 است. توصیه می‌شود پیش از ادامه
توسعه، یک Suite تست End-to-End برای مسیرهای
<code>Ask</code> و <code>AskStream</code> با و بدون
فایل پیوست، با و بدون ProjectId/ConversationId، و
برای کاربر Admin و غیر Admin نوشته شود.
</div>
</div>
</div>
<div class="page-info">
این مستند محرمانه بوده و صرفاً جهت بررسی فنی داخلی تهیه شده
است. هرگونه کپی‌برداری یا افشا بدون اجازه کتبی ممنوع است.
</div>
</div>
<footer class="document-footer">
<div class="footer-brand">
بازبینی فنی پنجم بر اساس کدهای به‌روزشده پروژه
xSaherelmWorkspace
</div>
<div class="footer-divider"></div>
<div>
تاریخ تهیه: آبان ۱۴۰۵ &nbsp;|&nbsp; نسخه: ۵.۰ &nbsp;|&nbsp;
طبقه‌بندی: محرمانه
</div>
</footer>
</div>
</body>
</html>