Files
xSaherelmWorkspace/Documents/Docs/Developer/xAiApi-14050807-Overview.html
T
saherelm eeeb132bb2 - Update submodule pointers: xAiApi, Modules/xAiModels, Modules/xHttpService;
- Add Documents/Docs/Developer/xAiApi-14050807-Overview.html and -Overview-1.html (review reports);
- Add Documents/GeneratedContext/*-20261029_145645.txt (xAiApi, xAiModels, xAiService);
- Add Documents/Docs/ChangeLogs/1405-08-07-v01.html and this commit message file.
2026-10-29 20:08:09 +03:30

1414 lines
43 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;
--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: 1000px;
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: 200px; height: 200px;
background: radial-gradient(circle, rgba(201,169,97,0.15) 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.9;
}
.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 {
background: linear-gradient(to left, #fffaf0, #fef5e7);
border: 1px solid #f6e05e;
border-right: 4px solid var(--accent);
padding: 18px 22px;
border-radius: 8px;
margin: 20px 0;
font-size: 14px;
}
.highlight-box strong { color: var(--accent-dark); }
.info-box {
background: linear-gradient(to left, #ebf8ff, #e6f6ff);
border: 1px solid #90cdf4;
border-right: 4px solid var(--primary-light);
padding: 18px 22px;
border-radius: 8px;
margin: 20px 0;
font-size: 14px;
}
.success-box {
background: linear-gradient(to left, #f0fff4, #e6fffa);
border: 1px solid #9ae6b4;
border-right: 4px solid var(--success);
padding: 18px 22px;
border-radius: 8px;
margin: 20px 0;
font-size: 14px;
}
.warning-box {
background: linear-gradient(to left, #fffaf0, #fef5e7);
border: 1px solid #fbd38d;
border-right: 4px solid var(--warning);
padding: 18px 22px;
border-radius: 8px;
margin: 20px 0;
font-size: 14px;
}
.danger-box {
background: linear-gradient(to left, #fff5f5, #fed7d7);
border: 1px solid #feb2b2;
border-right: 4px solid var(--danger);
padding: 18px 22px;
border-radius: 8px;
margin: 20px 0;
font-size: 14px;
}
.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 .stat-value {
font-size: 24px;
font-weight: 800;
margin-bottom: 5px;
color: var(--accent);
line-height: 1.3;
}
.stat-card .stat-label {
font-size: 12px;
opacity: 0.9;
}
.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;
}
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-001</div>
<div>نسخه: ۱.۰</div>
<div>تاریخ تهیه: آبان ۱۴۰۵</div>
<div>طبقه‌بندی: محرمانه</div>
</div>
</div>
<div class="document-title">
<span class="label">TECHNICAL ARCHITECTURE REVIEW</span>
<h1>تحلیل معماری و بررسی فنی سامانه xAiApi</h1>
<h2>
تحلیل جامع معماری، خطاهای منطقی، شرح عملکرد و پیشنهادهای
بهبود
</h2>
</div>
</header>
<div class="document-body">
<div class="intro-text">
<strong>خلاصه مدیریتی:</strong><br />
این مستند بر اساس کدهای ارائه‌شده در پروژه
xSaherelmWorkspace تهیه شده است. سامانه xAiApi یک API مبتنی
بر ASP.NET Core است که سرویس‌های هوش مصنوعی، RAG، استخراج
محتوا از فایل، Proxy مدل‌ها و مدیریت پروژه/گفتگو را ارائه
می‌کند. معماری کلی ماژولار و قابل توسعه است؛ اما در وضعیت
فعلی چند خطای منطقی مهم در لایه داده، ثبت Entity، مهاجرت
پایگاه داده، مسیرهای Proxy و قالب Streaming وجود دارد که پیش
از استفاده Production باید اصلاح شوند.
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۱</div>
<div class="section-title">
<h3>خلاصه اجرایی</h3>
<div class="subtitle">Executive Summary</div>
</div>
</div>
<div class="section-content">
<p>
سامانه از نظر ساختار ماژولار، تفکیک لایه‌ها و
استفاده از DI بسیار خوب طراحی شده است. وجود
ماژول‌های مستقل برای مدل‌های AI، سرویس‌های AI،
استخراج محتوا، فایل، هویت، Push و داده، توسعه‌پذیری
را افزایش داده است. با این حال، برخی خطاها باعث
می‌شوند رفتار واقعی سیستم با مستندات و انتظارات
طراحی هم‌راستا نباشد.
</p>
<div class="stats-grid">
<div class="stat-card">
<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 class="stat-card">
<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="danger-box">
<strong>نتیجه کلیدی:</strong> معماری پایه مناسب است،
اما تا زمان اصلاح مواردی مانند ثبت نشدن Entity وکتور
در DbContext، عدم تطابق Migration با مدل XAiVector،
اعمال نشدن فیلتر مالکیت در Queryها، عدم پیاده‌سازی
واقعی Scope در Knowledge و مسیر سراسری
ProxyController، استفاده 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">Architecture Analysis</div>
</div>
</div>
<div class="section-content">
<p>
سامانه xAiApi به عنوان Host اصلی ASP.NET Core عمل
می‌کند و از چندین ماژول داخلی استفاده می‌کند.
لایه‌بندی کلی به شکل زیر است:
</p>
<table class="styled-table">
<thead>
<tr>
<th>لایه / ماژول</th>
<th>مسئولیت اصلی</th>
<th>اجزای شاخص</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>xAiApi</strong></td>
<td>
Host API، Controllerها، Startup،
Middleware، Proxy، RAG در حافظه
</td>
<td>
DefaultAiController،
KnowledgeController،
ChatWithDocumentsController،
ProxyController، XAiModelProxyMiddleware
</td>
</tr>
<tr>
<td><strong>xAiModels</strong></td>
<td>
مدل‌های دامنه، DTOها، Entityها،
Repositoryها، Providerهای داده، GraphQL،
Hubs
</td>
<td>
XAiProject، XAiConversation، XAiMessage،
XAiVector، XAiDataProvider
</td>
</tr>
<tr>
<td><strong>xAiService</strong></td>
<td>
ثابت‌ها و Extensionهای کمکی سرویس AI
</td>
<td>
XAiServiceConstants،
XAiServiceExtensions
</td>
</tr>
<tr>
<td><strong>لایه زیرساخت</strong></td>
<td>
دسترسی داده، هویت، فایل، Push، String،
Tag، Storage
</td>
<td>
xDataService، xIdentityService،
xFileService، xPushService،
xStringService، xTagService،
xStorageService
</td>
</tr>
<tr>
<td><strong>لایه AI</strong></td>
<td>
اتصال به Ollama/OpenAI، Embedding،
Vision، RAG، Text Chunking
</td>
<td>
XAIServiceBase، XAiEmbeddingServiceBase،
XAiRAGService، XTextChunker،
XInMemoryVectorStore
</td>
</tr>
<tr>
<td><strong>لایه استخراج محتوا</strong></td>
<td>
استخراج متن/تصویر/صدا از فرمت‌های مختلف
</td>
<td>
XPdfFileContentExtractor،
XDocxFileContentExtractor،
XAudioFileContentExtractor،
XVisionFileContentExtractor و ...
</td>
</tr>
</tbody>
</table>
<p>
الگوی کلی استفاده از DI، Provider، Repository،
Enricher و Descriptor است. این الگو برای توسعه‌پذیری
مناسب است، اما پیچیدگی آن باعث شده برخی تنظیمات و
ثبت‌ها به‌صورت دستی و ناقص انجام شوند.
</p>
<div class="info-box">
<strong>نقطه قوت معماری:</strong> تفکیک Relative خوب
بین Controller، Service، Provider و Repository وجود
دارد. همچنین استفاده از Microsoft.Extensions.AI و
پشتیبانی هم‌زمان از Ollama و OpenAI، انعطاف خوبی
برای تعویض مدل فراهم می‌کند.
</div>
<div class="warning-box">
<strong>نقطه ضعف معماری:</strong> دو مسیر موازی برای
Proxy وجود دارد: Middleware و ProxyController.
همچنین RAG به دو شکل کاملاً متفاوت پیاده‌سازی شده
است: In-Memory در ChatWithDocuments و Persistent در
Knowledge، اما Scopeهای اعلام‌شده در Knowledge عملاً
در Query اعمال نمی‌شوند.
</div>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۳</div>
<div class="section-title">
<h3>شرح عملکرد سیستم</h3>
<div class="subtitle">System Behavior</div>
</div>
</div>
<div class="section-content">
<p class="no-indent">
<strong>۳-۱. چرخه Startup و DI</strong>
</p>
<p>
در Startup، ابتدا XCommons و تنظیمات برنامه ثبت
می‌شود. سپس CORS، Swagger، HttpService، Versioning،
Authorization، Identity، Storage، Push، Database،
StringService، TagService، FileService و در نهایت
XAiDataService و سرویس‌های AI ثبت می‌شوند. تنظیمات
AI از بخش AiApiConfiguration خوانده می‌شود و
اعتبارسنجی آن شامل وجود مدل‌ها و Promptهای معتبر
است.
</p>
<p class="no-indent">
<strong>۳-۲. سرویس‌های AI پایه</strong>
</p>
<p>
XAIServiceBase مسئول ارتباط با LLM است. این کلاس
تاریخچه پیام‌ها را می‌سازد، Prompt مقدمه را اضافه
می‌کند و در صورت نیاز Context مربوط به RAG را به
System Message اضافه می‌کند. XDefaultAiService از
مدل پیش‌فرض، XDefaultEmbeddingService از مدل
Embedding و XDefaultThinkingAiService از مدل
Thinking استفاده می‌کند.
</p>
<p class="no-indent">
<strong
>۳-۳. ChatWithDocuments (RAG در حافظه)</strong
>
</p>
<p>
در این جریان، فایل‌ها دریافت می‌شوند، MIME Type
آن‌ها بررسی می‌شود، متن استخراج می‌شود، توسط
XTextChunker به Chunkهای هم‌پوشان تقسیم می‌شود،
Embedding هر Chunk تولید می‌شود و در
XInMemoryVectorStore داخل یک Session نگهداری می‌شود.
سپس Ask یا AskStream با Embedding سؤال، نزدیک‌ترین
Chunkها را بازیابی و به LLM می‌دهد. Sessionها TTL
دارند و سرویس Cleanup دوره‌ای آن‌ها را حذف می‌کند.
</p>
<p class="no-indent">
<strong>۳-۴. Knowledge (RAG ماندگار)</strong>
</p>
<p>
در KnowledgeController، فایل‌ها با XAiRAGService
پردازش می‌شوند. متن استخراج، Chunk و Embedding
می‌شود و در جدول AiVectors ذخیره می‌شود. سپس Ask با
Embedding سؤال، جستجوی Cosine Similarity انجام
می‌دهد و پاسخ را با Context تولید می‌کند. شناسه
Chunkها به شکل ownerId/fileName#chunkIndex ساخته
می‌شود تا جداسازی بر اساس مالک انجام شود.
</p>
<p class="no-indent">
<strong>۳-۵. Proxy مدل‌ها</strong>
</p>
<p>
XAiModelProxyMiddleware مسیرهای دارای Prefix مشخص را
دریافت می‌کند، مدل را از تنظیمات می‌خواند، API Key
یا Token را اعتبارسنجی می‌کند، درخواست را به سرویس
مدل upstream ارسال می‌کند و پاسخ را Stream می‌کند.
ProxyController نیز یک مسیر جایگزین برای همین کار
فراهم می‌کند.
</p>
<p class="no-indent">
<strong>۳-۶. استخراج محتوا</strong>
</p>
<p>
XFileContentExtractor یک Composite Extractor است که
بر اساس MIME Type، Extractor مناسب را انتخاب می‌کند.
Extractorهای PDF، DOCX، RTF، EPUB، HTML، Code،
Image، Audio، Excel، PowerPoint، OpenDocument،
PlainText و Vision وجود دارند. PDF در صورت کم بودن
متن، Fallback به تصویر انجام می‌دهد. تصویر در صورت
فعال بودن OCR، متن استخراج می‌کند و در غیر این صورت
تصویر را برای Vision نگه می‌دارد.
</p>
<div class="success-box">
<strong>جریان کلی موفق:</strong> دریافت فایل ← تشخیص
MIME ← استخراج محتوا ← Chunking ← Embedding ← ذخیره
در Session یا جدول Vector ← بازیابی Context ← تولید
پاسخ با LLM.
</div>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۴</div>
<div class="section-title">
<h3>بررسی فنی و خطاهای منطقی</h3>
<div class="subtitle">
Technical Findings & Logical Errors
</div>
</div>
</div>
<div class="section-content">
<p>
در این بخش، خطاهای شناسایی‌شده بر اساس شدت تأثیر
دسته‌بندی شده‌اند. خطاهای «بحرانی» می‌توانند باعث
شکست Runtime، نشت داده یا عدم کارکرد اصلی شوند.
</p>
<table class="styled-table">
<thead>
<tr>
<th>شناسه</th>
<th>محل</th>
<th>شدت</th>
<th>شرح خطا و تأثیر</th>
</tr>
</thead>
<tbody>
<tr class="highlight-row">
<td>F-01</td>
<td>XAiApiDbContext</td>
<td
style="
color: var(--danger);
font-weight: 700;
"
>
بحرانی
</td>
<td>
در لیست dynamicEntityRegisterarsNames،
XAiVectorEntityRegisterar ثبت نشده است.
در نتیجه ممکن است Entity XAiVector در
Model EF Core وارد نشود و عملیات
Repository و RAG ماندگار با خطای عدم
شناسایی Entity مواجه شود.
</td>
</tr>
<tr class="highlight-row">
<td>F-02</td>
<td>Migration / XAiVector</td>
<td
style="
color: var(--danger);
font-weight: 700;
"
>
بحرانی
</td>
<td>
Entity XAiVector دارای فیلد Type و Index
روی Identifier و Type است، اما Migration
اولیه ستون Type و Indexها را ایجاد
نمی‌کند. عدم تطابق Model و Database باعث
خطای Runtime در خواندن/نوشتن وکتورها
می‌شود.
</td>
</tr>
<tr class="highlight-row">
<td>F-03</td>
<td>
XAiDataProvider.QueryProjects /
QueryConversations / QueryMessages
</td>
<td
style="
color: var(--danger);
font-weight: 700;
"
>
بحرانی
</td>
<td>
شرط ساخت Predicate برعکس نوشته شده است.
وقتی ownerId مقدار دارد، Predicate ساخته
نمی‌شود و Query بدون فیلتر مالک اجرا
می‌شود. این موضوع می‌تواند باعث نشت داده
بین کاربران شود.
</td>
</tr>
<tr class="highlight-row">
<td>F-04</td>
<td>
XAiDataProvider.GetDefaultConversation
</td>
<td
style="
color: var(--danger);
font-weight: 700;
"
>
بحرانی
</td>
<td>
در شاخه else از project.Id استفاده شده،
در حالی که project هنوز null است. این خط
باعث NullReferenceException می‌شود. باید
از projectId ورودی استفاده شود.
</td>
</tr>
<tr class="highlight-row">
<td>F-05</td>
<td>XAiRAGService / KnowledgeController</td>
<td
style="
color: var(--danger);
font-weight: 700;
"
>
بحرانی
</td>
<td>
Scopeهای Conversation، Project و Global
و همچنین Type در Ask و Retrieve عملاً
اعمال نمی‌شوند. XAiRAGService در Search
مقدار type را null می‌فرستد و
ProjectId/ConversationId را نادیده
می‌گیرد. نتیجه: جداسازی دانش بر اساس
پروژه/گفتگو کار نمی‌کند.
</td>
</tr>
<tr class="highlight-row">
<td>F-06</td>
<td>ProxyController</td>
<td
style="
color: var(--danger);
font-weight: 700;
"
>
بحرانی
</td>
<td>
Route تعریف‌شده به صورت
{modelName}/{path} در سطح Root است و
می‌تواند با مسیرهای دو بخشی دیگر مانند
DefaultAi/AskText تداخل کند. همچنین در
صورت غیرفعال بودن ProxyConfiguration،
احتمال حلقه بی‌نهایت به خود سامانه وجود
دارد.
</td>
</tr>
<tr>
<td>F-07</td>
<td>Startup.Configure</td>
<td
style="
color: var(--danger);
font-weight: 700;
"
>
بالا
</td>
<td>
چند Middleware مانند UseXStorageService،
UseXPushService، UseXDatabase،
UseXStringService، UseXTagService و
UseXFileService بعد از UseEndpoints ثبت
شده‌اند. Middlewareهای بعد از
UseEndpoints برای درخواست‌های Match شده
اجرا نمی‌شوند.
</td>
</tr>
<tr>
<td>F-08</td>
<td>XAiServiceControllerBase</td>
<td
style="
color: var(--danger);
font-weight: 700;
"
>
بالا
</td>
<td>
در AskTextStream و AskStream، خروجی با
Content-Type برابر text/event-stream
ارسال می‌شود اما داده‌ها با قالب معتبر
SSE یعنی data: ... و پایان‌بندی مناسب
نوشته نمی‌شوند. کلاینت‌های استاندارد SSE
ممکن است داده را دریافت نکنند.
</td>
</tr>
<tr>
<td>F-09</td>
<td>XCodeFileContentExtractor</td>
<td
style="
color: var(--danger);
font-weight: 700;
"
>
بالا
</td>
<td>
متن فایل خوانده می‌شود اما به
result.Text اختصاص داده نمی‌شود. در
نتیجه استخراج محتوای فایل‌های کد تقریباً
همیشه خالی است. همچنین نام فایل پیش‌فرض
book.epub به اشتباه استفاده شده است.
</td>
</tr>
<tr>
<td>F-10</td>
<td>XImageFileContentExtractor</td>
<td
style="
color: var(--warning);
font-weight: 700;
"
>
متوسط
</td>
<td>
در Constructor حتی وقتی
EnableOcrFallback برابر false است، وجود
DataPath و DefaultLanguage الزامی شده
است. این موضوع باعث می‌شود استخراج تصویر
بدون OCR هم شکست بخورد.
</td>
</tr>
<tr>
<td>F-11</td>
<td>XAiEmbeddingServiceBase</td>
<td
style="
color: var(--warning);
font-weight: 700;
"
>
متوسط
</td>
<td>
در حالت Ollama، نام مدل Embedding
(descriptor.LLM) هنگام ساخت
OllamaApiClient استفاده نمی‌شود. ممکن
است مدل پیش‌فرض Ollama انتخاب شود و
Embedding با مدل مورد انتظار متفاوت
باشد.
</td>
</tr>
<tr>
<td>F-12</td>
<td>
XAiModelsExtensions.HasDefaultProject /
HasDefaultConversation
</td>
<td
style="
color: var(--warning);
font-weight: 700;
"
>
متوسط
</td>
<td>
شرط اعتبارسنجی برعکس است: وقتی
Collection دارای Child است، Exception
پرتاب می‌شود. این متدها در صورت استفاده
می‌توانند رفتار نادرست ایجاد کنند.
</td>
</tr>
<tr>
<td>F-13</td>
<td>
XAiDataProvider.CreateProject /
CreateConversation
</td>
<td
style="
color: var(--warning);
font-weight: 700;
"
>
متوسط
</td>
<td>
متغیر isDefaultLanguageHandled پس از
انتساب زبان پیش‌فرض مقدار false می‌گیرد.
بنابراین برای چند Locale بدون زبان، زبان
پیش‌فرض تکراری اعمال می‌شود.
</td>
</tr>
<tr>
<td>F-14</td>
<td>XAiDataProvider.LoadConversations</td>
<td
style="
color: var(--warning);
font-weight: 700;
"
>
متوسط
</td>
<td>
برای Conversationها ignoreSoftDeleteds
برابر false است. در نتیجه ممکن است
آیتم‌های حذف‌شده در لیست برگردند.
</td>
</tr>
<tr>
<td>F-15</td>
<td>XAiRAGService.IngestAsync</td>
<td
style="
color: var(--warning);
font-weight: 700;
"
>
متوسط
</td>
<td>
فیلدهای Scope، ScopeId و Type در
XAiKnowledgeIngestResult و
XAiKnowledgeDocumentInfo پر نمی‌شوند.
همچنین محدودیت‌های MaxFilesPerIngest،
MaxFileSizeBytes و MaxDocumentsPerScope
اعمال نمی‌شوند.
</td>
</tr>
<tr>
<td>F-16</td>
<td>
XAiServiceControllerBase /
DefaultAiController
</td>
<td
style="
color: var(--warning);
font-weight: 700;
"
>
امنیتی
</td>
<td>
برخی Actionها با وجود [Authorize] در سطح
کلاس، دارای [AllowAnonymous] هستند. این
موضوع باعث می‌شود AskText و Embedding
بدون احراز هویت قابل فراخوانی باشند.
</td>
</tr>
<tr>
<td>F-17</td>
<td>
XAiModelProxyMiddleware /
ProxyController
</td>
<td
style="
color: var(--warning);
font-weight: 700;
"
>
متوسط
</td>
<td>
دو مسیر موازی برای Proxy وجود دارد.
ProxyController درخواست را به همین
سامانه و مسیر ai-model می‌فرستد که یک
Hop اضافی و ریسک Loop ایجاد می‌کند.
</td>
</tr>
</tbody>
</table>
<div class="danger-box">
<strong>مهم‌ترین ریسک:</strong> خطاهای F-01 تا F-05
مستقیماً روی صحت داده، جداسازی کاربران و کارکرد RAG
ماندگار اثر می‌گذارند. این موارد باید قبل از هر تست
پذیرش یا استقرار اصلاح شوند.
</div>
<p class="no-indent">
<strong>نمونه اصلاح پیشنهادی برای Queryها:</strong>
</p>
<div class="highlight-box">
به جای شرط
<code>if (ownerId.IsNullOrEmpty())</code> باید از
<code>if (!ownerId.IsNullOrEmpty())</code> استفاده
شود تا Predicate مالکیت در زمان وجود ownerId ساخته
شود. همچنین در GetDefaultConversation باید
<code>id: projectId</code> به جای
<code>id: project.Id</code> در شاخه else قرار گیرد.
</div>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۵</div>
<div class="section-title">
<h3>پیشنهادهای لازم برای بهبود عملکرد</h3>
<div class="subtitle">
Improvement Recommendations
</div>
</div>
</div>
<div class="section-content">
<p>
پیشنهادها بر اساس اولویت اجرایی دسته‌بندی شده‌اند:
</p>
<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>
ثبت XAiVectorEntityRegisterar در
XAiApiDbContext و ایجاد Migration جدید
برای ستون Type و Indexهای Identifier و
Type.
</td>
<td>
رفع خطای Runtime و تضمین کارکرد
Knowledge/RAG ماندگار.
</td>
</tr>
<tr class="highlight-row">
<td
style="
color: var(--danger);
font-weight: 700;
"
>
P0
</td>
<td>
اصلاح شرط‌های ownerId در QueryProjects،
QueryConversations و QueryMessages و رفع
NullReferenceException در
GetDefaultConversation.
</td>
<td>
جلوگیری از نشت داده و افزایش پایداری
عملیات پیش‌فرض.
</td>
</tr>
<tr class="highlight-row">
<td
style="
color: var(--danger);
font-weight: 700;
"
>
P0
</td>
<td>
پیاده‌سازی واقعی Scope و Type در
XAiRAGService: اعمال ProjectId،
ConversationId و Type در
SearchVectorsAsync و ذخیره آن‌ها در
Ingest.
</td>
<td>
جداسازی صحیح دانش بین Global، Project و
Conversation.
</td>
</tr>
<tr class="highlight-row">
<td
style="
color: var(--danger);
font-weight: 700;
"
>
P0
</td>
<td>
محدودکردن Route مربوط به ProxyController
یا حذف آن و اتکا به Middleware. جلوگیری
از Loop در حالت Proxy غیرفعال.
</td>
<td>
رفع تداخل Routing و کاهش ریسک
امنیتی/عملکردی.
</td>
</tr>
<tr>
<td
style="
color: var(--warning);
font-weight: 700;
"
>
P1
</td>
<td>
جابه‌جایی Middlewareهای Storage، Push،
Database، String، Tag و File به قبل از
UseEndpoints.
</td>
<td>
اطمینان از اجرای واقعی Middlewareها در
Pipeline.
</td>
</tr>
<tr>
<td
style="
color: var(--warning);
font-weight: 700;
"
>
P1
</td>
<td>
یکسان‌سازی قالب SSE در همه Controllerها
با prefix data: و پایان‌بندی دو newline
و ارسال Event نهایی.
</td>
<td>
سازگاری با کلاینت‌های استاندارد SSE و
بهبود تجربه Streaming.
</td>
</tr>
<tr>
<td
style="
color: var(--warning);
font-weight: 700;
"
>
P1
</td>
<td>
اصلاح XCodeFileContentExtractor برای
انتساب واقعی متن خوانده‌شده به
result.Text و حذف نام فایل پیش‌فرض
اشتباه.
</td>
<td>
کارکرد صحیح استخراج کد در RAG و
ChatWithDocuments.
</td>
</tr>
<tr>
<td
style="
color: var(--warning);
font-weight: 700;
"
>
P1
</td>
<td>
اعتبارسنجی OCR فقط در صورت
EnableOcrFallback و استفاده از مدل
Embedding Ollama به‌صورت صریح.
</td>
<td>
کاهش خطاهای Startup و افزایش دقت
Embedding.
</td>
</tr>
<tr>
<td
style="
color: var(--primary-light);
font-weight: 700;
"
>
P2
</td>
<td>
افزودن محدودیت‌های Ingest شامل تعداد
فایل، اندازه فایل و تعداد سند در Scope.
</td>
<td>
جلوگیری از مصرف بی‌رویه حافظه و پایگاه
داده.
</td>
</tr>
<tr>
<td
style="
color: var(--primary-light);
font-weight: 700;
"
>
P2
</td>
<td>
بهینه‌سازی جستجوی Vector: استفاده از
Index برداری یا حداقل فیلترهای دقیق‌تر
به جای بارگذاری همه رکوردها در حافظه.
</td>
<td>افزایش مقیاس‌پذیری Knowledge.</td>
</tr>
<tr>
<td
style="
color: var(--primary-light);
font-weight: 700;
"
>
P2
</td>
<td>
افزودن تست‌های واحد و یکپارچه برای
Queryهای مالکیت، RAG Scope، SSE، Proxy و
Extractorها.
</td>
<td>
کاهش Regression و افزایش اطمینان از
اصلاحات.
</td>
</tr>
<tr>
<td
style="
color: var(--primary-light);
font-weight: 700;
"
>
P2
</td>
<td>
بازبینی سیاست دسترسی Actionها و حذف
AllowAnonymousهای ناخواسته از سرویس‌های
AI.
</td>
<td>افزایش امنیت API.</td>
</tr>
</tbody>
</table>
<div class="info-box">
<strong>پیشنهاد معماری:</strong> بهتر است دو مسیر
RAG (In-Memory و Persistent) در یک Abstraction مشترک
با نام IXAiVectorSearchService ادغام شوند تا
Behavior جستجو، Scope، Type و Source Mapping در همه
جا یکسان باشد.
</div>
<div class="success-box">
<strong>پیشنهاد کوتاه‌مدت:</strong> ابتدا F-01 تا
F-06 اصلاح شود، سپس یک تست End-to-End برای Ingest،
Ask، AskStream، Scope و Proxy انجام گیرد. پس از آن
بهبودهای عملکردی و امنیتی در اولویت بعدی قرار گیرند.
</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>
سامانه xAiApi از نظر ساختار ماژولار و استفاده از
الگوهای DI، Provider و Repository یک پایه قابل توسعه
دارد. پشتیبانی از چند Provider مدل، استخراج محتوای
متنوع، RAG در حافظه و RAG ماندگار، و Proxy مدل‌ها
نشان‌دهنده دامنه وسیع قابلیت‌های طراحی‌شده است.
</p>
<p>
با این حال، وضعیت فعلی کد از نظر صحت منطقی و آمادگی
Production نیازمند اصلاحات مشخص است. مهم‌ترین مشکلات
در لایه داده و جداسازی مالکیت، ثبت Entity و
Migration، پیاده‌سازی Scope در Knowledge و مسیرهای
Proxy متمرکز هستند. اصلاح این موارد می‌تواند سامانه
را به یک وضعیت پایدار و قابل اتکا نزدیک کند.
</p>
<div class="conclusion-box">
<h3>🎯 جمع‌بندی اجرایی</h3>
<p>
معماری کلی مناسب است، اما بدون اصلاح خطاهای P0،
استفاده از سامانه در محیط واقعی ریسک بالایی
دارد.
</p>
<div class="highlight">
<strong>اولویت‌های اصلاح:</strong><br />
ثبت Entity وکتور + Migration صحیح + اصلاح
Queryهای مالکیت + پیاده‌سازی Scope در RAG +
محدودسازی ProxyController + اصلاح Startup
Pipeline
</div>
</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>