Author: mrveiss Copyright: © 2025 mrveiss Issue: #539
This document describes the performance optimizations available for ChromaDB codebase indexing.
The codebase indexing system scans the AutoBot codebase and stores code metadata (functions, classes, problems) in ChromaDB for semantic search and analysis. For large codebases (53K+ items), indexing can be resource-intensive.
This document covers the configurable optimizations introduced in Issue #539.
All configuration is done via environment variables. Set these in your .env file or export them before starting AutoBot.
Environment Variable: CODEBASE_INDEX_BATCH_SIZE
Default: 5000
Range: 1000 - 10000 (recommended)
Controls how many items are stored to ChromaDB per batch operation.
# Smaller batches - less memory, more batches
export CODEBASE_INDEX_BATCH_SIZE=2500
# Larger batches - more memory, fewer batches (faster)
export CODEBASE_INDEX_BATCH_SIZE=7500Trade-offs:
- Higher values: Fewer batch operations, faster overall, but more memory usage
- Lower values: More batch operations, slower overall, but less memory usage
Environment Variable: CODEBASE_INDEX_PARALLEL_BATCHES
Default: 1 (sequential)
Range: 1 - 4 (recommended)
Controls how many batches are processed concurrently during the storage phase.
# Sequential processing (default - safest)
export CODEBASE_INDEX_PARALLEL_BATCHES=1
# Process 2 batches concurrently
export CODEBASE_INDEX_PARALLEL_BATCHES=2
# Process 4 batches concurrently (fastest, highest resource usage)
export CODEBASE_INDEX_PARALLEL_BATCHES=4Trade-offs:
- Higher values: Faster storage, but higher CPU/memory usage
- Lower values: Slower storage, but lower resource usage
Note: ChromaDB may have limitations on concurrent writes. Start with 2 and increase if stable.
Environment Variable: CODEBASE_INDEX_INCREMENTAL
Default: false
Values: true | false
When enabled, only re-indexes files that have changed since the last indexing run.
# Enable incremental indexing
export CODEBASE_INDEX_INCREMENTAL=true
# Disable (full re-index every time)
export CODEBASE_INDEX_INCREMENTAL=falseHow it works:
- Computes SHA-256 hash of each file
- Compares with stored hash in Redis
- Skips files with matching hashes (unchanged)
- Stores new hashes after successful processing
Requirements:
- Redis must be available (uses
analyticsdatabase) - File hashes stored with prefix
codebase:file_hash:
Trade-offs:
- Enabled: Much faster subsequent runs, but requires Redis
- Disabled: Full re-index every time, no Redis dependency
# Fast indexing, acceptable resource usage
export CODEBASE_INDEX_BATCH_SIZE=5000
export CODEBASE_INDEX_PARALLEL_BATCHES=2
export CODEBASE_INDEX_INCREMENTAL=true# Balanced performance and stability
export CODEBASE_INDEX_BATCH_SIZE=5000
export CODEBASE_INDEX_PARALLEL_BATCHES=1
export CODEBASE_INDEX_INCREMENTAL=true# Minimize memory usage
export CODEBASE_INDEX_BATCH_SIZE=2000
export CODEBASE_INDEX_PARALLEL_BATCHES=1
export CODEBASE_INDEX_INCREMENTAL=true# Fastest possible indexing (high resource usage)
export CODEBASE_INDEX_BATCH_SIZE=7500
export CODEBASE_INDEX_PARALLEL_BATCHES=4
export CODEBASE_INDEX_INCREMENTAL=trueThe indexing task exposes configuration in its status:
{
"config": {
"batch_size": 5000,
"parallel_batches": 2,
"incremental_enabled": true
},
"stats": {
"files_scanned": 1500,
"files_skipped": 3200,
"items_stored": 45000
}
}files_skipped: Number of unchanged files skipped (incremental mode)batch_size: Current batch size in useparallel_batches: Current parallelism level
To force a full re-index when incremental indexing is enabled:
# Clear all file hashes from Redis
redis-cli -h <database-ip> -n 11 KEYS "codebase:file_hash:*" | xargs redis-cli -h <database-ip> -n 11 DELOr temporarily disable incremental indexing:
export CODEBASE_INDEX_INCREMENTAL=false
# Run indexing
# Then re-enable
export CODEBASE_INDEX_INCREMENTAL=true- Algorithm: SHA-256
- Chunk size: 64KB (memory-efficient for large files)
- Storage: Redis key
codebase:file_hash:{relative_path} - Database: Redis DB 11 (analytics)
- Default batch size: 5000 items
- ChromaDB embedding: Uses default
ONNXMiniLM_L6_V2model - Parallel execution: Uses
asyncio.gather()for concurrent batches
autobot-backend/api/codebase_analytics/scanner.py- Main indexing logicautobot-backend/api/codebase_analytics/storage.py- ChromaDB/Redis connectionsautobot-backend/utils/chromadb_client.py- ChromaDB client utilities
- Enable incremental indexing
- Increase batch size
- Increase parallel batches (if stable)
- Decrease batch size
- Set parallel batches to 1
- Clear file hash cache (see above)
- Check Redis connectivity
- Temporarily disable incremental indexing
- Reduce parallel batches to 1
- Check ChromaDB logs for specific errors