Analytics Dashboard Template
The analytics dashboard template provides real-time insights into your knowledge base performance, document statistics, and system health metrics. It uses pre-computed statistics stored in bot memory for fast loading.
Topic: Knowledge Base Analytics & Monitoring
This template is perfect for:
- Monitoring knowledge base growth
- Tracking document indexing status
- System health monitoring
- Capacity planning
The Code
REM Analytics Dashboard Start Dialog
REM Displays pre-computed statistics from update-stats.bas
DESCRIPTION "View knowledge base analytics and statistics"
REM Load pre-computed values from BOT MEMORY
totalDocs = GET BOT MEMORY("analytics_total_docs")
totalVectors = GET BOT MEMORY("analytics_total_vectors")
storageMB = GET BOT MEMORY("analytics_storage_mb")
collections = GET BOT MEMORY("analytics_collections")
docsWeek = GET BOT MEMORY("analytics_docs_week")
docsMonth = GET BOT MEMORY("analytics_docs_month")
growthRate = GET BOT MEMORY("analytics_growth_rate")
healthPercent = GET BOT MEMORY("analytics_health_percent")
lastUpdate = GET BOT MEMORY("analytics_last_update")
REM Set contexts for different report types
SET CONTEXT "overview" AS "Total documents: " + totalDocs + ", Storage: " + storageMB + " MB"
SET CONTEXT "activity" AS "Documents added this week: " + docsWeek + ", Growth rate: " + growthRate + "%"
SET CONTEXT "health" AS "System health: " + healthPercent + "%, Last updated: " + lastUpdate
REM Setup suggestions
CLEAR SUGGESTIONS
ADD SUGGESTION "overview" AS "Show overview"
ADD SUGGESTION "activity" AS "Recent activity"
ADD SUGGESTION "health" AS "System health"
REM Display dashboard
TALK "📊 **Analytics Dashboard**"
TALK ""
TALK "**Knowledge Base Overview**"
TALK "• Documents: " + FORMAT(totalDocs, "#,##0")
TALK "• Vectors: " + FORMAT(totalVectors, "#,##0")
TALK "• Storage: " + FORMAT(storageMB, "#,##0.00") + " MB"
TALK ""
TALK "Ask me about any metric or select a topic above."
Sample Dialogs
These conversations show how the analytics dashboard works in real-world scenarios.
Dialog 1: Viewing Overview Statistics
📊
Analytics Bot
online
Today
Dialog 2: Checking System Health
📊
Analytics Bot
online
Dialog 3: Statistics Not Yet Computed
📊
Analytics Bot
online
Keywords Used
| Keyword | Purpose |
|---|---|
GET BOT MEMORY | Retrieve pre-computed statistics |
SET CONTEXT | Provide context for AI responses |
CLEAR SUGGESTIONS | Reset quick reply options |
ADD SUGGESTION | Add quick reply buttons |
TALK | Display formatted statistics |
FORMAT | Format numbers with separators |
How It Works
- Load Statistics: Pre-computed values are retrieved from bot memory
- Set Contexts: Different contexts are set for overview, activity, and health queries
- Setup UI: Quick reply suggestions are configured
- Display Dashboard: Formatted statistics are shown to the user
The Update Stats Job
Statistics are pre-computed by a scheduled job to ensure fast dashboard loading:
REM update-stats.bas - Scheduled job to compute analytics
SET SCHEDULE "0 * * * *" REM Run every hour
REM Compute statistics
totalDocs = KB DOCUMENTS COUNT()
totalVectors = KB STATISTICS().total_vectors
storageMB = KB STORAGE SIZE() / 1024 / 1024
collections = UBOUND(KB LIST COLLECTIONS())
REM Calculate activity
docsWeek = KB DOCUMENTS ADDED SINCE(NOW() - 7)
docsMonth = KB DOCUMENTS ADDED SINCE(NOW() - 30)
REM Store in bot memory
SET BOT MEMORY "analytics_total_docs", totalDocs
SET BOT MEMORY "analytics_total_vectors", totalVectors
SET BOT MEMORY "analytics_storage_mb", storageMB
SET BOT MEMORY "analytics_collections", collections
SET BOT MEMORY "analytics_docs_week", docsWeek
SET BOT MEMORY "analytics_docs_month", docsMonth
SET BOT MEMORY "analytics_last_update", NOW()
TALK "Analytics updated successfully."
Customization Ideas
Add Export Functionality
ADD TOOL "export-stats"
REM In export-stats.bas
PARAM format AS STRING LIKE "csv" DESCRIPTION "Export format: csv, json, xlsx"
data = []
data.total_docs = GET BOT MEMORY("analytics_total_docs")
data.total_vectors = GET BOT MEMORY("analytics_total_vectors")
data.storage_mb = GET BOT MEMORY("analytics_storage_mb")
IF format = "csv" THEN
SAVE "analytics-export.csv", data
TALK "📥 Analytics exported to analytics-export.csv"
ELSE IF format = "json" THEN
WRITE "analytics-export.json", TOJSON(data)
TALK "📥 Analytics exported to analytics-export.json"
END IF
Add Alerting
REM Check for issues and alert
IF healthPercent < 90 THEN
SEND MAIL "admin@company.com", "System Health Alert", "Health dropped to " + healthPercent + "%"
END IF
IF storageMB > 900 THEN
SEND MAIL "admin@company.com", "Storage Warning", "Storage usage at " + storageMB + " MB"
END IF
Add Trend Visualization
REM Generate a simple trend chart
ADD TOOL "show-trend"
REM Collect historical data
history = FIND "analytics_history.csv", "date > " + FORMAT(NOW() - 30, "YYYY-MM-DD")
REM Create chart
chart = CREATE CHART "line", history, "date", "documents"
TALK chart
Related Templates
- backup.bas - Backup management and monitoring
- start.bas - Basic bot structure