> ## Documentation Index
> Fetch the complete documentation index at: https://docs.memvid.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Maintenance & Repair

> Verify integrity, repair files, and manage your memory files

Commands for maintaining the health and integrity of your memory files.

***

## Verify

Check file integrity without modification.

### Basic Usage

```bash theme={null}
memvid verify knowledge.mv2
```

### Options

| Option   | Description               |
| -------- | ------------------------- |
| `--deep` | Run thorough verification |
| `--json` | Output as JSON            |

### Examples

```bash theme={null}
# Quick verification
memvid verify knowledge.mv2

# Deep verification (slower, more thorough)
memvid verify knowledge.mv2 --deep

# JSON output for automation
memvid verify knowledge.mv2 --deep --json
```

**Output:**

```
Verifying: knowledge.mv2

Checks:
  [PASS] HeaderChecksum
  [PASS] TocIntegrity
  [PASS] WalConsistency
  [PASS] TimeIndexSortOrder
  [PASS] LexIndexDecode
  [PASS] VecIndexDecode
  [PASS] FrameCountConsistency

Overall: PASSED
```

**JSON Output:**

```json theme={null}
{
  "file_path": "knowledge.mv2",
  "checks": [
    { "name": "HeaderChecksum", "status": "passed" },
    { "name": "TocIntegrity", "status": "passed" },
    { "name": "WalConsistency", "status": "passed" },
    { "name": "TimeIndexSortOrder", "status": "passed" },
    { "name": "LexIndexDecode", "status": "passed" },
    { "name": "VecIndexDecode", "status": "passed" },
    { "name": "FrameCountConsistency", "status": "passed" }
  ],
  "overall_status": "passed"
}
```

### Exit Codes

* `0` - All checks passed
* Non-zero - One or more checks failed

***

## Doctor

Diagnose and repair issues with memory files.

### Basic Usage

```bash theme={null}
memvid doctor knowledge.mv2
```

### Options

| Option                 | Description                       |
| ---------------------- | --------------------------------- |
| `--plan-only`          | Preview repairs without applying  |
| `--rebuild-time-index` | Rebuild the time index            |
| `--rebuild-lex-index`  | Rebuild the lexical index         |
| `--rebuild-vec-index`  | Rebuild the vector index          |
| `--vacuum`             | Compact and reclaim deleted space |
| `--json`               | Output as JSON                    |

### Examples

```bash theme={null}
# Preview what would be fixed
memvid doctor knowledge.mv2 --plan-only

# Rebuild corrupted time index
memvid doctor knowledge.mv2 --rebuild-time-index

# Rebuild lexical index
memvid doctor knowledge.mv2 --rebuild-lex-index

# Rebuild vector index
memvid doctor knowledge.mv2 --rebuild-vec-index

# Compact deleted frames and reclaim space
memvid doctor knowledge.mv2 --vacuum

# Fix multiple issues at once
memvid doctor knowledge.mv2 --rebuild-time-index --rebuild-lex-index

# Full repair and optimization
memvid doctor knowledge.mv2 \
  --rebuild-time-index \
  --rebuild-lex-index \
  --rebuild-vec-index \
  --vacuum
```

**Output:**

```
Doctor Report: knowledge.mv2

Findings:
  [WARN] Time index has 3 out-of-order entries
  [INFO] 12 deleted frames can be vacuumed

Planned Actions:
  1. Rebuild time index
  2. Vacuum deleted frames

Executing repairs...
  [DONE] Time index rebuilt (148 entries)
  [DONE] Vacuumed 12 frames, reclaimed 2.3 MB

Complete.
```

### Severity Levels

| Level   | Description                         |
| ------- | ----------------------------------- |
| `INFO`  | Informational, no action needed     |
| `WARN`  | Potential issue, repair recommended |
| `ERROR` | Problem found, repair required      |

***

## Verify Single File

Ensure no auxiliary files exist alongside your memory file.

### Basic Usage

```bash theme={null}
memvid verify-single-file knowledge.mv2
```

This checks that the directory contains only the `.mv2` file with no leftover sidecars:

* No `.wal` files
* No `.shm` files
* No `.lock` files
* No `-wal` files
* No hidden siblings

### Example

```bash theme={null}
$ memvid verify-single-file knowledge.mv2
Single-file check: PASSED
No auxiliary files found.
```

If sidecars are found:

```bash theme={null}
$ memvid verify-single-file knowledge.mv2
Single-file check: FAILED
Found auxiliary files:
  - knowledge.mv2-wal
  - knowledge.mv2.lock

Remove these files and re-verify.
```

***

## Common Maintenance Tasks

### After Crashes

If your application crashed while writing:

```bash theme={null}
# Verify integrity
memvid verify knowledge.mv2 --deep

# If issues found, run doctor
memvid doctor knowledge.mv2 --plan-only

# Apply repairs if needed
memvid doctor knowledge.mv2 --rebuild-time-index
```

### Reclaiming Space

After deleting many frames:

```bash theme={null}
# Check current stats
memvid stats knowledge.mv2

# Vacuum to reclaim space
memvid doctor knowledge.mv2 --vacuum

# Verify results
memvid stats knowledge.mv2
```

### Rebuilding Indices

If search isn't working correctly:

```bash theme={null}
# Check index status
memvid stats knowledge.mv2 --json | grep has_lex_index

# Rebuild lexical index
memvid doctor knowledge.mv2 --rebuild-lex-index

# Rebuild vector index
memvid doctor knowledge.mv2 --rebuild-vec-index

# Verify search works
memvid find knowledge.mv2 --query "test"
```

### Cleaning Up Old Files

Remove leftover files from older versions:

```bash theme={null}
# Check for sidecars
ls -la knowledge.mv2*

# Remove any found
rm -f knowledge.mv2-wal knowledge.mv2-shm knowledge.mv2.lock

# Verify clean state
memvid verify-single-file knowledge.mv2
```

***

## Environment Variables

| Variable                   | Description                | Default            |
| -------------------------- | -------------------------- | ------------------ |
| `MEMVID_MODELS_DIR`        | Model cache directory      | `~/.memvid/models` |
| `MEMVID_CACHE_DIR`         | General cache directory    | `~/.cache/memvid`  |
| `MEMVID_OFFLINE`           | Skip model downloads       | `false`            |
| `MEMVID_PARALLEL_SEGMENTS` | Control parallel ingestion | Auto               |

### Setting Environment Variables

```bash theme={null}
# Set model directory
export MEMVID_MODELS_DIR=~/.memvid/models

# Enable offline mode
export MEMVID_OFFLINE=1

# Enable parallel ingestion
export MEMVID_PARALLEL_SEGMENTS=1
```

***

## Debug Commands

### Version

Check CLI version:

```bash theme={null}
memvid version
```

### Debug Segment

Inspect internal vector segment data (advanced):

```bash theme={null}
# View segment metadata
memvid debug-segment knowledge.mv2 --segment-id 1

# Include hex dump
memvid debug-segment knowledge.mv2 --segment-id 1 --hex-dump --max-bytes 512
```

### Verbose Output

Enable debug logging:

```bash theme={null}
# Increase verbosity
memvid -v verify knowledge.mv2       # WARN level
memvid -vv verify knowledge.mv2      # INFO level
memvid -vvv verify knowledge.mv2     # DEBUG level
memvid -vvvv verify knowledge.mv2    # TRACE level
```

***

## Troubleshooting

### Time Index Corruption

**Symptom:**

```
TimeIndexSortOrder: Failed
```

**Solution:**

```bash theme={null}
memvid doctor knowledge.mv2 --rebuild-time-index
memvid verify knowledge.mv2 --deep
```

### Lexical Index Issues

**Symptom:**

* Search returns no results
* `has_lex_index: false` in stats

**Solution:**

```bash theme={null}
memvid doctor knowledge.mv2 --rebuild-lex-index
```

### Vector Index Issues

**Symptom:**

* Semantic search not working
* `has_vec_index: false` in stats

**Solution:**

```bash theme={null}
memvid doctor knowledge.mv2 --rebuild-vec-index
```

### Capacity Issues

**Symptom:**

```
Error: CapacityExceeded
```

**Solutions:**

```bash theme={null}
# Check current usage
memvid stats knowledge.mv2

# Delete unused frames
memvid delete knowledge.mv2 --frame-id 42 --yes

# Vacuum to reclaim space
memvid doctor knowledge.mv2 --vacuum
```

### Lock Issues

**Symptom:**

```
Error: File is locked by another process
```

**Solutions:**

```bash theme={null}
# Check who holds the lock
memvid who knowledge.mv2

# Request release
memvid nudge knowledge.mv2

# Find process (macOS/Linux)
lsof knowledge.mv2
```

***

## Best Practices

### Regular Maintenance

1. **Verify periodically**: Run `memvid verify --deep` weekly or after major ingestion
2. **Vacuum after deletions**: Run `--vacuum` after deleting significant content
3. **Monitor capacity**: Check `memvid stats` before large ingestions

### Before Sharing Files

1. Verify integrity: `memvid verify knowledge.mv2 --deep`
2. Check single-file: `memvid verify-single-file knowledge.mv2`
3. Review stats: `memvid stats knowledge.mv2`

### After System Updates

1. Verify existing files still work
2. Rebuild indices if search behaves differently
3. Check for any deprecated features

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Create & Ingest" icon="plus" href="/cli/create-and-put">
    Add more content to your memories
  </Card>

  <Card title="Search & Ask" icon="magnifying-glass" href="/cli/search-and-ask">
    Query your memories
  </Card>
</CardGroup>
