Incremental RAG Index Synchronization Tutorial
A tutorial presents a small synchronizer for keeping a RAG knowledge base aligned with changing source files. Python computes content fingerprints and synchronization plans, SQLite stores manifests, and ChromaDB stores chunks. The implementation uses stable document and chunk IDs, idempotent upserts, set-difference deletion, read-back verification, and a final manifest commit to address duplicate ingestion and stale records. Because SQLite and ChromaDB do not share a transaction, the tutorial notes that updates are not strictly atomic, but says deterministic IDs, repeated reconciliation, and upserts can support recovery after interruptions. The author-created implementation has not been validated with production-scale, concurrent, or service deployment workloads.
Unresolved synchronization can cause retrieval to mix obsolete and current document versions, including outdated clauses or product information. The tutorial offers a portable reconciliation protocol intended to make index updates explainable, verifiable, and recoverable without depending on a single vector-database API.
很多 RAG 教程讲到“加载文档—切分—向量化—写入向量库”就结束了。这个流程适合第一次建库,却没有回答知识库上线后更常见的问题:
- 同一个目录每天同步一次,会不会重复入库?
- 文件修改后,旧切片是否还留在向量库?
- 文档从 20 个切片缩短到 12 个,后 8 个怎样清理?
- 源文件被删除后,怎样证明向量和元数据都已删除?
- 同步中途崩溃,下次运行能否自动恢复?
如果这些问题没有明确答案,检索结果中就可能同时出现新旧版本。模型最终引用了旧条款、旧产品说明或过期非遗资料时,单纯调整 Prompt 并不能解决根因。
本文实现一个小型但完整的同步器:Python 负责计算内容指纹和同步计划,SQLite 保存同步清单,ChromaDB 保存切片。重点不是某个向量库 API,而是一套可以迁移到其他存储的对账协议。