The `KB STATISTICS` keyword retrieves comprehensive statistics about the bot's knowledge base, including document counts, vector counts, storage usage, and collection information from the Qdrant vector database.
---
## Syntax
```basic
stats = KB STATISTICS
```
---
## Parameters
None. Returns statistics for the current bot's knowledge base.
---
## Description
`KB STATISTICS` queries the Qdrant vector database to gather comprehensive metrics about the bot's knowledge base. This is useful for monitoring KB health, planning capacity, generating admin reports, and tracking document ingestion over time.
The keyword returns a JSON object containing:
- Total collections count
- Total documents across all collections
- Total vectors stored
- Disk and RAM usage
- Documents added in the last week/month
- Per-collection statistics
Use cases include:
- Admin dashboards and monitoring
- Capacity planning and alerts
- Usage reporting and analytics
- Knowledge base health checks
- Cost tracking for vector storage
---
## Return Value
Returns a JSON string with the following structure:
| Property | Type | Description |
|----------|------|-------------|
| `total_collections` | Number | Number of KB collections for this bot |
| `total_documents` | Number | Total document count across collections |
| `total_vectors` | Number | Total vectors stored in Qdrant |
| `total_disk_size_mb` | Number | Disk storage usage in MB |
| `total_ram_size_mb` | Number | RAM usage in MB |
| `documents_added_last_week` | Number | Documents added in past 7 days |
| `documents_added_last_month` | Number | Documents added in past 30 days |
| `collections` | Array | Detailed stats per collection |
### Collection Stats Object
Each collection in the `collections` array contains:
| Property | Type | Description |
|----------|------|-------------|
| `name` | String | Collection name |
| `vectors_count` | Number | Vectors in this collection |
| `points_count` | Number | Points (documents) count |
| `segments_count` | Number | Storage segments |
| `disk_data_size` | Number | Disk size in bytes |
| `ram_data_size` | Number | RAM size in bytes |
| `indexed_vectors_count` | Number | Indexed vectors |
| `status` | String | Collection status (green/yellow/red) |
- [KB LIST COLLECTIONS](keyword-kb-list-collections.md) — List all KB collections
- [KB STORAGE SIZE](keyword-kb-storage-size.md) — Get storage usage in MB
- [CLEAR KB](keyword-clear-kb.md) — Clear knowledge base content
- [USE KB](keyword-use-kb.md) — Enable knowledge base for queries
---
## Configuration
No specific configuration required. The keyword uses the Qdrant connection configured at the system level.
Ensure Qdrant is running and accessible:
```csv
name,value
qdrant-url,https://localhost:6334
```
---
## Implementation Notes
- Implemented in Rust under `src/basic/keywords/kb_statistics.rs`
- Queries Qdrant REST API for collection statistics
- Filters collections by bot ID prefix (`kb_{bot_id}`)
- Document counts from both Qdrant and PostgreSQL
- Returns JSON string for flexible parsing
- May take 1-2 seconds for large knowledge bases
---
## Summary
`KB STATISTICS` provides comprehensive metrics about the bot's knowledge base, enabling administrators to monitor health, track growth, and plan capacity. Use it for dashboards, alerts, and reporting. For simpler queries, use the specialized keywords like `KB DOCUMENTS COUNT` or `KB STORAGE SIZE`.