Update xAiApi Submodule (Chat With Documents) and Add ChangeLog / Plan Documents ...
- Update xAiApi Submodule Pointer to Chat With Documents (In-Memory RAG) Implementation; - Add Documents/Docs/ChangeLogs/1405-08-03.html (ChangeLog of Pushed Commits); - Add Documents/Docs/ChangeLogs/1405-08-03-uncommitted.html (ChangeLog of this Commit); - Add Documents/Docs/ChangeLogs/CommitMessage-1405-08-03.txt; - Add Documents/Markdown/plan1.md and plan1.html (Chat With Documents Implementation Plan); - ...
This commit is contained in:
@@ -0,0 +1,236 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fa" dir="rtl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>گزارش تغییرات کامیتنشده ۱۴۰۵/۰۸/۰۳ - xSaherelmWorkspace</title>
|
||||
<style>
|
||||
:root {
|
||||
--primary: #1e3a8a;
|
||||
--secondary: #3b82f6;
|
||||
--accent: #f59e0b;
|
||||
--success: #10b981;
|
||||
--danger: #ef4444;
|
||||
--warning: #f97316;
|
||||
--bg-light: #f8fafc;
|
||||
--bg-code: #1e293b;
|
||||
--text-dark: #0f172a;
|
||||
--text-muted: #64748b;
|
||||
--border: #e2e8f0;
|
||||
}
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
body { font-family: 'Tahoma', 'Segoe UI', sans-serif; background: linear-gradient(135deg, #f8fafc 0%, #e0e7ff 100%); color: var(--text-dark); line-height: 1.8; padding: 20px; }
|
||||
.container { max-width: 1200px; margin: 0 auto; background: white; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,0.1); overflow: hidden; }
|
||||
.header { background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%); color: white; padding: 40px; text-align: center; }
|
||||
.header h1 { font-size: 2.1em; margin-bottom: 10px; }
|
||||
.header .subtitle { font-size: 1.1em; opacity: 0.95; }
|
||||
.meta-bar { display: flex; justify-content: space-between; background: var(--bg-light); padding: 15px 30px; border-bottom: 2px solid var(--border); flex-wrap: wrap; gap: 15px; }
|
||||
.meta-item { display: flex; align-items: center; gap: 8px; font-size: 0.9em; color: var(--text-muted); }
|
||||
.meta-item strong { color: var(--primary); }
|
||||
.content { padding: 40px; }
|
||||
.section { margin-bottom: 35px; padding: 25px; background: var(--bg-light); border-radius: 12px; border-right: 5px solid var(--secondary); }
|
||||
.section h2 { color: var(--primary); font-size: 1.5em; margin-bottom: 18px; padding-bottom: 10px; border-bottom: 2px solid var(--border); }
|
||||
.section h3 { color: var(--secondary); font-size: 1.15em; margin: 22px 0 12px; }
|
||||
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 15px; margin-bottom: 10px; }
|
||||
.stat-card { background: white; border: 1px solid var(--border); border-radius: 10px; padding: 18px; text-align: center; }
|
||||
.stat-card .value { font-size: 1.9em; font-weight: bold; color: var(--primary); }
|
||||
.stat-card .label { font-size: 0.85em; color: var(--text-muted); }
|
||||
.stat-card.add .value { color: var(--success); }
|
||||
.stat-card.del .value { color: var(--danger); }
|
||||
table { width: 100%; border-collapse: collapse; background: white; border-radius: 8px; overflow: hidden; margin: 12px 0; font-size: 0.93em; }
|
||||
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: right; vertical-align: top; }
|
||||
th { background: var(--primary); color: white; font-weight: 600; }
|
||||
tr:last-child td { border-bottom: none; }
|
||||
tr:hover td { background: #f1f5f9; }
|
||||
code { font-family: 'Consolas', 'Courier New', monospace; background: #e2e8f0; padding: 2px 6px; border-radius: 4px; font-size: 0.9em; direction: ltr; display: inline-block; }
|
||||
pre { background: var(--bg-code); color: #e2e8f0; padding: 16px; border-radius: 8px; direction: ltr; text-align: left; overflow-x: auto; font-family: 'Consolas', 'Courier New', monospace; font-size: 0.88em; line-height: 1.6; }
|
||||
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.78em; font-weight: bold; color: white; }
|
||||
.badge.new { background: var(--success); }
|
||||
.badge.mod { background: var(--warning); }
|
||||
.badge.sub { background: var(--secondary); }
|
||||
.commit { background: white; border: 1px solid var(--border); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
|
||||
.commit-head { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
|
||||
.commit-head .msg { font-weight: bold; color: var(--primary); font-size: 1.05em; }
|
||||
.commit-head .info { color: var(--text-muted); font-size: 0.85em; }
|
||||
.diffstat { color: var(--text-muted); font-size: 0.85em; }
|
||||
.diffstat .plus { color: var(--success); font-weight: bold; }
|
||||
.diffstat .minus { color: var(--danger); font-weight: bold; }
|
||||
ul { padding-right: 22px; margin: 8px 0; }
|
||||
li { margin-bottom: 6px; }
|
||||
.note { background: #fffbeb; border-right: 4px solid var(--accent); padding: 12px 16px; border-radius: 8px; margin-top: 12px; font-size: 0.92em; }
|
||||
.warn { background: #fef2f2; border-right: 4px solid var(--danger); padding: 12px 16px; border-radius: 8px; margin-top: 12px; font-size: 0.92em; }
|
||||
.footer { background: var(--bg-light); border-top: 2px solid var(--border); padding: 18px 30px; text-align: center; color: var(--text-muted); font-size: 0.85em; }
|
||||
a { color: var(--secondary); text-decoration: none; }
|
||||
a:hover { text-decoration: underline; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
|
||||
<div class="header">
|
||||
<h1>گزارش تغییرات کامیتنشده (Uncommitted ChangeLog)</h1>
|
||||
<div class="subtitle">یکشنبه ۳ آبان ۱۴۰۵ | 2026-10-25 | xSaherelmWorkspace</div>
|
||||
</div>
|
||||
|
||||
<div class="meta-bar">
|
||||
<div class="meta-item"><strong>نویسنده:</strong> Hadi Khazaee Asl</div>
|
||||
<div class="meta-item"><strong>برنچ:</strong> <code>master</code></div>
|
||||
<div class="meta-item"><strong>وضعیت:</strong> تغییرات در Working Tree، هنوز کامیت نشدهاند</div>
|
||||
<div class="meta-item"><strong>پایهٔ کار:</strong> workspace <code>43f5cc0</code> / xAiApi <code>47d8a19</code></div>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
|
||||
<!-- خلاصه -->
|
||||
<div class="section">
|
||||
<h2>خلاصه</h2>
|
||||
<div class="stats">
|
||||
<div class="stat-card"><div class="value">2</div><div class="label">مخزن تغییریافته</div></div>
|
||||
<div class="stat-card"><div class="value">5</div><div class="label">فایل جدید</div></div>
|
||||
<div class="stat-card"><div class="value">9</div><div class="label">فایل تغییریافته</div></div>
|
||||
<div class="stat-card"><div class="value">5</div><div class="label">Endpoint جدید</div></div>
|
||||
<div class="stat-card add"><div class="value">+1,090</div><div class="label">خط اضافهشده (xAiApi)</div></div>
|
||||
<div class="stat-card del"><div class="value">-170</div><div class="label">خط حذفشده (xAiApi)</div></div>
|
||||
</div>
|
||||
<p>
|
||||
این گزارش ادامهٔ کارهای ثبتشده در <a href="1405-08-03.html">ChangeLog ۳ آبان ۱۴۰۵</a> است و تکمیل قابلیت
|
||||
<strong>Chat With Documents (RAG درونحافظهای)</strong> در پروژهٔ <code>xAiApi</code> را پوشش میدهد:
|
||||
تعریف مدلهای DTO، افزودن متدهای <code>AskWithContext</code> به سرویس پایهٔ AI،
|
||||
بازنویسی کامل <code>ChatWithDocumentsController</code> با Endpointهای Ingest / Ask / AskStream / Session،
|
||||
سرویس پسزمینهٔ پاکسازی Sessionهای منقضی و پیکربندی <code>RAGDescriptor</code>.
|
||||
در مخزن اصلی نیز فایلهای مستندات (ChangeLog و طرح <code>plan1</code>) اضافه شدهاند.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- مخزن اصلی -->
|
||||
<div class="section">
|
||||
<h2>۱. مخزن اصلی: xSaherelmWorkspace</h2>
|
||||
<p>ریموت: <a href="https://git.saherelm.ir/saherelm/xSaherelmWorkspace.git">git.saherelm.ir/saherelm/xSaherelmWorkspace.git</a></p>
|
||||
|
||||
<div class="commit">
|
||||
<div class="commit-head">
|
||||
<span class="msg">تغییرات کامیتنشده</span>
|
||||
<span class="info">بر پایهٔ <code>43f5cc0</code> | <code>git status</code></span>
|
||||
</div>
|
||||
<div class="diffstat">4 مورد | 3 فایل جدید + 1 سابماژول تغییریافته</div>
|
||||
<table>
|
||||
<thead><tr><th>نوع</th><th>فایل</th><th>توضیح</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td><span class="badge new">جدید</span></td><td><code>Documents/Docs/ChangeLogs/1405-08-03.html</code></td><td>گزارش تغییرات پوششدهٔ ۳ آبان (TextChunker و In-Memory Vector Store)</td></tr>
|
||||
<tr><td><span class="badge new">جدید</span></td><td><code>Documents/Markdown/plan1.md</code></td><td>طرح گامبهگام تکمیل Chat With Documents (وضعیت فعلی، گامهای ۱ تا ۸ و نکات تصمیمگیری)</td></tr>
|
||||
<tr><td><span class="badge new">جدید</span></td><td><code>Documents/Markdown/plan1.html</code></td><td>نسخهٔ HTML طرح فوق</td></tr>
|
||||
<tr><td><span class="badge sub">سابماژول</span></td><td><code>xAiApi</code></td><td>محتوای سابماژول تغییر کرده است (<code>Submodule xAiApi contains modified content</code>)؛ پس از کامیت در xAiApi باید پوینتر بهروزرسانی شود</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- xAiApi -->
|
||||
<div class="section">
|
||||
<h2>۲. سابماژول: xAiApi</h2>
|
||||
<p>ریموت: <a href="https://git.saherelm.ir/saherelm/xSaherElmAiApi.git">git.saherelm.ir/saherelm/xSaherElmAiApi.git</a></p>
|
||||
|
||||
<div class="commit">
|
||||
<div class="commit-head">
|
||||
<span class="msg">Implement Chat With Documents (In-Memory RAG) ...</span>
|
||||
<span class="info">کامیتنشده | بر پایهٔ <code>47d8a19</code></span>
|
||||
</div>
|
||||
<div class="diffstat">11 فایل (۲ جدید، ۹ تغییریافته) | <span class="plus">+1,090</span> / <span class="minus">-170</span></div>
|
||||
<table>
|
||||
<thead><tr><th>نوع</th><th>فایل</th><th>تغییر</th><th>توضیح</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td><span class="badge new">جدید</span></td><td><code>Models/XAiDocumentModels.cs</code></td><td>+181</td><td>مدلهای DTO: <code>XAiDocumentIngestResult</code>, <code>XAiDocumentAskRequest</code>, <code>XAiDocumentSource</code>, <code>XAiDocumentAnswer</code>, <code>XAiDocumentAnswerChunk</code> (SSE), <code>XAiDocumentSessionInfo</code>, <code>XAiDocumentRAGDescriptor</code></td></tr>
|
||||
<tr><td><span class="badge new">جدید</span></td><td><code>Providers/XInMemoryVectorStoreCleanupService.cs</code></td><td>+77</td><td><code>BackgroundService</code> که هر ۵ دقیقه <code>RemoveExpired()</code> را روی Vector Store اجرا و نتیجه را لاگ میکند</td></tr>
|
||||
<tr><td><span class="badge mod">تغییر</span></td><td><code>Controllers/ChatWithDocumentsController.cs</code></td><td>+672</td><td>بازنویسی کامل: اصلاح <code>using</code> به <code>Microsoft.AspNetCore.Mvc</code>، حذف فیلد محلی و <code>IDisposable</code>، تزریق <code>IXTextChunker</code>/<code>IXInMemoryVectorStore</code>/<code>IXDefaultEmbeddingService</code>/<code>IXFileContentExtractor</code>/<code>XAiApiConfiguration</code>، پیادهسازی ۵ Endpoint و متدهای کمکی <code>ExtractText</code>, <code>EmbedChunks</code>, <code>Retrieve</code>, <code>ToSources</code>, <code>GetMetadata</code>, <code>WriteChunk</code></td></tr>
|
||||
<tr><td><span class="badge mod">تغییر</span></td><td><code>Providers/XAIServiceBase.cs</code></td><td>+183 / -5</td><td>region جدید «Context Actions»: <code>AskWithContextAsync</code>, <code>AskWithContextAsEnumerable</code>, <code>GetContextHistory</code> (Introduction + پرامپت RAG + بلوک Context + سؤال کاربر) و <code>BuildContextBlock</code>؛ بدون ذخیره در دیتابیس؛ حذف usingهای بلااستفاده</td></tr>
|
||||
<tr><td><span class="badge mod">تغییر</span></td><td><code>Interfaces/IXAiServiceBase.cs</code></td><td>+34 / -1</td><td>افزودن امضای <code>AskWithContextAsync</code> و <code>AskWithContextAsEnumerable</code> در region «Context Actions»</td></tr>
|
||||
<tr><td><span class="badge mod">تغییر</span></td><td><code>Providers/XInMemoryVectorStore.cs</code></td><td>+62 / -26</td><td>بهینهسازی <code>Search</code>: تبدیل <code>queryEmbedding.ToArray()</code> یکبار قبل از حلقه؛ فرمتدهی امضاها و انتقال متدهای خصوصی به region «Private»</td></tr>
|
||||
<tr><td><span class="badge mod">تغییر</span></td><td><code>Extensions/XModelsExtensions.cs</code></td><td>+21 / -1</td><td>افزودن <code>IsValid(this XAiDocumentAskRequest)</code> (بررسی Prompt، SessionId، بازهٔ TopK و MinScore)</td></tr>
|
||||
<tr><td><span class="badge mod">تغییر</span></td><td><code>DI/XDIHelperExtension.cs</code></td><td>+11</td><td>ثبت <code>XInMemoryVectorStoreCleanupService</code> بهعنوان HostedService و افزودن <code>AddXAiChatWithDocuments()</code></td></tr>
|
||||
<tr><td><span class="badge mod">تغییر</span></td><td><code>Configurations/XAiApiConfiguration.cs</code></td><td>+5</td><td>افزودن پراپرتی <code>RAGDescriptor</code> از نوع <code>XAiDocumentRAGDescriptor</code></td></tr>
|
||||
<tr><td><span class="badge mod">تغییر</span></td><td><code>Startup.cs</code></td><td>+3 / -3</td><td>جایگزینی <code>AddXAiInMemoryVectorStore()</code> با <code>AddXAiChatWithDocuments()</code></td></tr>
|
||||
<tr><td><span class="badge mod">تغییر</span></td><td><code>appsettings.Development.json</code></td><td>+18 (محتوایی)</td><td>افزودن پرامپت <code>ChatWithDocuments</code> به <code>Prompts</code> و بخش <code>RAGDescriptor</code>؛ دیف خام (+142/-124) ناشی از تغییر فاصله/Line Ending است</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3>Endpointهای کنترلر <code>ChatWithDocuments</code></h3>
|
||||
<table>
|
||||
<thead><tr><th>متد</th><th>مسیر</th><th>ورودی</th><th>خروجی / توضیح</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td><code>POST</code></td><td><code>/ChatWithDocuments/Ingest</code></td><td><code>multipart/form-data</code> (files, sessionId?, ttlMinutes?)</td><td><code>XAiDocumentIngestResult</code> — Extract → Chunk → Embed (Batch) → Store؛ فایلهای ناسازگار/خالی در <code>SkippedFiles</code></td></tr>
|
||||
<tr><td><code>POST</code></td><td><code>/ChatWithDocuments/Ask</code></td><td><code>XAiDocumentAskRequest</code></td><td><code>XAiDocumentAnswer</code> — Embedding سؤال → Search → <code>AskWithContextAsync</code>؛ در نبود Context: <code>NoContextFound = true</code></td></tr>
|
||||
<tr><td><code>POST</code></td><td><code>/ChatWithDocuments/AskStream</code></td><td><code>XAiDocumentAskRequest</code></td><td>SSE (<code>text/event-stream</code>) — رویداد اول Sources، سپس Deltaهای متن، رویداد آخر <code>IsFinal = true</code></td></tr>
|
||||
<tr><td><code>GET</code></td><td><code>/ChatWithDocuments/Session/{id}</code></td><td>Guid</td><td><code>XAiDocumentSessionInfo</code> (بدون Embedding) یا 404</td></tr>
|
||||
<tr><td><code>DELETE</code></td><td><code>/ChatWithDocuments/Session/{id}</code></td><td>Guid</td><td>حذف Session؛ 200 / 404</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3>پیکربندی جدید در <code>appsettings.Development.json</code></h3>
|
||||
<pre>"RAGDescriptor": {
|
||||
"MaxTopK": 20,
|
||||
"DefaultTopK": 5,
|
||||
"DefaultTtlMinutes": 30,
|
||||
"EmbeddingBatchSize": 32,
|
||||
"SourceSnippetLength": 200,
|
||||
"DefaultMinScore": "0.35f",
|
||||
"MetadataFileName": "fileName",
|
||||
"MetadataMimeType": "mimeType",
|
||||
"PromptName": "ChatWithDocuments",
|
||||
"MetadataChunkIndex": "chunkIndex"
|
||||
}</pre>
|
||||
<pre>{
|
||||
"Name": "ChatWithDocuments",
|
||||
"Template": "You are a document question-answering assistant. Answer the user's question ONLY based on the provided Context chunks below. ...",
|
||||
"Description": "System prompt for RAG based Chat With Documents",
|
||||
"Params": []
|
||||
}</pre>
|
||||
</div>
|
||||
|
||||
<h3>نکات فنی</h3>
|
||||
<ul>
|
||||
<li>تمام دسترسیها به Session با <code>ownerId = (await GetUserInfo()).UserId</code> محدود میشود و همهٔ Endpointها از الگوی <code>try/catch</code> + <code>GetExceptionActionResult(ex)</code> پیروی میکنند.</li>
|
||||
<li>Context بهصورت پیام <strong>System</strong> جداگانه (پرامپت RAG + بلوک Chunkها با Identifier) به مدل ارسال میشود؛ هیچچیز در دیتابیس ذخیره نمیشود.</li>
|
||||
<li><code>TopK</code> با <code>Math.Clamp(1, MaxTopK)</code> محدود میشود و مقادیر پیشفرض از <code>RAGDescriptor</code> خوانده میشوند.</li>
|
||||
<li>Embedding تکهها بهصورت Batch (<code>EmbeddingBatchSize = 32</code>) انجام میشود و Metadata هر Vector شامل <code>fileName</code>, <code>mimeType</code>, <code>chunkIndex</code> است.</li>
|
||||
<li>سرویس پاکسازی بهصورت <code>HostedService</code> داخل <code>AddXAiInMemoryVectorStore()</code> ثبت میشود.</li>
|
||||
</ul>
|
||||
<div class="warn">
|
||||
<strong>هشدار پیکربندی:</strong> مقدار <code>"DefaultMinScore": "0.35f"</code> در <code>appsettings.Development.json</code> بهصورت رشته با پسوند <code>f</code> نوشته شده است.
|
||||
بایندر پیکربندی .NET نمیتواند آن را به <code>float</code> تبدیل کند و هنگام Bind خطا میدهد؛ باید قبل از کامیت به <code>0.35</code> (عدد) اصلاح شود.
|
||||
</div>
|
||||
<div class="note">
|
||||
<strong>کارهای باقیمانده طبق طرح (plan1.md):</strong> افزودن <code>RAGDescriptor</code> و پرامپت <code>ChatWithDocuments</code> به <code>appsettings.json</code> (Production)،
|
||||
تست دستی جریان Ingest → Ask → AskStream → Delete با یک PDF، تصمیم دربارهٔ پروژهٔ یونیتتست (<code>xAiApi.Tests</code>) و پاکسازی فایلهای موقت <code>tmp.md</code> / <code>tmp.html</code>.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- بدون تغییر -->
|
||||
<div class="section">
|
||||
<h2>۳. مخازن بدون تغییر</h2>
|
||||
<p>در ۳۲ سابماژول زیر تغییر کامیتنشدهای وجود ندارد:</p>
|
||||
<ul>
|
||||
<li><strong>Modules (۲۸ مورد):</strong> xAiModels, xAiService, xApiSDKHolder, xCategoryService, xCommons, xContentService, xDataService, xEventService, xExceptions, xFileService, xFrameworkComponentsHolder, xFrameworkCoreHolder, xFrameworkIdentitySDKHolder, xFrameworkPushServiceHolder, xFrameworkServicesHolder, xHttpService, xIdentityHelper, xIdentityModels, xIdentityService, xMessageService, xModels, xPushService, xServices, xStorageService, xStringService, xTagService, xTermsAndConditionsService, xWebinarService</li>
|
||||
<li><strong>Applications (۴ مورد):</strong> xApi, xClient, xIds, xFrameworkTest</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- دستورات -->
|
||||
<div class="section">
|
||||
<h2>۴. دستورات استفادهشده برای استخراج تغییرات</h2>
|
||||
<pre>git status --porcelain=v1 -uall
|
||||
git diff --submodule=log xAiApi
|
||||
git -C xAiApi status --porcelain=v1 -uall
|
||||
git -C xAiApi diff --stat
|
||||
git -C xAiApi diff --ignore-all-space --stat -- appsettings.Development.json</pre>
|
||||
<p>پیامهای کامیت پیشنهادی در فایل <code>CommitMessage-1405-08-03.txt</code> کنار همین گزارش قرار دارد.</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
تولیدشده در تاریخ ۱۴۰۵/۰۸/۰۳ (2026-10-25) | فن آوران ساحر علم
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,229 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fa" dir="rtl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>گزارش تغییرات ۱۴۰۵/۰۸/۰۳ - xSaherelmWorkspace</title>
|
||||
<style>
|
||||
:root {
|
||||
--primary: #1e3a8a;
|
||||
--secondary: #3b82f6;
|
||||
--accent: #f59e0b;
|
||||
--success: #10b981;
|
||||
--danger: #ef4444;
|
||||
--warning: #f97316;
|
||||
--bg-light: #f8fafc;
|
||||
--bg-code: #1e293b;
|
||||
--text-dark: #0f172a;
|
||||
--text-muted: #64748b;
|
||||
--border: #e2e8f0;
|
||||
}
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
body { font-family: 'Tahoma', 'Segoe UI', sans-serif; background: linear-gradient(135deg, #f8fafc 0%, #e0e7ff 100%); color: var(--text-dark); line-height: 1.8; padding: 20px; }
|
||||
.container { max-width: 1200px; margin: 0 auto; background: white; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,0.1); overflow: hidden; }
|
||||
.header { background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%); color: white; padding: 40px; text-align: center; }
|
||||
.header h1 { font-size: 2.1em; margin-bottom: 10px; }
|
||||
.header .subtitle { font-size: 1.1em; opacity: 0.95; }
|
||||
.meta-bar { display: flex; justify-content: space-between; background: var(--bg-light); padding: 15px 30px; border-bottom: 2px solid var(--border); flex-wrap: wrap; gap: 15px; }
|
||||
.meta-item { display: flex; align-items: center; gap: 8px; font-size: 0.9em; color: var(--text-muted); }
|
||||
.meta-item strong { color: var(--primary); }
|
||||
.content { padding: 40px; }
|
||||
.section { margin-bottom: 35px; padding: 25px; background: var(--bg-light); border-radius: 12px; border-right: 5px solid var(--secondary); }
|
||||
.section h2 { color: var(--primary); font-size: 1.5em; margin-bottom: 18px; padding-bottom: 10px; border-bottom: 2px solid var(--border); }
|
||||
.section h3 { color: var(--secondary); font-size: 1.15em; margin: 22px 0 12px; }
|
||||
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 15px; margin-bottom: 10px; }
|
||||
.stat-card { background: white; border: 1px solid var(--border); border-radius: 10px; padding: 18px; text-align: center; }
|
||||
.stat-card .value { font-size: 1.9em; font-weight: bold; color: var(--primary); }
|
||||
.stat-card .label { font-size: 0.85em; color: var(--text-muted); }
|
||||
.stat-card.add .value { color: var(--success); }
|
||||
.stat-card.del .value { color: var(--danger); }
|
||||
table { width: 100%; border-collapse: collapse; background: white; border-radius: 8px; overflow: hidden; margin: 12px 0; font-size: 0.93em; }
|
||||
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: right; vertical-align: top; }
|
||||
th { background: var(--primary); color: white; font-weight: 600; }
|
||||
tr:last-child td { border-bottom: none; }
|
||||
tr:hover td { background: #f1f5f9; }
|
||||
code { font-family: 'Consolas', 'Courier New', monospace; background: #e2e8f0; padding: 2px 6px; border-radius: 4px; font-size: 0.9em; direction: ltr; display: inline-block; }
|
||||
pre { background: var(--bg-code); color: #e2e8f0; padding: 16px; border-radius: 8px; direction: ltr; text-align: left; overflow-x: auto; font-family: 'Consolas', 'Courier New', monospace; font-size: 0.88em; line-height: 1.6; }
|
||||
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.78em; font-weight: bold; color: white; }
|
||||
.badge.new { background: var(--success); }
|
||||
.badge.mod { background: var(--warning); }
|
||||
.badge.sub { background: var(--secondary); }
|
||||
.commit { background: white; border: 1px solid var(--border); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
|
||||
.commit-head { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
|
||||
.commit-head .msg { font-weight: bold; color: var(--primary); font-size: 1.05em; }
|
||||
.commit-head .info { color: var(--text-muted); font-size: 0.85em; }
|
||||
.diffstat { color: var(--text-muted); font-size: 0.85em; }
|
||||
.diffstat .plus { color: var(--success); font-weight: bold; }
|
||||
.diffstat .minus { color: var(--danger); font-weight: bold; }
|
||||
ul { padding-right: 22px; margin: 8px 0; }
|
||||
li { margin-bottom: 6px; }
|
||||
.note { background: #fffbeb; border-right: 4px solid var(--accent); padding: 12px 16px; border-radius: 8px; margin-top: 12px; font-size: 0.92em; }
|
||||
.footer { background: var(--bg-light); border-top: 2px solid var(--border); padding: 18px 30px; text-align: center; color: var(--text-muted); font-size: 0.85em; }
|
||||
a { color: var(--secondary); text-decoration: none; }
|
||||
a:hover { text-decoration: underline; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
|
||||
<div class="header">
|
||||
<h1>گزارش تغییرات (ChangeLog)</h1>
|
||||
<div class="subtitle">یکشنبه ۳ آبان ۱۴۰۵ | 2026-10-25 | xSaherelmWorkspace</div>
|
||||
</div>
|
||||
|
||||
<div class="meta-bar">
|
||||
<div class="meta-item"><strong>نویسنده:</strong> Hadi Khazaee Asl</div>
|
||||
<div class="meta-item"><strong>برنچ:</strong> <code>master</code></div>
|
||||
<div class="meta-item"><strong>وضعیت:</strong> همه کامیتها به <code>origin/master</code> پوش شدهاند</div>
|
||||
<div class="meta-item"><strong>بازه زمانی:</strong> 17:23 تا 17:58 (+03:30)</div>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
|
||||
<!-- خلاصه -->
|
||||
<div class="section">
|
||||
<h2>خلاصه</h2>
|
||||
<div class="stats">
|
||||
<div class="stat-card"><div class="value">2</div><div class="label">مخزن تغییریافته</div></div>
|
||||
<div class="stat-card"><div class="value">4</div><div class="label">کامیت پوششده</div></div>
|
||||
<div class="stat-card"><div class="value">7</div><div class="label">فایل جدید</div></div>
|
||||
<div class="stat-card"><div class="value">16</div><div class="label">فایل تغییریافته (کل)</div></div>
|
||||
<div class="stat-card add"><div class="value">+1,454</div><div class="label">خط اضافهشده</div></div>
|
||||
<div class="stat-card del"><div class="value">-9</div><div class="label">خط حذفشده</div></div>
|
||||
</div>
|
||||
<p>
|
||||
محور اصلی کارهای امروز، پیادهسازی زیرساخت <strong>Chat With Documents</strong> در پروژه
|
||||
<code>xAiApi</code> بود: افزودن سرویس <strong>تکهبندی متن (TextChunker)</strong> و
|
||||
<strong>مخزن برداری درونحافظهای (In-Memory Vector Store)</strong> بههمراه ریفکتور ثبت سرویسها در DI.
|
||||
در مخزن اصلی ورکاسپیس نیز یادداشت طرح (<code>tmp.md</code> / <code>tmp.html</code>) و پوینتر سابماژول <code>xAiApi</code> بهروزرسانی شد.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- مخزن اصلی -->
|
||||
<div class="section">
|
||||
<h2>۱. مخزن اصلی: xSaherelmWorkspace</h2>
|
||||
<p>ریموت: <a href="https://git.saherelm.ir/saherelm/xSaherelmWorkspace.git">git.saherelm.ir/saherelm/xSaherelmWorkspace.git</a></p>
|
||||
|
||||
<div class="commit">
|
||||
<div class="commit-head">
|
||||
<span class="msg">last works ...</span>
|
||||
<span class="info"><code>2c991e7</code> | 2026-10-25 17:23:25</span>
|
||||
</div>
|
||||
<div class="diffstat">3 فایل | <span class="plus">+419</span> / <span class="minus">-1</span></div>
|
||||
<table>
|
||||
<thead><tr><th>نوع</th><th>فایل</th><th>تغییر</th><th>توضیح</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td><span class="badge new">جدید</span></td><td><code>Documents/Markdown/tmp.md</code></td><td>+24</td><td>طرح نهایی «Chat With Documents» (SessionId بهصورت Guid، جریان Ingest → Ask، TTL، TopK/MinScore)</td></tr>
|
||||
<tr><td><span class="badge new">جدید</span></td><td><code>Documents/Markdown/tmp.html</code></td><td>+394</td><td>نسخه HTML همان طرح</td></tr>
|
||||
<tr><td><span class="badge sub">سابماژول</span></td><td><code>xAiApi</code></td><td>+1 / -1</td><td>پوینتر از <code>4b857de</code> به <code>429b97c</code></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="commit">
|
||||
<div class="commit-head">
|
||||
<span class="msg">last ...</span>
|
||||
<span class="info"><code>43f5cc0</code> | 2026-10-25 17:58:14</span>
|
||||
</div>
|
||||
<div class="diffstat">1 فایل | <span class="plus">+1</span> / <span class="minus">-1</span></div>
|
||||
<table>
|
||||
<thead><tr><th>نوع</th><th>فایل</th><th>تغییر</th><th>توضیح</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td><span class="badge sub">سابماژول</span></td><td><code>xAiApi</code></td><td>+1 / -1</td><td>پوینتر از <code>429b97c</code> به <code>47d8a19</code></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- xAiApi -->
|
||||
<div class="section">
|
||||
<h2>۲. سابماژول: xAiApi</h2>
|
||||
<p>ریموت: <a href="https://git.saherelm.ir/saherelm/xSaherElmAiApi.git">git.saherelm.ir/saherelm/xSaherElmAiApi.git</a></p>
|
||||
|
||||
<div class="commit">
|
||||
<div class="commit-head">
|
||||
<span class="msg">add TextChunker Service for AI Project ...</span>
|
||||
<span class="info"><code>429b97c</code> | 2026-10-25 17:23:03</span>
|
||||
</div>
|
||||
<div class="diffstat">9 فایل | <span class="plus">+760</span> / <span class="minus">-6</span></div>
|
||||
<table>
|
||||
<thead><tr><th>نوع</th><th>فایل</th><th>تغییر</th><th>توضیح</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td><span class="badge new">جدید</span></td><td><code>Interfaces/IXTextChunker.cs</code></td><td>+32</td><td>قرارداد سرویس تکهبندی: <code>ChunkText(text, source)</code> و <code>ChunkTexts(text)</code></td></tr>
|
||||
<tr><td><span class="badge new">جدید</span></td><td><code>Providers/XTextChunker.cs</code></td><td>+588</td><td>پیادهسازی تکهبندی متن با ChunkSize/Overlap، نرمالسازی فاصلهها و ادغام تکههای کوچک</td></tr>
|
||||
<tr><td><span class="badge new">جدید</span></td><td><code>Models/XTextChunk.cs</code></td><td>+38</td><td>مدل خروجی تکه: <code>Index</code>, <code>Text</code>, <code>Source</code>, <code>Identifier</code> (مثل <code>file.pdf#3</code>), <code>StartOffset</code>, <code>Length</code></td></tr>
|
||||
<tr><td><span class="badge new">جدید</span></td><td><code>Models/XTextChunkerDescriptor.cs</code></td><td>+33</td><td>تنظیمات: <code>ChunkSize=800</code>, <code>ChunkOverlap=150</code>, <code>MinChunkSize=50</code>, <code>ChunkIdentifierSeparator="#"</code>, <code>NormalizeWhitespace=true</code></td></tr>
|
||||
<tr><td><span class="badge mod">تغییر</span></td><td><code>Configurations/XAiApiConfiguration.cs</code></td><td>+5</td><td>افزودن پراپرتی <code>TextChunker</code> از نوع <code>XTextChunkerDescriptor</code></td></tr>
|
||||
<tr><td><span class="badge mod">تغییر</span></td><td><code>DI/XDIHelperExtension.cs</code></td><td>+29</td><td>افزودن <code>AddXAiServices()</code> (انتقال ثبت سرویسهای AI از Startup) و <code>AddXAiTextChunker()</code> (Singleton)</td></tr>
|
||||
<tr><td><span class="badge mod">تغییر</span></td><td><code>Extensions/XModelsExtensions.cs</code></td><td>+21 / -1</td><td>افزودن <code>IsValid(this XTextChunkerDescriptor)</code> برای اعتبارسنجی تنظیمات</td></tr>
|
||||
<tr><td><span class="badge mod">تغییر</span></td><td><code>Startup.cs</code></td><td>+6 / -4</td><td>جایگزینی ثبت مستقیم سرویسها با <code>AddXAiTextChunker()</code> و <code>AddXAiServices()</code></td></tr>
|
||||
<tr><td><span class="badge mod">تغییر</span></td><td><code>appsettings.Development.json</code></td><td>+8 / -1</td><td>افزودن بخش <code>TextChunker</code> به پیکربندی</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<pre>"TextChunker": {
|
||||
"ChunkSize": 800,
|
||||
"ChunkOverlap": 150,
|
||||
"MinChunkSize": 50,
|
||||
"NormalizeWhitespace": true,
|
||||
"ChunkIdentifierSeparator": "#"
|
||||
}</pre>
|
||||
</div>
|
||||
|
||||
<div class="commit">
|
||||
<div class="commit-head">
|
||||
<span class="msg">last ...</span>
|
||||
<span class="info"><code>47d8a19</code> | 2026-10-25 17:58:05</span>
|
||||
</div>
|
||||
<div class="diffstat">5 فایل | <span class="plus">+275</span> / <span class="minus">-2</span></div>
|
||||
<table>
|
||||
<thead><tr><th>نوع</th><th>فایل</th><th>تغییر</th><th>توضیح</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td><span class="badge new">جدید</span></td><td><code>Interfaces/IXInMemoryVectorStore.cs</code></td><td>+48</td><td>قرارداد مخزن برداری: <code>CreateSession</code>, <code>Replace</code>, <code>Add</code>, <code>Search(sessionId, queryEmbedding, topK, minScore)</code>, <code>TryGet</code>, <code>Remove</code>, <code>RemoveExpired</code>, <code>Count</code></td></tr>
|
||||
<tr><td><span class="badge new">جدید</span></td><td><code>Providers/XInMemoryVectorStore.cs</code></td><td>+197</td><td>پیادهسازی Singleton درونحافظهای مبتنی بر Session (Guid)، پشتیبانی از TTL و بررسی <code>OwnerId</code></td></tr>
|
||||
<tr><td><span class="badge new">جدید</span></td><td><code>Models/XAiDocumentSession.cs</code></td><td>+18</td><td>مدل Session: <code>Id</code>, <code>Ttl</code>, <code>OwnerId</code>, <code>CreatedAtUtc</code>, <code>LastAccessAtUtc</code>, <code>Vectors</code>, <code>IsExpired()</code></td></tr>
|
||||
<tr><td><span class="badge mod">تغییر</span></td><td><code>DI/XDIHelperExtension.cs</code></td><td>+8</td><td>افزودن <code>AddXAiInMemoryVectorStore()</code></td></tr>
|
||||
<tr><td><span class="badge mod">تغییر</span></td><td><code>Startup.cs</code></td><td>+4 / -2</td><td>فراخوانی <code>AddXAiInMemoryVectorStore()</code> و حذف usingهای بلااستفاده</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<h3>نکات فنی</h3>
|
||||
<ul>
|
||||
<li>هر دو سرویس <code>XTextChunker</code> و <code>XInMemoryVectorStore</code> بهصورت <strong>Singleton</strong> ثبت شدهاند (Stateless / حافظه مشترک).</li>
|
||||
<li>دادههای Vector Store فقط در حافظه نگهداری میشوند و با انقضای TTL یا حذف Session پاک میشوند؛ چیزی در دیتابیس یا دیسک نوشته نمیشود.</li>
|
||||
<li>ثبت سرویسهای <code>IXDefaultAiService</code>, <code>IXDefaultEmbeddingService</code>, <code>IXDefaultThinkingAiService</code> از <code>Startup.cs</code> به متد <code>AddXAiServices()</code> منتقل شد.</li>
|
||||
</ul>
|
||||
<div class="note">
|
||||
<strong>کارهای باقیمانده طبق طرح (tmp.md):</strong> افزودن <code>AskWithContextAsync</code> به <code>IXAiServiceBase</code>،
|
||||
بازنویسی <code>ChatWithDocumentsController</code> (Endpointهای Ingest / Ask / AskStream / Session)،
|
||||
ثوابت پرامپت در <code>XAiApiConstants</code>، و یونیتتستهای <code>XTextChunker</code> و <code>XInMemoryVectorStore.Search</code> در <code>xFrameworkTest</code>.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- بدون تغییر -->
|
||||
<div class="section">
|
||||
<h2>۳. مخازن بدون تغییر</h2>
|
||||
<p>در ۳۲ سابماژول زیر امروز هیچ کامیتی ثبت نشده است:</p>
|
||||
<ul>
|
||||
<li><strong>Modules (۲۸ مورد):</strong> xAiModels, xAiService, xApiSDKHolder, xCategoryService, xCommons, xContentService, xDataService, xEventService, xExceptions, xFileService, xFrameworkComponentsHolder, xFrameworkCoreHolder, xFrameworkIdentitySDKHolder, xFrameworkPushServiceHolder, xFrameworkServicesHolder, xHttpService, xIdentityHelper, xIdentityModels, xIdentityService, xMessageService, xModels, xPushService, xServices, xStorageService, xStringService, xTagService, xTermsAndConditionsService, xWebinarService</li>
|
||||
<li><strong>Applications (۴ مورد):</strong> xApi, xClient, xIds, xFrameworkTest</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- دستورات -->
|
||||
<div class="section">
|
||||
<h2>۴. دستورات استفادهشده برای استخراج لاگ</h2>
|
||||
<pre>git log --since="2026-10-25 00:00" --until="2026-10-26 00:00" --stat --date=iso
|
||||
git -C xAiApi log --since="2026-10-25 00:00" --stat --date=iso
|
||||
git status -sb # master...origin/master (in sync)</pre>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
تولیدشده در تاریخ ۱۴۰۵/۰۸/۰۳ (2026-10-25) | فن آوران ساحر علم
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
===============================================================================
|
||||
Commit Messages - xSaherelmWorkspace
|
||||
تاریخ: یکشنبه ۱۴۰۵/۰۸/۰۳ (2026-10-25)
|
||||
نویسنده: Hadi Khazaee Asl
|
||||
گزارش کامل: Documents/Docs/ChangeLogs/1405-08-03-uncommitted.html
|
||||
===============================================================================
|
||||
|
||||
ترتیب کامیت: ابتدا سابماژول xAiApi، سپس مخزن اصلی (برای بهروزرسانی پوینتر سابماژول).
|
||||
توجه: پیش از کامیت، مقدار "DefaultMinScore": "0.35f" در xAiApi/appsettings.Development.json
|
||||
باید به 0.35 (عدد) اصلاح شود.
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
[1] xAiApi (https://git.saherelm.ir/saherelm/xSaherElmAiApi.git) - 1405/08/03
|
||||
-------------------------------------------------------------------------------
|
||||
Implement Chat With Documents (In-Memory RAG) ...
|
||||
|
||||
- Add XAiDocumentModels (IngestResult, AskRequest, Answer, AnswerChunk, Source, SessionInfo, RAGDescriptor DTOs);
|
||||
- Add AskWithContextAsync and AskWithContextAsEnumerable (Context Actions) to IXAiServiceBase and XAIServiceBase;
|
||||
- Add GetContextHistory and BuildContextBlock Helpers for Building RAG Chat History without Persisting;
|
||||
- Rewrite ChatWithDocumentsController with Ingest, Ask, AskStream (SSE), Get Session and Delete Session Endpoints;
|
||||
- Add XInMemoryVectorStoreCleanupService (BackgroundService) for Removing Expired Sessions Periodically;
|
||||
- Add AddXAiChatWithDocuments DI Extension, Register Cleanup HostedService and use it in Startup;
|
||||
- Add RAGDescriptor Property to XAiApiConfiguration and its Section to appsettings.Development.json;
|
||||
- Add ChatWithDocuments System Prompt to Prompts in appsettings.Development.json;
|
||||
- Add IsValid Extension Method for XAiDocumentAskRequest;
|
||||
- Optimize XInMemoryVectorStore.Search (Query Embedding Converted once) and Refactor Formatting;
|
||||
- Remove Unused Usings in XAIServiceBase and IXAiServiceBase;
|
||||
|
||||
Files:
|
||||
A Models/XAiDocumentModels.cs
|
||||
A Providers/XInMemoryVectorStoreCleanupService.cs
|
||||
M Controllers/ChatWithDocumentsController.cs
|
||||
M Providers/XAIServiceBase.cs
|
||||
M Interfaces/IXAiServiceBase.cs
|
||||
M Providers/XInMemoryVectorStore.cs
|
||||
M Extensions/XModelsExtensions.cs
|
||||
M DI/XDIHelperExtension.cs
|
||||
M Configurations/XAiApiConfiguration.cs
|
||||
M Startup.cs
|
||||
M appsettings.Development.json
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
[2] xSaherelmWorkspace (https://git.saherelm.ir/saherelm/xSaherelmWorkspace.git) - 1405/08/03
|
||||
-------------------------------------------------------------------------------
|
||||
Update xAiApi Submodule (Chat With Documents) and Add ChangeLog / Plan Documents ...
|
||||
|
||||
- Update xAiApi Submodule Pointer to Chat With Documents (In-Memory RAG) Implementation;
|
||||
- Add Documents/Docs/ChangeLogs/1405-08-03.html (ChangeLog of Pushed Commits);
|
||||
- Add Documents/Docs/ChangeLogs/1405-08-03-uncommitted.html (ChangeLog of this Commit);
|
||||
- Add Documents/Docs/ChangeLogs/CommitMessage-1405-08-03.txt;
|
||||
- Add Documents/Markdown/plan1.md and plan1.html (Chat With Documents Implementation Plan);
|
||||
|
||||
Files:
|
||||
M xAiApi
|
||||
A Documents/Docs/ChangeLogs/1405-08-03.html
|
||||
A Documents/Docs/ChangeLogs/1405-08-03-uncommitted.html
|
||||
A Documents/Docs/ChangeLogs/CommitMessage-1405-08-03.txt
|
||||
A Documents/Markdown/plan1.md
|
||||
A Documents/Markdown/plan1.html
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
دستورات پیشنهادی
|
||||
-------------------------------------------------------------------------------
|
||||
# 1) xAiApi
|
||||
cd xAiApi
|
||||
git add -A
|
||||
git commit -m "Implement Chat With Documents (In-Memory RAG) ..." -m "- Add XAiDocumentModels (IngestResult, AskRequest, Answer, AnswerChunk, Source, SessionInfo, RAGDescriptor DTOs);
|
||||
- Add AskWithContextAsync and AskWithContextAsEnumerable (Context Actions) to IXAiServiceBase and XAIServiceBase;
|
||||
- Add GetContextHistory and BuildContextBlock Helpers for Building RAG Chat History without Persisting;
|
||||
- Rewrite ChatWithDocumentsController with Ingest, Ask, AskStream (SSE), Get Session and Delete Session Endpoints;
|
||||
- Add XInMemoryVectorStoreCleanupService (BackgroundService) for Removing Expired Sessions Periodically;
|
||||
- Add AddXAiChatWithDocuments DI Extension, Register Cleanup HostedService and use it in Startup;
|
||||
- Add RAGDescriptor Property to XAiApiConfiguration and its Section to appsettings.Development.json;
|
||||
- Add ChatWithDocuments System Prompt to Prompts in appsettings.Development.json;
|
||||
- Add IsValid Extension Method for XAiDocumentAskRequest;
|
||||
- Optimize XInMemoryVectorStore.Search (Query Embedding Converted once) and Refactor Formatting;
|
||||
- Remove Unused Usings in XAIServiceBase and IXAiServiceBase;"
|
||||
git push origin master
|
||||
cd ..
|
||||
|
||||
# 2) xSaherelmWorkspace
|
||||
git add xAiApi Documents/Docs/ChangeLogs Documents/Markdown/plan1.md Documents/Markdown/plan1.html
|
||||
git commit -m "Update xAiApi Submodule (Chat With Documents) and Add ChangeLog / Plan Documents ..." -m "- Update xAiApi Submodule Pointer to Chat With Documents (In-Memory RAG) Implementation;
|
||||
- Add Documents/Docs/ChangeLogs/1405-08-03.html (ChangeLog of Pushed Commits);
|
||||
- Add Documents/Docs/ChangeLogs/1405-08-03-uncommitted.html (ChangeLog of this Commit);
|
||||
- Add Documents/Docs/ChangeLogs/CommitMessage-1405-08-03.txt;
|
||||
- Add Documents/Markdown/plan1.md and plan1.html (Chat With Documents Implementation Plan);"
|
||||
git push origin master
|
||||
@@ -0,0 +1,487 @@
|
||||
<!DOCTYPE html>
|
||||
<html dir="rtl">
|
||||
<head>
|
||||
<title>plan1.md</title>
|
||||
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
|
||||
|
||||
<style>
|
||||
/* https://github.com/microsoft/vscode/blob/master/extensions/markdown-language-features/media/markdown.css */
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
body {
|
||||
font-family: var(--vscode-markdown-font-family, -apple-system, BlinkMacSystemFont, "Segoe WPC", "Segoe UI", "Ubuntu", "Droid Sans", sans-serif);
|
||||
font-size: var(--vscode-markdown-font-size, 14px);
|
||||
padding: 0 26px;
|
||||
line-height: var(--vscode-markdown-line-height, 22px);
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
#code-csp-warning {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
color: white;
|
||||
margin: 16px;
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
font-family: sans-serif;
|
||||
background-color:#444444;
|
||||
cursor: pointer;
|
||||
padding: 6px;
|
||||
box-shadow: 1px 1px 1px rgba(0,0,0,.25);
|
||||
}
|
||||
|
||||
#code-csp-warning:hover {
|
||||
text-decoration: none;
|
||||
background-color:#007acc;
|
||||
box-shadow: 2px 2px 2px rgba(0,0,0,.25);
|
||||
}
|
||||
|
||||
body.scrollBeyondLastLine {
|
||||
margin-bottom: calc(100vh - 22px);
|
||||
}
|
||||
|
||||
body.showEditorSelection .code-line {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
body.showEditorSelection .code-active-line:before,
|
||||
body.showEditorSelection .code-line:hover:before {
|
||||
content: "";
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: -12px;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body.showEditorSelection li.code-active-line:before,
|
||||
body.showEditorSelection li.code-line:hover:before {
|
||||
left: -30px;
|
||||
}
|
||||
|
||||
.vscode-light.showEditorSelection .code-active-line:before {
|
||||
border-left: 3px solid rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.vscode-light.showEditorSelection .code-line:hover:before {
|
||||
border-left: 3px solid rgba(0, 0, 0, 0.40);
|
||||
}
|
||||
|
||||
.vscode-light.showEditorSelection .code-line .code-line:hover:before {
|
||||
border-left: none;
|
||||
}
|
||||
|
||||
.vscode-dark.showEditorSelection .code-active-line:before {
|
||||
border-left: 3px solid rgba(255, 255, 255, 0.4);
|
||||
}
|
||||
|
||||
.vscode-dark.showEditorSelection .code-line:hover:before {
|
||||
border-left: 3px solid rgba(255, 255, 255, 0.60);
|
||||
}
|
||||
|
||||
.vscode-dark.showEditorSelection .code-line .code-line:hover:before {
|
||||
border-left: none;
|
||||
}
|
||||
|
||||
.vscode-high-contrast.showEditorSelection .code-active-line:before {
|
||||
border-left: 3px solid rgba(255, 160, 0, 0.7);
|
||||
}
|
||||
|
||||
.vscode-high-contrast.showEditorSelection .code-line:hover:before {
|
||||
border-left: 3px solid rgba(255, 160, 0, 1);
|
||||
}
|
||||
|
||||
.vscode-high-contrast.showEditorSelection .code-line .code-line:hover:before {
|
||||
border-left: none;
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
a:focus,
|
||||
input:focus,
|
||||
select:focus,
|
||||
textarea:focus {
|
||||
outline: 1px solid -webkit-focus-ring-color;
|
||||
outline-offset: -1px;
|
||||
}
|
||||
|
||||
hr {
|
||||
border: 0;
|
||||
height: 2px;
|
||||
border-bottom: 2px solid;
|
||||
}
|
||||
|
||||
h1 {
|
||||
padding-bottom: 0.3em;
|
||||
line-height: 1.2;
|
||||
border-bottom-width: 1px;
|
||||
border-bottom-style: solid;
|
||||
}
|
||||
|
||||
h1, h2, h3 {
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
table > thead > tr > th {
|
||||
text-align: left;
|
||||
border-bottom: 1px solid;
|
||||
}
|
||||
|
||||
table > thead > tr > th,
|
||||
table > thead > tr > td,
|
||||
table > tbody > tr > th,
|
||||
table > tbody > tr > td {
|
||||
padding: 5px 10px;
|
||||
}
|
||||
|
||||
table > tbody > tr + tr > td {
|
||||
border-top: 1px solid;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
margin: 0 7px 0 5px;
|
||||
padding: 0 16px 0 10px;
|
||||
border-left-width: 5px;
|
||||
border-left-style: solid;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: Menlo, Monaco, Consolas, "Droid Sans Mono", "Courier New", monospace, "Droid Sans Fallback";
|
||||
font-size: 1em;
|
||||
line-height: 1.357em;
|
||||
}
|
||||
|
||||
body.wordWrap pre {
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
pre:not(.hljs),
|
||||
pre.hljs code > div {
|
||||
padding: 16px;
|
||||
border-radius: 3px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
pre code {
|
||||
color: var(--vscode-editor-foreground);
|
||||
tab-size: 4;
|
||||
}
|
||||
|
||||
/** Theming */
|
||||
|
||||
.vscode-light pre {
|
||||
background-color: rgba(220, 220, 220, 0.4);
|
||||
}
|
||||
|
||||
.vscode-dark pre {
|
||||
background-color: rgba(10, 10, 10, 0.4);
|
||||
}
|
||||
|
||||
.vscode-high-contrast pre {
|
||||
background-color: rgb(0, 0, 0);
|
||||
}
|
||||
|
||||
.vscode-high-contrast h1 {
|
||||
border-color: rgb(0, 0, 0);
|
||||
}
|
||||
|
||||
.vscode-light table > thead > tr > th {
|
||||
border-color: rgba(0, 0, 0, 0.69);
|
||||
}
|
||||
|
||||
.vscode-dark table > thead > tr > th {
|
||||
border-color: rgba(255, 255, 255, 0.69);
|
||||
}
|
||||
|
||||
.vscode-light h1,
|
||||
.vscode-light hr,
|
||||
.vscode-light table > tbody > tr + tr > td {
|
||||
border-color: rgba(0, 0, 0, 0.18);
|
||||
}
|
||||
|
||||
.vscode-dark h1,
|
||||
.vscode-dark hr,
|
||||
.vscode-dark table > tbody > tr + tr > td {
|
||||
border-color: rgba(255, 255, 255, 0.18);
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<style>
|
||||
/* Tomorrow Theme */
|
||||
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
|
||||
/* Original theme - https://github.com/chriskempson/tomorrow-theme */
|
||||
|
||||
/* Tomorrow Comment */
|
||||
.hljs-comment,
|
||||
.hljs-quote {
|
||||
color: #8e908c;
|
||||
}
|
||||
|
||||
/* Tomorrow Red */
|
||||
.hljs-variable,
|
||||
.hljs-template-variable,
|
||||
.hljs-tag,
|
||||
.hljs-name,
|
||||
.hljs-selector-id,
|
||||
.hljs-selector-class,
|
||||
.hljs-regexp,
|
||||
.hljs-deletion {
|
||||
color: #c82829;
|
||||
}
|
||||
|
||||
/* Tomorrow Orange */
|
||||
.hljs-number,
|
||||
.hljs-built_in,
|
||||
.hljs-builtin-name,
|
||||
.hljs-literal,
|
||||
.hljs-type,
|
||||
.hljs-params,
|
||||
.hljs-meta,
|
||||
.hljs-link {
|
||||
color: #f5871f;
|
||||
}
|
||||
|
||||
/* Tomorrow Yellow */
|
||||
.hljs-attribute {
|
||||
color: #eab700;
|
||||
}
|
||||
|
||||
/* Tomorrow Green */
|
||||
.hljs-string,
|
||||
.hljs-symbol,
|
||||
.hljs-bullet,
|
||||
.hljs-addition {
|
||||
color: #718c00;
|
||||
}
|
||||
|
||||
/* Tomorrow Blue */
|
||||
.hljs-title,
|
||||
.hljs-section {
|
||||
color: #4271ae;
|
||||
}
|
||||
|
||||
/* Tomorrow Purple */
|
||||
.hljs-keyword,
|
||||
.hljs-selector-tag {
|
||||
color: #8959a8;
|
||||
}
|
||||
|
||||
.hljs {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
color: #4d4d4c;
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
.hljs-emphasis {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.hljs-strong {
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
|
||||
<style>
|
||||
/*
|
||||
* Markdown PDF CSS
|
||||
*/
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe WPC", "Segoe UI", "Ubuntu", "Droid Sans", sans-serif, "Meiryo";
|
||||
padding: 0 12px;
|
||||
}
|
||||
|
||||
pre {
|
||||
background-color: #f8f8f8;
|
||||
border: 1px solid #cccccc;
|
||||
border-radius: 3px;
|
||||
overflow-x: auto;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
pre:not(.hljs) {
|
||||
padding: 23px;
|
||||
line-height: 19px;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
background: rgba(127, 127, 127, 0.1);
|
||||
border-color: rgba(0, 122, 204, 0.5);
|
||||
}
|
||||
|
||||
.emoji {
|
||||
height: 1.4em;
|
||||
}
|
||||
|
||||
code {
|
||||
font-size: 14px;
|
||||
line-height: 19px;
|
||||
}
|
||||
|
||||
/* for inline code */
|
||||
:not(pre):not(.hljs) > code {
|
||||
color: #C9AE75; /* Change the old color so it seems less like an error */
|
||||
font-size: inherit;
|
||||
}
|
||||
|
||||
/* Page Break : use <div class="page"/> or <div class="page"></div> to insert page break
|
||||
-------------------------------------------------------- */
|
||||
.page {
|
||||
page-break-after: always;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
mermaid.initialize({
|
||||
startOnLoad: true,
|
||||
theme: document.body.classList.contains('vscode-dark') || document.body.classList.contains('vscode-high-contrast')
|
||||
? 'dark'
|
||||
: 'default'
|
||||
});
|
||||
</script>
|
||||
<p><code>xFrameworkTest</code> یک پروژه Cordova/JS است، نه پروژه تست .NET — بنابراین یونیتتست C# جایی برای قرارگیری ندارد (در برنامه لحاظ میکنم).</p>
|
||||
<h2 id="وضعیت-فعلی-آنچه-انجام-شده">وضعیت فعلی (آنچه انجام شده)</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>مؤلفه</th>
|
||||
<th>وضعیت</th>
|
||||
<th>محل</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code>IXTextChunker</code> / <code>XTextChunker</code></td>
|
||||
<td>انجام شده، در DI ثبت شده</td>
|
||||
<td><code>xAiApi\Providers\XTextChunker.cs</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>XTextChunk</code>, <code>XTextChunkerDescriptor</code> + <code>IsValid()</code> + کانفیگ <code>TextChunker</code></td>
|
||||
<td>انجام شده</td>
|
||||
<td><code>Models\</code>, <code>Extensions\XModelsExtensions.cs:51</code>, <code>appsettings.Development.json</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>IXInMemoryVectorStore</code> / <code>XInMemoryVectorStore</code> / <code>XAiDocumentSession</code></td>
|
||||
<td>انجام شده، در DI ثبت شده (TTL پیشفرض ۳۰ دقیقه، OwnerId، CosineSimilarity)</td>
|
||||
<td><code>xAiApi\Providers\XInMemoryVectorStore.cs</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>ChatWithDocumentsController</code></td>
|
||||
<td><strong>اسکلت خالی</strong> — هنوز <code>IList<XAiVectorDto> vectorStore</code> محلی دارد، <code>using Microsoft.AspNetCore.Components</code> اشتباه (باید <code>Mvc</code> باشد)، هیچ Endpoint ندارد، <code>IXInMemoryVectorStore</code>/<code>IXTextChunker</code> تزریق نشده</td>
|
||||
<td><code>xAiApi\Controllers\ChatWithDocumentsController.cs:6,30</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>AskWithContextAsync</code> در <code>IXAiServiceBase</code></td>
|
||||
<td><strong>انجام نشده</strong></td>
|
||||
<td>—</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>پرامپت <code>ChatWithDocuments</code> در appsettings + ثابتها</td>
|
||||
<td><strong>انجام نشده</strong> (فقط Introduction/ContentExtraction/Embedding وجود دارد)</td>
|
||||
<td><code>Constants\XAiApiConstants.cs:14-22</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>مدلهای Request/Response</td>
|
||||
<td><strong>انجام نشده</strong></td>
|
||||
<td>—</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>ثبت <code>RemoveExpired</code> دورهای</td>
|
||||
<td><strong>انجام نشده</strong> (فقط lazy داخل <code>Count</code>/<code>TryGet</code>)</td>
|
||||
<td>—</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h2 id="گامهای-باقیمانده">گامهای باقیمانده</h2>
|
||||
<h3 id="گام-۱--ثوابت-و-پرامپت">گام ۱ — ثوابت و پرامپت</h3>
|
||||
<ul>
|
||||
<li><code>xAiApi\Constants\XAiApiConstants.cs</code>: افزودن
|
||||
<code>XAiApiChatWithDocumentsPromptName = "ChatWithDocuments"</code>, <code>XAiDocumentDefaultTopK = 5</code>, <code>XAiDocumentDefaultMinScore = 0.35f</code>, <code>XAiDocumentDefaultTtlMinutes = 30</code>, کلیدهای Metadata (<code>fileName</code>, <code>mimeType</code>, <code>chunkIndex</code>).</li>
|
||||
<li><code>appsettings.Development.json</code> و <code>appsettings.json</code>: افزودن پرامپت <code>ChatWithDocuments</code> به آرایه <code>Prompts</code> (دستور پاسخدهی فقط بر اساس Context، ذکر منبع، و اعلام «در اسناد یافت نشد»). پرامپت باید placeholder برای Context داشته باشد یا Context بهصورت پیام جداگانه System ارسال شود (پیشنهاد: پیام جدا، سادهتر).</li>
|
||||
</ul>
|
||||
<h3 id="گام-۲--مدلهای-dto-پوشه-xaiapimodels">گام ۲ — مدلهای DTO (پوشه <code>xAiApi\Models\</code>)</h3>
|
||||
<ul>
|
||||
<li><code>XAiDocumentIngestResult</code> — <code>SessionId</code>, <code>FilesCount</code>, <code>ChunksCount</code>, <code>SkippedFiles[]</code>, <code>ExpiresAtUtc</code></li>
|
||||
<li><code>XAiDocumentAskRequest</code> — <code>SessionId</code>, <code>Prompt</code>, <code>TopK?</code>, <code>MinScore?</code> + متد <code>IsValid()</code> در <code>XModelsExtensions</code></li>
|
||||
<li><code>XAiDocumentAnswer</code> — <code>Answer</code>, <code>NoContextFound</code>, <code>Sources: IList<XAiDocumentSource></code> (<code>Identifier</code>, <code>FileName</code>, <code>ChunkIndex</code>, <code>Score</code>, <code>Snippet</code>)</li>
|
||||
<li><code>XAiDocumentSessionInfo</code> — خروجی <code>GET Session/{id}</code> بدون Embeddingها (<code>Id</code>, <code>CreatedAtUtc</code>, <code>LastAccessAtUtc</code>, <code>Ttl</code>, <code>VectorsCount</code>, فهرست فایلها)</li>
|
||||
</ul>
|
||||
<h3 id="گام-۳--سرویس-پایه-askwithcontextasync--askwithcontextasenumerable">گام ۳ — سرویس پایه: <code>AskWithContextAsync</code> / <code>AskWithContextAsEnumerable</code></h3>
|
||||
<ul>
|
||||
<li><code>Interfaces\IXAiServiceBase.cs</code>: افزودن region جدید «Context Actions» با دو امضا:
|
||||
<code>Task<string> AskWithContextAsync(string prompt, IEnumerable<XAiVectorSearchResult> context, CancellationToken)</code> و نسخه <code>IAsyncEnumerable<string></code>.</li>
|
||||
<li><code>Providers\XAIServiceBase.cs</code>: پیادهسازی مشابه <code>AskTextAsync</code> (:97) ولی History =
|
||||
<code>[System: Introduction] + [System: ChatWithDocuments-Prompt + Context متنی (هر chunk با شماره و Identifier)] + [User: prompt]</code>.
|
||||
<strong>بدون</strong> هیچ تماسی با <code>dataProvider</code> (ذخیره در DB نمیشود). متد کمکی private <code>BuildContextBlock(IEnumerable<XAiVectorSearchResult>)</code>.</li>
|
||||
</ul>
|
||||
<h3 id="گام-۴--بازنویسی-chatwithdocumentscontroller">گام ۴ — بازنویسی <code>ChatWithDocumentsController</code></h3>
|
||||
<ul>
|
||||
<li>اصلاح <code>using Microsoft.AspNetCore.Components</code> → <code>Microsoft.AspNetCore.Mvc</code>؛ حذف فیلد <code>vectorStore</code> و <code>IDisposable</code>.</li>
|
||||
<li>تزریق: <code>IXDefaultAiService</code>, <code>IXDefaultEmbeddingService</code>, <code>IXFileContentExtractor</code>, <code>IXTextChunker</code>, <code>IXInMemoryVectorStore</code>, <code>XAiApiConfiguration</code>.</li>
|
||||
<li>Endpointها (الگو از <code>XAiServiceControllerBase.cs:718-760</code> و SSE از <code>:655-710</code>):
|
||||
<ul>
|
||||
<li><code>POST Ingest</code> (<code>multipart/form-data</code>, <code>IFormFileCollection</code>, اختیاری <code>sessionId</code> برای افزودن به Session موجود): هر فایل → <code>CanExtract</code> → <code>ExtractRichAsync</code> → متن = <code>Text ?? AudioTranscript</code> → <code>textChunker.Chunk(text, fileName)</code> → <code>embeddingService.Embeddings(batch)</code> → ساخت <code>XAiVectorDto</code> با <code>Identifier = chunk.Identifier</code>, <code>Metadata{fileName, mimeType, chunkIndex}</code> → <code>vectorStore.CreateSession(vectors, ownerId)</code> یا <code>Add(...)</code> → بازگشت <code>XAiDocumentIngestResult</code>.</li>
|
||||
<li><code>POST Ask</code> (<code>[FromBody] XAiDocumentAskRequest</code>): <code>embeddingService.Embedding(prompt)</code> → <code>vectorStore.Search(sessionId, emb, topK, minScore, ownerId)</code> → اگر خالی: <code>{ NoContextFound = true }</code> → وگرنه <code>aiService.AskWithContextAsync</code> → <code>XAiDocumentAnswer</code> با Sources.</li>
|
||||
<li><code>POST AskStream</code>: همان جریان با <code>AskWithContextAsEnumerable</code> و SSE (کپی هدرها و <code>DisableBuffering</code> از کنترلر پایه).</li>
|
||||
<li><code>GET Session/{id}</code>: <code>TryGet</code> → <code>XAiDocumentSessionInfo</code> یا 404.</li>
|
||||
<li><code>DELETE Session/{id}</code>: <code>Remove</code> → 200/404.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>همه با <code>try/catch</code> + <code>GetExceptionActionResult(ex)</code> و <code>ownerId = (await GetUserInfo()).UserId</code> طبق الگوی موجود.</li>
|
||||
</ul>
|
||||
<h3 id="گام-۵--di-و-startup">گام ۵ — DI و Startup</h3>
|
||||
<ul>
|
||||
<li><code>DI\XDIHelperExtension.cs</code>: متد <code>AddXAiChatWithDocuments()</code> که <code>AddXAiTextChunker()</code> + <code>AddXAiInMemoryVectorStore()</code> را صدا میزند؛ <code>Startup.cs:191-196</code> به یک فراخوانی سادهتر تبدیل شود.</li>
|
||||
<li>(اختیاری) یک <code>BackgroundService</code>/<code>Timer</code> ساده برای <code>RemoveExpired()</code> هر ۵ دقیقه تا حافظه نشت نکند.</li>
|
||||
</ul>
|
||||
<h3 id="گام-۶--بهبودهای-کوچک-vector-store-اختیاری-ولی-توصیهشده">گام ۶ — بهبودهای کوچک Vector Store (اختیاری ولی توصیهشده)</h3>
|
||||
<ul>
|
||||
<li><code>XInMemoryVectorStore.cs:138-139</code>: <code>queryEmbedding.ToArray()</code> در هر iteration حلقه تکرار میشود → یکبار قبل از حلقه.</li>
|
||||
<li>محدودیت حداکثر تعداد Session / Vector برای جلوگیری از OOM (ثابت در Constants).</li>
|
||||
</ul>
|
||||
<h3 id="گام-۷--اعتبارسنجی">گام ۷ — اعتبارسنجی</h3>
|
||||
<ul>
|
||||
<li><code>dotnet build xAiApi\xAiApi.csproj</code></li>
|
||||
<li>تست دستی: <code>POST ChatWithDocuments/Ingest</code> با یک PDF → دریافت <code>SessionId</code> → <code>POST Ask</code> با سؤال مرتبط و نامرتبط (بررسی <code>NoContextFound</code>) → <code>AskStream</code> → <code>DELETE Session</code>.</li>
|
||||
<li><strong>یونیتتست:</strong> <code>xFrameworkTest</code> پروژه Cordova/JS است، نه .NET؛ پس یا تستها حذف شوند یا یک پروژه <code>xAiApi.Tests</code> (xUnit) جدید ساخته شود — نیاز به تصمیم شما.</li>
|
||||
</ul>
|
||||
<h3 id="گام-۸--مستندسازی">گام ۸ — مستندسازی</h3>
|
||||
<ul>
|
||||
<li>بهروزرسانی <code>Documents\Docs\ChangeLogs\1405-08-03.html</code> (یا ChangeLog روز بعد) و حذف فایلهای موقت <code>Documents\Markdown\tmp.md/tmp.html</code> یا انتقال به <code>Documents\Docs\Developer\17_ChatWithDocuments.html</code>.</li>
|
||||
</ul>
|
||||
<h2 id="نکات-تصمیمگیری">نکات تصمیمگیری</h2>
|
||||
<ol>
|
||||
<li><strong>Context در پرامپت یا پیام جدا؟</strong> پیشنهاد: پیام System جداگانه (بدون نیاز به placeholder).</li>
|
||||
<li><strong>Ingest روی Session موجود</strong> (<code>Add</code>) پشتیبانی شود یا هر Ingest، Session جدید بسازد؟ پیشنهاد: پارامتر اختیاری <code>sessionId</code>.</li>
|
||||
<li><strong>یونیتتست</strong>: ساخت پروژه <code>xAiApi.Tests</code> یا صرفنظر؟</li>
|
||||
</ol>
|
||||
<p>اگر طرح مورد تأیید است، گزینههای بالا را مشخص کنید و به <strong>Act mode</strong> سوئیچ کنید (toggle to Act mode) تا پیادهسازی را از گام ۱ شروع کنم.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,68 @@
|
||||
`xFrameworkTest` یک پروژه Cordova/JS است، نه پروژه تست .NET — بنابراین یونیتتست C# جایی برای قرارگیری ندارد (در برنامه لحاظ میکنم).
|
||||
|
||||
## وضعیت فعلی (آنچه انجام شده)
|
||||
|
||||
| مؤلفه | وضعیت | محل |
|
||||
|---|---|---|
|
||||
| `IXTextChunker` / `XTextChunker` | انجام شده، در DI ثبت شده | `xAiApi\Providers\XTextChunker.cs` |
|
||||
| `XTextChunk`, `XTextChunkerDescriptor` + `IsValid()` + کانفیگ `TextChunker` | انجام شده | `Models\`, `Extensions\XModelsExtensions.cs:51`, `appsettings.Development.json` |
|
||||
| `IXInMemoryVectorStore` / `XInMemoryVectorStore` / `XAiDocumentSession` | انجام شده، در DI ثبت شده (TTL پیشفرض ۳۰ دقیقه، OwnerId، CosineSimilarity) | `xAiApi\Providers\XInMemoryVectorStore.cs` |
|
||||
| `ChatWithDocumentsController` | **اسکلت خالی** — هنوز `IList<XAiVectorDto> vectorStore` محلی دارد، `using Microsoft.AspNetCore.Components` اشتباه (باید `Mvc` باشد)، هیچ Endpoint ندارد، `IXInMemoryVectorStore`/`IXTextChunker` تزریق نشده | `xAiApi\Controllers\ChatWithDocumentsController.cs:6,30` |
|
||||
| `AskWithContextAsync` در `IXAiServiceBase` | **انجام نشده** | — |
|
||||
| پرامپت `ChatWithDocuments` در appsettings + ثابتها | **انجام نشده** (فقط Introduction/ContentExtraction/Embedding وجود دارد) | `Constants\XAiApiConstants.cs:14-22` |
|
||||
| مدلهای Request/Response | **انجام نشده** | — |
|
||||
| ثبت `RemoveExpired` دورهای | **انجام نشده** (فقط lazy داخل `Count`/`TryGet`) | — |
|
||||
|
||||
## گامهای باقیمانده
|
||||
|
||||
### گام ۱ — ثوابت و پرامپت
|
||||
- `xAiApi\Constants\XAiApiConstants.cs`: افزودن
|
||||
`XAiApiChatWithDocumentsPromptName = "ChatWithDocuments"`, `XAiDocumentDefaultTopK = 5`, `XAiDocumentDefaultMinScore = 0.35f`, `XAiDocumentDefaultTtlMinutes = 30`, کلیدهای Metadata (`fileName`, `mimeType`, `chunkIndex`).
|
||||
- `appsettings.Development.json` و `appsettings.json`: افزودن پرامپت `ChatWithDocuments` به آرایه `Prompts` (دستور پاسخدهی فقط بر اساس Context، ذکر منبع، و اعلام «در اسناد یافت نشد»). پرامپت باید placeholder برای Context داشته باشد یا Context بهصورت پیام جداگانه System ارسال شود (پیشنهاد: پیام جدا، سادهتر).
|
||||
|
||||
### گام ۲ — مدلهای DTO (پوشه `xAiApi\Models\`)
|
||||
- `XAiDocumentIngestResult` — `SessionId`, `FilesCount`, `ChunksCount`, `SkippedFiles[]`, `ExpiresAtUtc`
|
||||
- `XAiDocumentAskRequest` — `SessionId`, `Prompt`, `TopK?`, `MinScore?` + متد `IsValid()` در `XModelsExtensions`
|
||||
- `XAiDocumentAnswer` — `Answer`, `NoContextFound`, `Sources: IList<XAiDocumentSource>` (`Identifier`, `FileName`, `ChunkIndex`, `Score`, `Snippet`)
|
||||
- `XAiDocumentSessionInfo` — خروجی `GET Session/{id}` بدون Embeddingها (`Id`, `CreatedAtUtc`, `LastAccessAtUtc`, `Ttl`, `VectorsCount`, فهرست فایلها)
|
||||
|
||||
### گام ۳ — سرویس پایه: `AskWithContextAsync` / `AskWithContextAsEnumerable`
|
||||
- `Interfaces\IXAiServiceBase.cs`: افزودن region جدید «Context Actions» با دو امضا:
|
||||
`Task<string> AskWithContextAsync(string prompt, IEnumerable<XAiVectorSearchResult> context, CancellationToken)` و نسخه `IAsyncEnumerable<string>`.
|
||||
- `Providers\XAIServiceBase.cs`: پیادهسازی مشابه `AskTextAsync` (:97) ولی History =
|
||||
`[System: Introduction] + [System: ChatWithDocuments-Prompt + Context متنی (هر chunk با شماره و Identifier)] + [User: prompt]`.
|
||||
**بدون** هیچ تماسی با `dataProvider` (ذخیره در DB نمیشود). متد کمکی private `BuildContextBlock(IEnumerable<XAiVectorSearchResult>)`.
|
||||
|
||||
### گام ۴ — بازنویسی `ChatWithDocumentsController`
|
||||
- اصلاح `using Microsoft.AspNetCore.Components` → `Microsoft.AspNetCore.Mvc`؛ حذف فیلد `vectorStore` و `IDisposable`.
|
||||
- تزریق: `IXDefaultAiService`, `IXDefaultEmbeddingService`, `IXFileContentExtractor`, `IXTextChunker`, `IXInMemoryVectorStore`, `XAiApiConfiguration`.
|
||||
- Endpointها (الگو از `XAiServiceControllerBase.cs:718-760` و SSE از `:655-710`):
|
||||
- `POST Ingest` (`multipart/form-data`, `IFormFileCollection`, اختیاری `sessionId` برای افزودن به Session موجود): هر فایل → `CanExtract` → `ExtractRichAsync` → متن = `Text ?? AudioTranscript` → `textChunker.Chunk(text, fileName)` → `embeddingService.Embeddings(batch)` → ساخت `XAiVectorDto` با `Identifier = chunk.Identifier`, `Metadata{fileName, mimeType, chunkIndex}` → `vectorStore.CreateSession(vectors, ownerId)` یا `Add(...)` → بازگشت `XAiDocumentIngestResult`.
|
||||
- `POST Ask` (`[FromBody] XAiDocumentAskRequest`): `embeddingService.Embedding(prompt)` → `vectorStore.Search(sessionId, emb, topK, minScore, ownerId)` → اگر خالی: `{ NoContextFound = true }` → وگرنه `aiService.AskWithContextAsync` → `XAiDocumentAnswer` با Sources.
|
||||
- `POST AskStream`: همان جریان با `AskWithContextAsEnumerable` و SSE (کپی هدرها و `DisableBuffering` از کنترلر پایه).
|
||||
- `GET Session/{id}`: `TryGet` → `XAiDocumentSessionInfo` یا 404.
|
||||
- `DELETE Session/{id}`: `Remove` → 200/404.
|
||||
- همه با `try/catch` + `GetExceptionActionResult(ex)` و `ownerId = (await GetUserInfo()).UserId` طبق الگوی موجود.
|
||||
|
||||
### گام ۵ — DI و Startup
|
||||
- `DI\XDIHelperExtension.cs`: متد `AddXAiChatWithDocuments()` که `AddXAiTextChunker()` + `AddXAiInMemoryVectorStore()` را صدا میزند؛ `Startup.cs:191-196` به یک فراخوانی سادهتر تبدیل شود.
|
||||
- (اختیاری) یک `BackgroundService`/`Timer` ساده برای `RemoveExpired()` هر ۵ دقیقه تا حافظه نشت نکند.
|
||||
|
||||
### گام ۶ — بهبودهای کوچک Vector Store (اختیاری ولی توصیهشده)
|
||||
- `XInMemoryVectorStore.cs:138-139`: `queryEmbedding.ToArray()` در هر iteration حلقه تکرار میشود → یکبار قبل از حلقه.
|
||||
- محدودیت حداکثر تعداد Session / Vector برای جلوگیری از OOM (ثابت در Constants).
|
||||
|
||||
### گام ۷ — اعتبارسنجی
|
||||
- `dotnet build xAiApi\xAiApi.csproj`
|
||||
- تست دستی: `POST ChatWithDocuments/Ingest` با یک PDF → دریافت `SessionId` → `POST Ask` با سؤال مرتبط و نامرتبط (بررسی `NoContextFound`) → `AskStream` → `DELETE Session`.
|
||||
- **یونیتتست:** `xFrameworkTest` پروژه Cordova/JS است، نه .NET؛ پس یا تستها حذف شوند یا یک پروژه `xAiApi.Tests` (xUnit) جدید ساخته شود — نیاز به تصمیم شما.
|
||||
|
||||
### گام ۸ — مستندسازی
|
||||
- بهروزرسانی `Documents\Docs\ChangeLogs\1405-08-03.html` (یا ChangeLog روز بعد) و حذف فایلهای موقت `Documents\Markdown\tmp.md/tmp.html` یا انتقال به `Documents\Docs\Developer\17_ChatWithDocuments.html`.
|
||||
|
||||
## نکات تصمیمگیری
|
||||
1. **Context در پرامپت یا پیام جدا؟** پیشنهاد: پیام System جداگانه (بدون نیاز به placeholder).
|
||||
2. **Ingest روی Session موجود** (`Add`) پشتیبانی شود یا هر Ingest، Session جدید بسازد؟ پیشنهاد: پارامتر اختیاری `sessionId`.
|
||||
3. **یونیتتست**: ساخت پروژه `xAiApi.Tests` یا صرفنظر؟
|
||||
|
||||
اگر طرح مورد تأیید است، گزینههای بالا را مشخص کنید و به **Act mode** سوئیچ کنید (toggle to Act mode) تا پیادهسازی را از گام ۱ شروع کنم.
|
||||
+1
-1
Submodule xAiApi updated: 47d8a19423...47da04a594
Reference in New Issue
Block a user