feat(ingestion): reuse content-addressed artifacts across rebuilds - #2467
Open
jasminewensm wants to merge 10 commits into
Open
feat(ingestion): reuse content-addressed artifacts across rebuilds#2467jasminewensm wants to merge 10 commits into
jasminewensm wants to merge 10 commits into
Conversation
Classify parser, VLM, chat, embedding, wiki, and graph ingestion operations. Add provider request counters, pre-cache baseline tests, and cache_status=not_supported observations.
Add versioned normalization, deterministic UUIDv5 identities, duplicate ordinals, and parent-child identity assignment. Persist stable identity separately from random chunk row IDs with non-unique cross-database lookup indexes.
Preserve existing chunk IDs for stable-identity matches and apply ingestion chunk differences transactionally. Define idempotent BatchSave semantics across supported vector stores, use stable point IDs for Qdrant and Milvus, and lazily clean historical random-ID points. Keep embedding recomputation enabled and introduce no artifact cache.
Persist tenant-scoped embedding vectors as derived artifacts and reuse exact-text matches across ingestion operations. Support partial batch hits, binary float32 payloads, lease heartbeats, cancellation cleanup, fail-closed decoding, and cache-aware ingestion observations.
Persist tenant-scoped GraphRAG candidate nodes and relations using the derived-artifact lease protocol. Support partial hits, concurrent claim sharing, lease renewal and takeover, corrupt fallback, deterministic normalization, and current chunk-ID rebinding.
jasminewensm
marked this pull request as ready for review
July 31, 2026 09:35
Author
|
本 PR 已完成实现、自查和上游同步,现在可以开始审查。 相关 Artifact 复用测试已在 Ubuntu 24.04、Go 1.26.0 环境通过,其中包括 Service Race 测试。当前剩余 Workflow 因 PR 来自 Fork,正在等待维护者批准运行。 感谢审查。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🚀 概述
本 PR 将知识重建流程从 “删除全部旧数据并从零重新计算” 改造为 “基于内容寻址的增量复用”。
本实现不仅增加了简单的函数结果缓存,还引入了一套持久化的 Artifact 生命周期与状态对账协议, 使系统能够在不绕过数据库、向量存储、Wiki、图谱和任务实时状态的前提下, 安全复用已经完成的昂贵计算结果。
✅ 核心验证结果
最终效果: 对于本 PR 实现的缓存产物层,首次成功计算后, 相同输入的后续重建不会继续增加对应 Provider 的调用次数。
Fixes #1679
🎯 问题背景
原有的知识重建流程大致如下:
即使底层文档内容完全没有变化,完整的摄取链路仍然会重新执行。 同时,由于 Chunk ID 每次都使用随机 UUID 重新生成,向量、Wiki 引用、 图谱引用以及其他派生产物无法在多次重建之间保持稳定的逻辑身份。
这会导致:
🧭 方案架构
本实现并非简单的 Memoization,而是增加了一套包含所有权、租约、 Payload 校验、精确失效、崩溃恢复和实时状态对账的持久化 Artifact 生命周期。
🧩 已完成的改动
stable_identity和identity_version已接入生产路径的 Artifact 类型
multimodal.ocrmultimodal.captionembedding.vectorwiki.document-mapgraph.chunk-extraction1. 稳定 Chunk 身份与非破坏式差异对账
Chunk 新增以下稳定身份字段:
稳定身份由归一化后的 Chunk 内容和稳定的文档内信息派生。
数据库中的
Chunk.ID仍然与稳定身份分离。 这是有意保留的设计:GORM 软删除后,旧行的数据库主键仍然存在。 如果直接将确定性身份用作数据库主键,相同内容后续重建时可能发生主键冲突。Chunk 对账流程现在会:
同时保留了上游已有的可编辑 Chunk 语义:
ContentRevision;SourceContent;IndexStatus;2. 持久化派生产物仓库
Artifact 支持以下生命周期状态:
每条 Artifact 记录包含以下身份与生命周期信息:
Artifact 仓库支持:
3. OCR 与 Caption 正典产物
多模态 Artifact Key 包含以下相关依赖:
缓存命中时:
多模态正典结果在源头隔离 VLM 的非确定性, 避免 OCR/Caption 的微小随机差异导致下游 Chunk、Embedding、 Wiki 和 Graph Artifact Key 连锁失效。
4. 基于内容寻址的 Embedding 产物
Embedding Artifact Key 包含:
该设计支持:
只有 Embedding 计算结果会被缓存。 向量存储的持久化、清理和对账仍然实时执行。
5. Wiki 单文档 Map 产物
可复用的 Wiki 单文档 Map Payload 包含重建以下结果所需的信息:
缓存中的来源引用使用稳定 Chunk 身份,而不是数据库行 ID。 恢复缓存时,系统会将稳定身份重新绑定到当前有效的 Chunk 数据库行。
Wiki Map 缓存命中后,以下操作仍然实时执行:
Wiki Reduce 被有意排除在缓存范围之外, 因为其结果依赖多个文档当前的实时贡献者集合。
6. GraphRAG 单 Chunk 抽取产物
对于稳定身份和输入均未变化的 Chunk:
图谱持久化仍然实时执行,确保最终图谱始终反映当前有效的文档和 Chunk 状态。
🛡️ 正确性约束
♻️ 缓存边界
🔄 精确失效行为
🔐 恢复机制、租户隔离与 Payload 安全
computingArtifact 可在租约过期后被其他 Worker 接管;🗄️ 数据库与兼容行为
stable_identity和identity_version;derived_artifacts表保存可复用产物状态;✅ 预期行为
内容未变化的重建
对于已经实现缓存的 Artifact 层,首次成功计算之后, 相同输入的后续重建不应继续增加对应 Provider 的调用次数。
文档部分内容发生变化
任务重试或崩溃恢复
🔗 与上游最新代码的兼容性
当前功能分支已经与最新的
upstream/main完成同步。同步过程中保留了上游以下行为:
当前功能分支没有落后于
upstream/main。🧪 验证结果
本实现已在 Windows 本地环境完成聚焦测试,并在与最新上游代码合并后, 通过 GitHub Actions 在 Linux 环境中完成验证。
275191ce12d9af1e01968ec95f6112612982b2d928d97736验收结果
查看关键验收测试
TestIngestionCachesEndToEndAcrossRestartInvalidationAndCrashRecoveryTestIngestionArtifactReuse_ThreeIdenticalRebuildsDoNotIncreaseProviderCallsTestIngestionArtifactReuse_OneChunkChangedTestIngestionArtifactInvalidation_TenantIsolationTestIngestionArtifactPayloads_ContainNoSecretsOrRowIDsTestImageMultimodalArtifactCache_RebuildReusesOCRAndCaptionTestEmbeddingArtifactCachePartialHitPreservesOrderTestWikiMapArtifactSecondRunSkipsPureMapChatAndStillReducesTestWikiMapArtifactHitRebindsStableIdentityToRebuiltRowIDTestGraphExtractArtifactCachePartialHitAcrossChunksTestApplyIngestionChunkReconcile_SQLite_AppliesAtomicManagedDiffTestApplyIngestionChunkReconcile_SQLite_RejectsSupersededAttempt查看 Linux 验证命令
GitHub Actions 日志中的 Node.js 弃用警告来自
actions/checkout@v4和actions/setup-go@v5, 不影响 Go 测试结果。📚 设计文档
🔍 审查指南
查看实现提交列表
ca153da0- 增加摄取链路可观测性基线8d0dfb0a- 持久化稳定的文本 Chunk 身份abe9b59e- 根据稳定身份对文档 Chunk 进行差异对账ff6c297d- 增加持久化派生产物缓存基础设施33af18ad- 缓存 OCR 和 Caption 正典 Artifactce2a612a- 复用基于内容寻址的 Embedding Artifact68c5f3cd- 缓存 Wiki 单文档 Map Artifact063877c7- 缓存 GraphRAG 单 Chunk 抽取 Artifact36750b32- 完善精确失效、恢复、隔离和验收测试275191ce- 与最新 upstream/main 同步并解决兼容问题建议按照以下顺序审查: