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15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
"""
๐Ÿง  DATAVISION PRODUCT KNOWLEDGE BASE
====================================

This module contains comprehensive product knowledge that enables
the AI to understand and guide users through DataVision features.

Used by the LLM to:
1. Answer "how to" questions about the product
2. Guide users to the right features
3. Provide step-by-step instructions
4. Explain what DataVision is and its capabilities
"""


DATAVISION_PRODUCT_KNOWLEDGE = """
## ๐Ÿš€ DataVision AI - Complete Product Knowledge Base

### WHAT IS DATAVISION?

**DataVision AI** is an enterprise-grade, AI-powered data analytics and machine learning platform that enables users to:
- Upload and analyze data without coding
- Train production-quality machine learning models in minutes
- Get AI-powered insights from business data
- Create automated reports and visualizations
- Make predictions using trained models

**Key Differentiators:**
- ๐Ÿง  **No-Code ML**: Train models without programming
- โšก **Fast Training**: From data to production model in 30 seconds to 10 minutes
- ๐ŸŽฏ **Multi-Mode AI**: Traditional ML, NLP (Natural Language Processing), and Deep Learning
- ๐Ÿ“Š **Smart Analytics**: AI-generated charts and insights
- ๐Ÿ”’ **Per-User Isolation**: Each user's data and models are completely private

### ML MODES EXPLAINED:

1. **Traditional ML** ๐Ÿค–
   - Best for: Structured/tabular data (sales, customers, transactions)
   - Algorithms: Random Forest, XGBoost, LightGBM, SVM, Neural Networks
   - Use when: Your data has clear columns like "price", "age", "category"

2. **NLP (Natural Language Processing)** ๐Ÿ“
   - Best for: Text data (reviews, emails, documents, social media)
   - Algorithms: TF-IDF, Word2Vec, BERT, Sentiment Analysis
   - Use when: You want to analyze or classify text content

3. **Deep Learning** ๐Ÿง 
   - Best for: Complex patterns, large datasets, sequential data
   - Architectures: MLP, RNN, LSTM, GRU, Transformers
   - Use when: You have 10,000+ rows or need maximum accuracy

### CORE FEATURES:

1. **DATA HUB** (Upload & Manage Data) ๐Ÿ“‚
   - Upload CSV, Excel (.xlsx, .xls), JSON files (max 50MB)
   - View data preview with first 100 rows
   - See column statistics and data types
   - Check data quality scores (A-F grades)
   - Auto-detect date, numeric, and categorical columns
   - **Navigation**: Click "Data Hub" in the sidebar

2. **ANALYST CHAT** (AI-Powered Data Q&A) ๐Ÿ’ฌ
   - Ask questions in natural language
   - Get charts, insights, and analysis automatically
   - Three analysis modes:
     - โšก Speed Mode: Fast answers, simple queries
     - ๐ŸŽฏ Balanced Mode: Best accuracy/speed trade-off (DEFAULT)
     - ๐Ÿ”ฌ Precision Mode: Most accurate, complex analysis
   - Example questions:
     - "What are my total sales by region?"
     - "Show me a trend of revenue over time"
     - "Which products have the highest margins?"
   - **Navigation**: Click "Chat" in the sidebar

3. **AUTOML** (Train Machine Learning Models) ๐Ÿค–
   - Upload data โ†’ Select target column โ†’ Click Train
   - Automatically tests 20+ algorithms and picks the best
   - Three ML modes:
     - **Traditional ML**: For tabular/structured data
     - **NLP**: For text classification/analysis
     - **Deep Learning**: For complex patterns and large data
   - Two training speeds:
     - **Fast Mode**: 7 algorithms, ~30-60 seconds
     - **Ultra Mode**: 20+ algorithms, ~2-10 minutes (maximum accuracy)
   - Supported tasks:
     - **Classification**: Predict categories (Yes/No, A/B/C, spam/not spam)
     - **Regression**: Predict numbers (price, sales, scores)
   - **Navigation**: Click "ML Predictions" in the sidebar

4. **ML PREDICTIONS** (Use Trained Models) ๐Ÿ”ฎ
   - View all your trained models with metrics
   - **Playground**: Make single predictions by entering values
   - **Batch Predictions**: Upload new data for bulk predictions
   - Export predictions as CSV
   - View feature importance and model insights
   - Compare models from different training runs
   - **Navigation**: Click "ML Predictions" in the sidebar

5. **CLUSTERING** (Unsupervised Learning) ๐ŸŽฏ
   - Find natural groups in your data
   - Perfect for customer segmentation
   - Algorithms available:
     - K-Means (most common, fast)
     - DBSCAN (density-based, finds outliers)
     - Hierarchical (creates tree of clusters)
     - GMM (Gaussian Mixture, soft clustering)
     - Spectral (graph-based)
   - Auto-detects optimal number of clusters
   - **Navigation**: Click "Clustering" in the sidebar

6. **DASHBOARD** (AI-Generated Visualizations) ๐Ÿ“Š
   - Automatic chart recommendations based on your data
   - Interactive visualizations (hover, zoom, filter)
   - KPI cards showing key metrics
   - Export as PNG, PDF, or PPTX
   - **Navigation**: Click "Dashboard" in the sidebar

7. **REPORTS** (Automated Reports) ๐Ÿ“‹
   - Generate PDF/Markdown reports automatically
   - Report types:
     - Executive Summary
     - Data Quality Report
     - ML Model Performance Report
     - Full Analysis Report
   - Schedule automated reports (daily/weekly)
   - **Navigation**: Click "Reports" in the sidebar

8. **FORECASTING** (Time Series Predictions) ๐Ÿ“ˆ
   - Predict future values (sales, demand, prices)
   - Automatic trend detection
   - Seasonality analysis
   - Multiple algorithms: ARIMA, Prophet, LSTM
   - Confidence intervals for predictions

### COMMON USER QUESTIONS AND ANSWERS:

**Q: "What is DataVision?"**
A: DataVision AI is a no-code data analytics and machine learning platform. You can upload data, train ML models, make predictions, create visualizations, and generate reports - all without writing code. It supports Traditional ML, NLP, and Deep Learning.

**Q: "How do I upload data?"**
A: Go to **Data Hub** โ†’ Click the upload area or drag & drop your CSV/Excel/JSON file. Files are automatically processed and you'll see a preview immediately.

**Q: "How do I train a machine learning model?"**
A: 
1. Go to **ML Predictions** (click in sidebar)
2. Select your uploaded file
3. Choose the column you want to predict (target)
4. Select ML mode (Traditional/NLP/Deep Learning)
5. Click **"Train Model"**
6. Wait for training to complete (30 seconds - 10 minutes)
7. View results: accuracy, charts, feature importance

**Q: "What file formats are supported?"**
A: CSV (.csv), Excel (.xlsx, .xls), and JSON files up to 50MB.

**Q: "How do I make predictions with my trained model?"**
A: 
1. Go to **ML Predictions** (click in sidebar)
2. Click the **Playground** tab
3. Enter values for each feature
4. Click **Predict** to get the result
5. For bulk predictions, use the **Batch** tab and upload a CSV

**Q: "How do I segment customers?"**
A: 
1. Go to **Clustering** (click in sidebar)
2. Select your customer data file
3. Choose an algorithm (K-Means recommended)
4. Click **Run Clustering**
5. View the segments and insights
6. Download the results with cluster labels

**Q: "How do I export results?"**
A: Click the **Download** button on any chart or report. Available formats: CSV, PNG, PDF, PPTX.

**Q: "What's the difference between Fast and Ultra training mode?"**
A: 
- **Fast Mode**: Tests 7 top algorithms quickly (~30-60 seconds). Good for quick experiments.
- **Ultra Mode**: Tests 20+ algorithms with hyperparameter tuning (~2-10 minutes). Best for production models with maximum accuracy.

**Q: "When should I use NLP mode?"**
A: Use NLP mode when your data contains text you want to analyze or classify. Examples:
- Sentiment analysis of reviews
- Email/ticket classification
- Spam detection
- Document categorization

**Q: "When should I use Deep Learning mode?"**
A: Use Deep Learning when:
- You have 10,000+ rows of data
- Traditional ML accuracy is not satisfactory
- Your data has complex patterns
- You're working with sequential or time-series data

**Q: "Why is my model accuracy low?"**
A: Common reasons and solutions:
1. **Not enough data**: Aim for 500+ rows, ideally 5000+
2. **Missing values in target**: Clean your data before training
3. **Too many categories**: Consider grouping similar categories
4. **Irrelevant features**: Remove columns that don't relate to the prediction
5. **Class imbalance**: Use Ultra mode which handles imbalanced data better

**Q: "How do I ask better questions in Chat?"**
A: Be specific! Instead of "show me data", try:
- "What are total sales by region?"
- "Show monthly revenue trend for 2024"
- "Which products have the highest profit margin?"
- "Compare sales between Q1 and Q2"
- "What is the average order value by customer segment?"

**Q: "How do I improve model accuracy?"**
A: 
1. Use **Ultra Mode** for more thorough training
2. Try **Deep Learning** mode for complex patterns
3. Clean your data (remove duplicates, handle missing values)
4. Train on more data (more rows = better learning)
5. Check **Feature Importance** and remove irrelevant columns
6. Use **Multi-Mode** training to combine Traditional ML + NLP + Deep Learning

### ML METRICS EXPLAINED:

- **Accuracy**: Percentage of correct predictions (higher is better)
- **Precision**: Of positive predictions, how many were correct?
- **Recall**: Of actual positives, how many did we catch?
- **F1 Score**: Balance between precision and recall
- **AUC-ROC**: Model's ability to distinguish between classes
- **Rยฒ Score**: For regression - how well model explains variance
- **MAE/RMSE**: For regression - average prediction error

### WHAT I CAN HELP WITH:

1. **DATA ANALYSIS** - When you ask about your uploaded data
   - "What are the top 10 customers by revenue?"
   - "Show me trends over time"
   - "Calculate average order value"
   - "What's the distribution of sales by region?"

2. **PRODUCT GUIDANCE** - When you ask how to use features
   - "How do I train a model?"
   - "Where do I upload files?"
   - "How to export predictions?"
   - "What's the difference between ML modes?"

3. **ML RECOMMENDATIONS** - When you need ML advice
   - "Should I use classification or regression?"
   - "What algorithm is best for my data?"
   - "How can I improve accuracy?"
   - "When should I use Deep Learning?"

4. **TECHNICAL SUPPORT** - When you have issues
   - "Why is training taking so long?"
   - "Why can't I see my charts?"
   - "How do I fix low accuracy?"
"""


def get_product_knowledge() -> str:
    """Get the product knowledge base string."""
    return DATAVISION_PRODUCT_KNOWLEDGE


def is_product_question(query: str) -> bool:
    """
    Detect if the query is asking about DataVision features
    rather than about the user's data.
    """
    product_keywords = [
        # What is questions
        "what is datavision", "what is this", "what does this do",
        "what can you do", "what are your capabilities", "what features",
        "tell me about datavision", "explain datavision", "describe datavision",
        
        # How-to questions
        "how do i", "how to", "how can i",
        "where do i", "where is", "where can i",
        "what is the", "what's the",
        
        # Feature names
        "data hub", "datahub", "automl", "auto ml", "auto-ml",
        "predictions", "prediction page", "clustering",
        "dashboard", "reports", "settings", "playground",
        "ml predictions", "deep learning", "nlp", "traditional ml",
        
        # Actions
        "upload", "train", "predict", "export", "download",
        "segment", "cluster", "analyze", "forecast",
        
        # Navigation
        "find", "access", "navigate", "go to", "open",
        
        # Help
        "help", "tutorial", "guide", "instructions",
        "documentation", "docs", "getting started",
        
        # Product-specific
        "datavision", "this app", "this tool", "the system",
        "your feature", "your product", "this platform",
        "this application", "your capabilities",
        
        # ML concepts (when asking generally, not about their data)
        "what is classification", "what is regression",
        "what is machine learning", "what is deep learning",
        "what is nlp", "what is clustering",
        "difference between", "when should i use",
        "how does ml work", "what algorithm",
        "improve accuracy", "fix accuracy", "better model"
    ]
    
    query_lower = query.lower()
    return any(keyword in query_lower for keyword in product_keywords)


def get_relevant_product_help(query: str) -> str:
    """
    Get specific product help based on the query topic.
    Returns a focused response rather than the full knowledge base.
    """
    query_lower = query.lower()
    
    # What is DataVision
    if any(phrase in query_lower for phrase in ["what is datavision", "what is this", "tell me about datavision", 
                                                   "what can you do", "what does this do", "your capabilities"]):
        return """
๐Ÿš€ **What is DataVision AI?**

DataVision is an enterprise-grade, AI-powered data analytics and machine learning platform that enables you to:

- ๐Ÿ“‚ **Upload Data**: CSV, Excel, JSON files up to 50MB
- ๐Ÿ’ฌ **Ask Questions**: Natural language queries about your data
- ๐Ÿค– **Train ML Models**: No-code machine learning (Traditional ML, NLP, Deep Learning)
- ๐Ÿ”ฎ **Make Predictions**: Use trained models on new data
- ๐Ÿ“Š **Create Charts**: AI-generated visualizations
- ๐Ÿ“‹ **Generate Reports**: Automated PDF/Markdown reports
- ๐ŸŽฏ **Cluster Data**: Customer segmentation and grouping

**Getting Started:**
1. Upload your data in **Data Hub**
2. Ask questions in **Chat** or train a model in **ML Predictions**
3. View insights in **Dashboard**
"""
    
    # Upload/Data questions
    if any(word in query_lower for word in ["upload", "file", "data hub", "import"]):
        return """
๐Ÿ“‚ **Uploading Data:**
1. Go to **Data Hub** (click in sidebar)
2. Drag & drop your file or click to browse
3. Supported formats: CSV, Excel (.xlsx, .xls), JSON
4. Max file size: 50MB
5. Data is automatically processed and previewed
"""
    
    # Training questions
    if any(word in query_lower for word in ["train", "automl", "machine learning"]):
        return """
๐Ÿค– **Training ML Models:**
1. Go to **ML Predictions** (click in sidebar)
2. Select your uploaded file
3. Choose the target column (what to predict)
4. Select ML mode:
   - **Traditional ML**: Best for tabular data
   - **NLP**: Best for text data
   - **Deep Learning**: Best for complex patterns
5. Click **Train Model**
6. Wait for training (30s - 10min)

**Tips:**
- Use **Ultra Mode** for maximum accuracy
- Ensure target column has no missing values
- Aim for 500+ rows of data
"""

    # NLP questions
    if any(word in query_lower for word in ["nlp", "text", "natural language", "sentiment"]):
        return """
๐Ÿ“ **NLP (Natural Language Processing):**

Use NLP mode when your data contains text you want to analyze or classify:
- **Sentiment Analysis**: Analyze customer reviews, feedback
- **Text Classification**: Categorize emails, tickets, documents
- **Spam Detection**: Identify spam vs legitimate content

**How to use:**
1. Go to **ML Predictions**
2. Select file with text column
3. Choose **NLP** mode
4. Select your text column
5. Train the model

**Algorithms**: TF-IDF, Word2Vec, BERT, FastText, and more
"""

    # Deep Learning questions
    if any(word in query_lower for word in ["deep learning", "neural network", "lstm", "rnn", "ann"]):
        return """
๐Ÿง  **Deep Learning:**

Use Deep Learning for complex patterns and large datasets:
- Best when you have **10,000+ rows**
- Captures non-linear relationships
- Great for sequential/time-series data

**Available Architectures:**
- MLP (Multi-Layer Perceptron)
- RNN (Recurrent Neural Network)
- LSTM (Long Short-Term Memory)
- GRU (Gated Recurrent Unit)
- Transformers

**How to use:**
1. Go to **ML Predictions**
2. Select file
3. Choose **Deep Learning** mode
4. Select architecture (or use Auto)
5. Train the model
"""
    
    # Prediction questions
    if any(word in query_lower for word in ["predict", "inference", "playground"]):
        return """
๐Ÿ”ฎ **Making Predictions:**
1. Go to **ML Predictions** (click in sidebar)
2. Click the **Playground** tab
3. Enter values for each feature
4. Click **Predict** to get the result

**For Batch Predictions:**
1. Click the **Batch** tab
2. Upload a CSV with new data
3. Download predictions with results
"""
    
    # Clustering questions
    if any(word in query_lower for word in ["cluster", "segment", "group", "unsupervised"]):
        return """
๐ŸŽฏ **Clustering / Segmentation:**
1. Go to **Clustering** (click in sidebar)
2. Select your data file
3. Choose algorithm:
   - **K-Means**: Most common, fast
   - **DBSCAN**: Finds outliers
   - **Hierarchical**: Creates tree structure
   - **GMM**: Soft clustering
4. Click **Run Clustering**
5. View segments and download results

**Best for:** Customer segmentation, product grouping, pattern discovery
"""
    
    # Chart/Dashboard questions
    if any(word in query_lower for word in ["chart", "graph", "visual", "dashboard"]):
        return """
๐Ÿ“Š **Creating Visualizations:**
1. Go to **Dashboard** for AI-generated charts
2. Or ask me in Chat: "Show me a bar chart of sales by region"
3. Click **Download** on any chart to export as PNG

**Chart Types:** Bar, Line, Pie, Scatter, Heatmap, Box Plot, and more
"""
    
    # Export questions
    if any(word in query_lower for word in ["export", "download", "save"]):
        return """
๐Ÿ“ฅ **Exporting Data:**
- **Charts**: Click Download button โ†’ PNG or PDF
- **Predictions**: ML Predictions page โ†’ Download CSV
- **Reports**: Reports page โ†’ Generate โ†’ Download PDF
- **Raw Data**: Data Hub โ†’ Export button
"""
    
    # Accuracy questions
    if any(word in query_lower for word in ["accuracy", "improve", "better model", "low score"]):
        return """
๐Ÿ“ˆ **Improving Model Accuracy:**

1. **More Data**: Aim for 500+ rows, ideally 5000+
2. **Clean Data**: Remove duplicates, handle missing values
3. **Ultra Mode**: Tests 20+ algorithms for best results
4. **Deep Learning**: Try for complex patterns
5. **Multi-Mode**: Combine Traditional + NLP + Deep Learning
6. **Feature Engineering**: Remove irrelevant columns

**Common Issues:**
- Target column has missing values
- Too many categories (try grouping)
- Data is too imbalanced (one class dominates)
"""
    
    # Default - return full knowledge
    return DATAVISION_PRODUCT_KNOWLEDGE