# المعلومات الاستخباراتية - الجزء 1-1: توليد عينات من البيانات (والصور) محلياً

<!--category-- Product, Privacy, LLM, ComfyUI, C# -->
<datetime class="hidden">2025-12-24T20:00</datetime>

داخل [الجزء الأول](/blog/zero-pii-customer-intelligence-part1) لقد غطينا الفلسفة: تقسيم شفاف بدون PII. [الجزء الثاني](/blog/zero-pii-customer-intelligence-part2) تشمل موجزات الدورات، والإشارات، وتعاريف الأجزاء.

أولاً: **كيف يمكنك التحقق من صحة أي من هذا دون أي وقت مضى لمس بيانات العملاء الحقيقية؟**

ولأجل هذه السلسلة، أُنشئ مجموعة كاملة من بيانات التجارة الإلكترونية الاصطناعية محلياً:

- (الأسماء والأوصاف والعلامات والأسعار)
- "الشخصيات المجهولة المصدر"/الشخص (المصالح + الإشارات)
- الصور المنتَج (وصورات التوصيف) عن طريق ComfyUI
- استورد DB الاختياري لكي يقاومه التطبيق الحقيقي

هذا واحد من تلك "يشعر وكأنه غش" تدفق العمل: تحصل على مدخلات واقعية، يمكنك تجديدها في أي وقت، وأنت أبداً لا تقدم PCI في بيئتك.

## لماذا البيانات التركيبية المحلية قوية جدا

إذا كنت تبني تجزئة/شخصية، فإنك تحتاج إلى مجموعات بيانات:

- لديك ما يكفي من الاختلاف لكسر التحللات ساذج
- آمنة للمشاركة (في الرموز والاختبارات والإسقاطات)
- غير قابل لإعادة قابل لإعادة المعالجة (إذاً يمكنك مقارنة تغييرات النموذج)

البيانات الحقيقية هي العكس: حساسة، فوضوية، من الصعب التحرك حولها، ومليئة بالتحيز التاريخي.

بيانات الاقتران تعطيك ثلاث قوى خارقة:

1. **/ / / /  /  -**تغيير منطق التقسيم، التجديد، إعادة التشغيل.
2. **مرجد**: محاكاة السلوكيات الغريبة الطويلة التي لن تراها في مجموعة بيانات صغيرة.
3. ****هل تستطيع * التفتيش على كل مجال من الأنشطة* وتأكد من أن "أرني لماذا" أنت صادق.

```mermaid
flowchart LR
    Taxonomy[gadget-taxonomy.json] --> Gen[SampleData generator]
    Gen --> Products[products.json]
    Gen --> Profiles[profiles.json]
    Gen --> Images[images/*]
    Products --> Import[Import into Postgres]
    Profiles --> Import

    style Taxonomy stroke:#1971c2,stroke-width:3px
    style Gen stroke:#1971c2,stroke-width:3px
    style Import stroke:#2f9e44,stroke-width:3px
```

## الـ جاري التنفيذ (ما الذي يجريه في داخل ( ماذا؟

المولّد الذي يعيش في `Mostlylucid.SegmentCommerce.SampleData`.

وليس عن قصد " إطار عمل " ؛ بل عن طريق مبادرة خارجية عملية تتحدث عن:

- **الوليمة** (LLLM المحلي) لجيل منظمة JOSON.
- **Comfyuy** (البث المستقر على أساس محلي) للصور على غرار الصور الفوتوغرافية المنتَجة.
- A A **)يتبع(** (أ) الحفاظ على اتساق النواتج (الفئات، والأنواع، والمتغيرات، ونطاقات الأسعار).

إعدادات هو مُثبّت فوق لذا أنت يُمْكِنُ أَنْ تُحرّكَه عبر بيئة المتغيرات:

```csharp
// Mostlylucid.SegmentCommerce.SampleData/Program.cs
var configuration = new ConfigurationBuilder()
    .SetBasePath(AppContext.BaseDirectory)
    .AddJsonFile("appsettings.json", optional: true)
    .AddEnvironmentVariables("SAMPLEDATA_")
    .Build();
```

## بدء البداية

تقوم عادة بإدارة ثلاث خدمات محلية إلى جانب المولد:

```mermaid
flowchart LR
    CLI[SampleData CLI] --> Ollama["Ollama
    http://localhost:11434"]
    CLI --> Comfy["ComfyUI
    http://localhost:8188"]
    CLI -. optional .-> DB[(Postgres)]

    style CLI stroke:#1971c2,stroke-width:3px
    style Ollama stroke:#1971c2,stroke-width:3px
    style Comfy stroke:#2f9e44,stroke-width:3px
    style DB stroke:#fab005,stroke-width:3px
```

تنفيذ المولّد من جذر:

```bash
dotnet run --project Mostlylucid.SegmentCommerce.SampleData -- status
```

ثمّ توليد a البيانات:

```bash
# v1 generator: taxonomy + optional Ollama + optional ComfyUI
# Writes ./Output/products.json, ./Output/profiles.json, ./Output/images/...
dotnet run --project Mostlylucid.SegmentCommerce.SampleData -- generate --count 20
```

مُستخدِم المُمَزِل:

```bash
# No LLM calls, taxonomy only
dotnet run --project Mostlylucid.SegmentCommerce.SampleData -- generate --no-ollama

# No ComfyUI images
dotnet run --project Mostlylucid.SegmentCommerce.SampleData -- generate --no-images

# Write into Postgres (uses configured connection string)
dotnet run --project Mostlylucid.SegmentCommerce.SampleData -- generate --db
```

ملاحظة: إذا لم يكن الموّلد V1 متاحاً، فإن المولّد V1 يعود إلى الصور ذات المكان (الاستخدامات) `picsum.photos`إذاً هذا الطريق ليس "متوقفاً تماماً عن العمل". `--no-images`.

## (بآلاف دولارات الولايات المتحدة)

هناك أيضاً أمر مولد جديد (`gen`) التي تبني مجموعة بيانات "على شكل سوق" أكثر اكتمالاً:

```bash
# v2 generator
# Writes dataset.json plus sellers/products/customers/orders split files
dotnet run --project Mostlylucid.SegmentCommerce.SampleData -- gen --sellers 50 --products 20 --customers 1000
```

إنها مدبرة كخط أنابيب متعدد المراحل:

```mermaid
flowchart LR
    A[Sellers] --> B[Products]
    B --> C[Customers]
    C --> D[Orders]
    D --> E[Embeddings]

    B -. optional .-> I[ComfyUI images]

    style A stroke:#1971c2,stroke-width:3px
    style B stroke:#1971c2,stroke-width:3px
    style C stroke:#1971c2,stroke-width:3px
    style D stroke:#1971c2,stroke-width:3px
    style E stroke:#2f9e44,stroke-width:3px
    style I stroke:#2f9e44,stroke-width:3px
```

ويمكنك أن ترى تلك المراحل مباشرة في الشفرة:

```csharp
// Mostlylucid.SegmentCommerce.SampleData/Services/DataGenerator.cs
// 1. Generate Sellers
// 2. Generate Products for each seller
// 3. Generate Customers
// 4. Generate Orders (with fake checkout data via Bogus)
// 5. Generate embeddings for all entities
```

### (الرتبة المحلية: OONNX, cashed بعد الجولة الأولى)

يمكن لمولِّد v2 أن يحاسب عمليات التضمين باستخدام نموذج OONNX (الافتراض: `all-MiniLM-L6-v2`في المرة الأولى التي تقوم بتشغيلها، تقوم بتحميل النموذج وتوجيهه إلى مجلد مخرجاتك.

وهذا يعني:

- احتياجات المرحلة الأولى من الدخول إلى الشبكة (تنزيل النماذج)
- المباريات اللاحقة محلية وسريعة
- إذا أردت ”لا توجد شبكة على الإطلاق“، تشغيل `--no-embeddings`

```csharp
// Mostlylucid.SegmentCommerce.SampleData/Services/EmbeddingService.cs
private const string ModelUrl = "https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/resolve/main/onnx/model.onnx";
private const string VocabUrl = "https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/resolve/main/vocab.txt";

// Download model if not exists
if (!File.Exists(_config.ModelPath))
{
    await DownloadFileAsync(ModelUrl, _config.ModelPath, ct);
}
```

## كيف ننتج منتجات "LLL-LL" (JSONSN)

والدافع إلى توليد المنتج صارم عن عمد: إذ يجب على LLLM أن تعيد JUSON فقط، مع وجود نموذج مضمن لمخطط JSON.

```csharp
// Mostlylucid.SegmentCommerce.SampleData/Services/OllamaProductGenerator.cs
return $"""
    You are a product catalog generator for an e-commerce store. Generate {count} unique, realistic product listings for the \"{category.DisplayName}\" category.

    Category description: {category.Description}
    Example products in this category: {category.ExampleProducts}
    Price range: £{category.PriceRange.Min:F2} - £{category.PriceRange.Max:F2}

    For each product, provide:
    1. A compelling product name (realistic brand-style naming)
    2. A detailed description (2-3 sentences, highlighting key features and benefits)
    3. A realistic price within the range
    4. Optional original price if on sale (20-40% higher than current price)
    5. 3-5 relevant tags
    6. Whether it's trending (about 20% should be trending)
    7. Whether it's featured (about 15% should be featured)
    8. An image prompt for AI image generation (detailed, product photography style)
    9. 2-3 colour variants for the product

    IMPORTANT: Respond with ONLY valid JSON, no markdown formatting, no code blocks, no explanations.

    Generate {count} diverse products now:
    """;
```

هذا مهم لأن النظم النهائية (توليد الصورة + الاستيراد + التضمين) تريد بيانات منظمة. LLM تنتج. *إلى خط أنابيب*لا كتابات.. لا كتابات.. لا كتابات..

### الردود على: Parse Jsson، أو Fal recht

وحتى مع عبارة "Json فقط"، لا تزال تحتاج إلى مقولة دفاعية ورجوع رشيق.

مولّد v2 يفعل ذلك عن طريق مساعد صغير`LlmService`أن يستخرج الأول `{...}` ويجسيدها على النحو التالي:

```csharp
// Mostlylucid.SegmentCommerce.SampleData/Services/LlmService.cs
var jsonStart = response.IndexOf('{');
var jsonEnd = response.LastIndexOf('}');

if (jsonStart >= 0 && jsonEnd > jsonStart)
{
    var jsonStr = response.Substring(jsonStart, jsonEnd - jsonStart + 1);
    return JsonSerializer.Deserialize<T>(jsonStr, new JsonSerializerOptions
    {
        PropertyNameCaseInsensitive = true
    });
}
```

وخطوط الانابيب العامة للجيل تقوم صراحة بالتحقق من مدى توافرها وانخفاضها إلى قوالب محددة عند الحاجة:

```mermaid
flowchart LR
    A[EnableLlm=true?] -->|no| F[Fallback templates]
    A -->|yes| B[GET /api/tags]
    B -->|model present| C[LLM JSON prompts]
    B -->|not available| F

    style A stroke:#1971c2,stroke-width:3px
    style C stroke:#2f9e44,stroke-width:3px
    style F stroke:#fab005,stroke-width:3px
```

### مثال: شخص (ت2)

والدافع الشخصي للزبائن قصير ومهيكل بحيث يمكن توليده بسرعة بنموذج محلي صغير:

```csharp
// Mostlylucid.SegmentCommerce.SampleData/Services/DataGenerator.cs
var prompt = $$"""
    Generate a shopper persona interested in: {{string.Join(", ", categoryNames)}}.

    Return JSON only:
    {
      "persona": "Brief persona description (e.g. 'Tech enthusiast who values quality')",
      "name": "Realistic first name",
      "bio": "One sentence about their shopping habits",
      "age": 25,
      "shopping_style": "budget|value|premium|luxury",
      "preferred_categories": ["category1", "category2"]
    }
    """;
```

## ComfyyUI: منتج تصويري عن طريق API

ComfyUI عظيم لأنه يعطيك خط أنابيب يمكن التحكم فيه (تدفقات العمل) بدلاً من "نقطة نهاية صورة الصندوق الأسود الوحيد".

المولّد:

1. يجري تحميل`ComfyUI/workflows/product_image.json`)
2. يَطْرِس الحثّ إلى `CLIPTextEncode`
3. الفرضيات `/prompt`
4. تقلول `/history/{promptId}`
5.  `/view?...`

```mermaid
sequenceDiagram
    participant Gen as SampleData
    participant Comfy as ComfyUI

    Gen->>Comfy: POST /prompt (workflow + prompt)
    Comfy-->>Gen: prompt_id
    loop poll
        Gen->>Comfy: GET /history/{prompt_id}
        Comfy-->>Gen: outputs / images
    end
    Gen->>Comfy: GET /view?filename=...&type=output
    Comfy-->>Gen: PNG bytes
```

اختيار نموذج comfyUI مُرَحَّل أيضاً إلى تدفق العمل في وقت التنفيذ (لذا يمكنك مبادلة نقاط التفتيش بدون تحرير Json):

```csharp
// Mostlylucid.SegmentCommerce.SampleData/Services/ComfyUIImageGenerator.cs
TryPatchCheckpoint(workflow, _config.ComfyUICheckpointName ?? "sd_xl_base_1.0.safetensors");
TryPatchRefiner(workflow, _config.ComfyUIRefinerName ?? "sd_xl_refiner_1.0.safetensors");
```

و تنسيق تدفق العمل بسيط و قوي عمداً:

```csharp
// Mostlylucid.SegmentCommerce.SampleData/Services/ComfyUIImageGenerator.cs
// Update CLIPTextEncode nodes with our prompt
if (classType == "CLIPTextEncode")
{
    var inputs = nodeObj["inputs"]?.AsObject();
    if (inputs != null && inputs.ContainsKey("text"))
    {
        var currentText = inputs["text"]?.GetValue<string>() ?? "";
        if (!currentText.Contains("bad") && !currentText.Contains("ugly") && !currentText.Contains("deformed"))
        {
            inputs["text"] = prompt;
        }
    }
}

// Update image dimensions
if (classType == "EmptyLatentImage")
{
    var inputs = nodeObj["inputs"]?.AsObject();
    if (inputs != null)
    {
        inputs["width"] = _config.ImageWidth;
        inputs["height"] = _config.ImageHeight;
    }
}
```

## التوصيفات والشخصيات (مفيدة، لا مخيفة)

ويخلق المولد V1 ملفات مجهولة الهوية ثم يثريها بشخصية (لا يزال لا يوجد PII). وينتهي بك الأمر إلى الحصول على بيانات اختبار "شخصية" واقعية من دون رسائل بريد إلكتروني أو عناوين أو أي شيء يمكن أن تشحنه عن طريق الخطأ.

في v1، يتم تحديد الملامح باستخدام هش أحادي الاتجاه، لذلك لا يوجد شيء "لاستعادة":

```csharp
// Mostlylucid.SegmentCommerce.SampleData/Services/ProfileGenerator.cs
var profileKey = Hash($"fp-{Guid.NewGuid():N}");

private static string Hash(string input)
{
    using var sha = SHA256.Create();
    var bytes = sha.ComputeHash(Encoding.UTF8.GetBytes(input));
    return Convert.ToHexString(bytes).ToLowerInvariant();
}
```

وهذه هي بالضبط عقلية السلسلة الكاملة : لا يمكنك ان تتسرب ما لم تخزنه قط .

```mermaid
flowchart TB
    Signals["Generated signals
    views/cart/purchase weights"] --> Persona["Persona enrichment
    Ollama JSON-only"]
    Persona --> Portrait[Portrait prompt]
    Portrait --> Comfy[ComfyUI]

    style Signals stroke:#1971c2,stroke-width:3px
    style Persona stroke:#1971c2,stroke-width:3px
    style Comfy stroke:#2f9e44,stroke-width:3px
```

## الصلاحية : ما الذي يتيح لك ان تثبته

خط الأنابيب المحلي هذا قوي لأنه يدعم *ألف - المصادقة على نموذج*ليس فقط عروضاً عرضية

- **مُجَلَصَة**: هل الأجزاء التي تحسبها "الشعر" متماسكة عندما تفحص أسماء/علامات المنتجات والشخصيات المنتجة؟
- ****هل "أرني لماذا" تشير إلى إشارة حقيقية يمكنك التحقق منها؟
- **بدء بدأ**إذا قمت بمسح مجموعة البيانات وتجديدها، هل يعمل النظام بشكل يمكن التنبؤ به؟
- **اختبار الرسوب**اصنع نفس شكل البيانات وتأكد من أن تغيراتك لا تكسر الترتيب، أو الدرجات، أو UI.

المعامله المهمه المهمه: عن طريق توليد كلا *النص النص* وقد عقد مؤتمراً *)١*يمكنك التحقق من كامل خبرة المنتج، وليس فقط الرياضيات الخلفية.

## ما هو التالي

**[الجزء الثاني](/blog/zero-pii-customer-intelligence-part2)**: موجزات الجلسة، الإشارات، وتعاريف الأجزاء  حيث نقوم بتوصيل بيانات العينة هذه إلى تقسيم عملي.

**الجزء الثالث** نمط صندوق الخروج، طابور الوظائف، والشفافية UI.

---


*رمز التشغيل: `Mostlylucid.SegmentCommerce.SampleData/`*