# chromadb.errors.InternalError: 检测到索引损坏，需要重建。

- **ID:** `llm/embedding-vector-index-corruption-after-reindex`
- **领域:** llm
- **类别:** data_error
- **错误码:** `CHROMA-ERR-0042`
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

当重建索引操作因崩溃或网络断开而中断时，ChromaDB 索引文件损坏，导致 HNSW 图处于不一致状态。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| chromadb==0.4.22 | active | — | — |
| chromadb==0.5.0 | active | — | — |
| langchain-chroma==0.1.0 | active | — | — |

## 解决方案

1. ```
   识别损坏的集合，删除它，然后重新摄取源文档：client.delete_collection('my_collection'); client.create_collection('my_collection'); 然后重新嵌入所有文档。对于生产环境，将源文档备份到独立存储（如 S3），并编写一个重新嵌入的脚本。
   ```
2. ```
   使用 ChromaDB 的内置持久性检查：运行 'chroma run --path /path/to/persist --debug' 并查找 'HNSW index integrity check failed'。然后使用 Python 客户端修复：collection._client._admin_client.reset_collection('my_collection')（需要管理员权限）。
   ```
3. ```
   设置一个 cron 任务，定期使用 chromadb.api.types.validate_metadata 验证索引完整性，并在任何重建索引操作之前对持久性目录进行快照。
   ```

## 无效尝试

- **** — The corrupted HNSW graph persists on disk; restarting doesn't repair the structural damage, and the same corrupted files are loaded again. (95% 失败率)
- **** — reset() wipes all data, not just the corrupted index, causing data loss for unrelated collections. It's a nuclear option that destroys all embeddings. (98% 失败率)
- **** — If the original embedding source data is lost or not backed up, you cannot recreate the index. This only works if you have the raw documents and can re-embed them. (70% 失败率)
