The `KB DOCUMENTS ADDED SINCE` keyword returns the count of documents added to the knowledge base within a specified number of days, useful for tracking ingestion activity and monitoring growth.
---
## Syntax
```basic
count = KB DOCUMENTS ADDED SINCE days
```
---
## Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `days` | Number | Number of days to look back |
---
## Description
`KB DOCUMENTS ADDED SINCE` queries the database to count how many documents were added to the bot's knowledge base within the specified time window. This is useful for tracking ingestion rates, monitoring content growth, and generating activity reports.
Use cases include:
- Tracking daily/weekly document ingestion
- Monitoring automated content pipelines
- Activity reports and dashboards
- Alert systems for low/high activity
- Growth trend analysis
---
## Return Value
Returns an integer representing the number of documents added within the specified period.
---
## Examples
### Basic Usage
```basic
' Count documents added in last 7 days
weekly_count = KB DOCUMENTS ADDED SINCE 7
TALK "Documents added this week: " + weekly_count
```
### Daily Activity Check
```basic
' Check today's ingestion
today_count = KB DOCUMENTS ADDED SINCE 1
IF today_count = 0 THEN
TALK "No new documents added today"
ELSE
TALK today_count + " documents added today"
END IF
```
### Growth Comparison
```basic
' Compare recent activity periods
last_week = KB DOCUMENTS ADDED SINCE 7
last_month = KB DOCUMENTS ADDED SINCE 30
weekly_average = last_month / 4
IF last_week > weekly_average * 1.5 THEN
TALK "Document ingestion is above average this week!"
ELSE IF last_week <weekly_average*0.5THEN
TALK "Document ingestion is below average this week"
ELSE
TALK "Document ingestion is on track"
END IF
```
### Activity Alert System
```basic
' Alert if no documents added recently
recent_docs = KB DOCUMENTS ADDED SINCE 3
IF recent_docs = 0 THEN
SEND_MAIL admin_email,
"KB Activity Alert",
"No documents have been added to the knowledge base in the last 3 days. Please check content pipelines.",
- [KB LIST COLLECTIONS](keyword-kb-list-collections.md) — List collections
---
## Implementation Notes
- Implemented in Rust under `src/basic/keywords/kb_statistics.rs`
- Queries PostgreSQL `kb_documents` table by `created_at` timestamp
- Filters by current bot ID
- Returns 0 if no documents found or on error
- Days parameter is converted to interval for SQL query
---
## Summary
`KB DOCUMENTS ADDED SINCE` provides a simple way to track recent document ingestion activity. Use it for monitoring content pipelines, generating activity reports, and creating alerts for unusual activity levels. Combine with other KB keywords for comprehensive knowledge base monitoring.