Skip to content

Commit 483704e

Browse files
committed
fix: improve long model download handling and first-time startup experience
- Increase health check timeouts to accommodate large model downloads (~300-500MB) - Add informative messages about expected first-time download delays - Add FAST_STARTUP environment variable option for quicker initialization - Update documentation with startup time expectations and solutions - Ensure project_initializer respects EMBEDDING_MODEL env variable - Improve troubleshooting information for timeout issues
1 parent 6ddaf6a commit 483704e

File tree

6 files changed

+77
-21
lines changed

6 files changed

+77
-21
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ ENV PYTHONUNBUFFERED=1 \
2525
PYTHONDONTWRITEBYTECODE=1
2626

2727
# Health check
28-
HEALTHCHECK --interval=30s --timeout=30s --start-period=30s --retries=3 \
28+
# Note: First run will download large embedding models which can take several minutes
29+
# The run.sh script handles this with a longer timeout, but Docker health checks need to be configured too
30+
HEALTHCHECK --interval=30s --timeout=30s --start-period=600s --retries=10 \
2931
CMD curl -f http://localhost:8000/health || exit 1
3032

3133
# Command to run when container starts

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,27 @@ The service will:
5050

5151
Files-DB-MCP works without configuration, but you can customize it with environment variables:
5252

53-
- `EMBEDDING_MODEL` - Change the embedding model (default: 'sentence-transformers/all-MiniLM-L6-v2')
53+
- `EMBEDDING_MODEL` - Change the embedding model (default: 'jinaai/jina-embeddings-v2-base-code' or project-specific model)
54+
- `FAST_STARTUP` - Set to 'true' to use a smaller model for faster startup (default: 'false')
5455
- `QUANTIZATION` - Enable/disable quantization (default: 'true')
5556
- `BINARY_EMBEDDINGS` - Enable/disable binary embeddings (default: 'false')
5657
- `IGNORE_PATTERNS` - Comma-separated list of files/dirs to ignore
5758

59+
### First-Time Startup
60+
61+
On first run, Files-DB-MCP will download embedding models which may take several minutes depending on:
62+
- The size of the selected model (300-500MB for high-quality models)
63+
- Your internet connection speed
64+
65+
Subsequent startups will be much faster as models are cached. For faster initial startup, you can:
66+
```bash
67+
# Use a smaller, faster model (90MB)
68+
EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2 files-db-mcp
69+
70+
# Or enable fast startup mode
71+
FAST_STARTUP=true files-db-mcp
72+
```
73+
5874
## Claude Code Integration
5975

6076
Add to your Claude Code configuration:

docker-compose.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ services:
2121
environment:
2222
- VECTOR_DB_HOST=vector-db
2323
- VECTOR_DB_PORT=6333
24-
- EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2 # Default code embedding model
24+
- EMBEDDING_MODEL=${EMBEDDING_MODEL:-sentence-transformers/all-MiniLM-L6-v2} # Default code embedding model
25+
# For faster startup, you can set EMBEDDING_MODEL to a smaller model:
26+
# Example: export EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2
27+
- FAST_STARTUP=${FAST_STARTUP:-false} # Set to 'true' to prioritize faster startup over quality
2528
- QUANTIZATION=true # Enable quantization by default
2629
- BINARY_EMBEDDINGS=false # Disable binary embeddings by default
2730
- DEBUG=true # Enable debug mode
@@ -33,9 +36,9 @@ services:
3336
healthcheck:
3437
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
3538
interval: 30s
36-
timeout: 20s
37-
retries: 5
38-
start_period: 180s # Give more time for model downloads
39+
timeout: 30s
40+
retries: 10
41+
start_period: 600s # Give much more time for large model downloads
3942

4043
volumes:
4144
qdrant_data:

docs/troubleshooting.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,37 @@ This guide helps you diagnose and solve common issues with Files-DB-MCP.
4242
- Ensure vector database is running and accessible
4343
- Check environment variables are properly set
4444

45-
### Health Check Fails
45+
### Health Check Fails or Long Startup Time
4646

4747
**Symptoms:**
48-
- Container shows "unhealthy" status
49-
- Service starts but health check fails
48+
- Container shows "unhealthy" status or "starting" for a long time
49+
- Timeout message: "Timeout waiting for MCP service to become healthy"
50+
- First run takes much longer than expected
51+
52+
**Causes:**
53+
- First startup requires downloading large embedding models (300-500MB)
54+
- Default timeout may be too short for large model downloads
55+
- Slow internet connection can extend download time
5056

5157
**Check:**
52-
1. **Health Check Response:**
58+
1. **Container Logs for Download Progress:**
59+
```bash
60+
docker logs files-db-mcp-files-db-mcp-1
61+
```
62+
Look for "Downloading model.safetensors" progress messages.
63+
64+
2. **Health Check Response:**
5365
```bash
5466
curl http://localhost:3000/health
5567
```
5668

57-
2. **Health Check Configuration:** Check the health check timeout in `docker-compose.yml`
69+
3. **Health Check Configuration:** Check the health check timeout in `docker-compose.yml`
5870

5971
**Solutions:**
60-
- Increase health check timeout for model loading
61-
- Check if the vector database is properly connected
62-
- Verify network settings between containers
72+
- Be patient during first startup - subsequent starts will be much faster
73+
- Increase health check start_period in docker-compose.yml to 600s or more
74+
- Increase timeout in scripts/run.sh to 600 seconds or more
75+
- Switch to a smaller embedding model by setting EMBEDDING_MODEL environment variable
6376

6477
## Docker Compose Issues
6578

scripts/run.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,18 @@ COMPOSE_HTTP_TIMEOUT=300 docker compose -f "$BASE_DIR/docker-compose.yml" up --b
7171
echo
7272
echo "Files-DB-MCP is starting up..."
7373
echo "Waiting for services to initialize..."
74+
echo "Note: First run requires downloading embedding models (~300-500MB) which may take several minutes."
75+
echo " Future startups will be much faster as models are cached."
7476

7577
# Get the actual container names as they might be different
7678
MCP_CONTAINER=$(docker compose -f "$BASE_DIR/docker-compose.yml" ps -q files-db-mcp)
7779
VECTOR_DB_CONTAINER=$(docker compose -f "$BASE_DIR/docker-compose.yml" ps -q vector-db)
7880

7981
echo "Container IDs: MCP=$MCP_CONTAINER, Vector DB=$VECTOR_DB_CONTAINER"
8082

81-
# Wait up to 2 minutes for MCP to become healthy
82-
timeout=120
83-
interval=5
83+
# Wait up to 10 minutes for MCP to become healthy (especially for first-time model downloads)
84+
timeout=600
85+
interval=10
8486
elapsed=0
8587

8688
echo "Waiting for MCP service to become healthy..."

src/project_initializer.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,22 @@ def select_embedding_model(self) -> Tuple[str, Dict[str, Any]]:
312312
Returns:
313313
Tuple of (model_name, model_config)
314314
"""
315-
# Check if we have a custom config
316-
if self.config_file.exists():
315+
# First check environment variable for FAST_STARTUP mode
316+
fast_startup = os.environ.get("FAST_STARTUP", "false").lower() == "true"
317+
318+
# Check if embedding model is explicitly set in environment
319+
env_model = os.environ.get("EMBEDDING_MODEL")
320+
if env_model:
321+
logger.info(f"Using embedding model from environment: {env_model}")
322+
self.embedding_model = env_model
323+
# Keep default config but allow overrides from config file
324+
if self.primary_project_type in DEFAULT_MODEL_CONFIGS:
325+
self.model_config = DEFAULT_MODEL_CONFIGS[self.primary_project_type].copy()
326+
else:
327+
self.model_config = DEFAULT_MODEL_CONFIGS["default"].copy()
328+
329+
# Check if we have a custom config file
330+
elif self.config_file.exists():
317331
try:
318332
with open(self.config_file, "r") as f:
319333
config = json.load(f)
@@ -327,8 +341,14 @@ def select_embedding_model(self) -> Tuple[str, Dict[str, Any]]:
327341
except Exception as e:
328342
logger.warning(f"Error reading config file: {e!s}")
329343

330-
# Use default model for the primary project type
331-
if self.primary_project_type in DEFAULT_EMBEDDING_MODELS:
344+
# If fast startup is requested, use the smallest model
345+
elif fast_startup:
346+
logger.info("FAST_STARTUP is enabled, using lightweight embedding model")
347+
self.embedding_model = "sentence-transformers/all-MiniLM-L6-v2" # Smallest model ~90MB
348+
self.model_config = DEFAULT_MODEL_CONFIGS["default"].copy()
349+
350+
# Otherwise use default model for the primary project type
351+
elif self.primary_project_type in DEFAULT_EMBEDDING_MODELS:
332352
self.embedding_model = DEFAULT_EMBEDDING_MODELS[self.primary_project_type]
333353
self.model_config = DEFAULT_MODEL_CONFIGS[self.primary_project_type].copy()
334354
else:

0 commit comments

Comments
 (0)