# llama_index.core.storage.kvstore.simple_kvstore:ValueError: 'index_store.json'文件已损坏或包含无效的JSON。

- **ID:** `llm/llamaindex-persistence-corruption`
- **领域:** llm
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

LlamaIndex持久化文件'index_store.json'因崩溃、并发写入或磁盘满错误而部分写入，导致JSON格式错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| llama-index>=0.10.0 | active | — | — |
| llama-index==0.9.0 | active | — | — |

## 解决方案

1. ```
   删除损坏的持久化目录并从零开始重建索引：
import shutil
import os

persist_dir = './storage'
if os.path.exists(persist_dir):
    shutil.rmtree(persist_dir)

# 然后重建索引
index = VectorStoreIndex.from_documents(documents)
index.storage_context.persist(persist_dir=persist_dir)
   ```
2. ```
   如果有备份，从备份恢复持久化目录：
cp -r ./storage_backup ./storage
# 然后验证
from llama_index.core import StorageContext
storage_context = StorageContext.from_defaults(persist_dir='./storage')
print('验证通过')
   ```

## 无效尝试

- **** — The file contains complex internal state; manual edits often break references between nodes and indices. (90% 失败率)
- **** — LlamaIndex attempts to load the existing file first, and fails before overwriting. (70% 失败率)
