/agentsop-idempotent-ingestion
Re-ingest-correctness SOP for production RAG. Activate when a calling agent builds, reviews, or debugs an ingestion pipeline that runs more than once over a changing corpus — scheduled re-index, incremental updates, CI re-ingest, or a "retrieval has duplicates / shows deleted
$ npx -y skills add agentsope/SkillAlchemy --skill agentsop-idempotent-ingestion --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/agentsop-idempotent-ingestion
Context preview
The summary Claude sees to decide when to auto-load this skill.
Re-ingest-correctness SOP for production RAG. Activate when a calling agent builds, reviews, or debugs an ingestion pipeline that runs more than once over a changing corpus — scheduled re-index, incremental updates, CI re-ingest, or a "retrieval has duplicates / shows deleted
SKILL.md
agentsop-idempotent-ingestion.SKILL.mdname: agentsop-idempotent-ingestion
version: 0.1.0
description: |
Re-ingest-correctness SOP for production RAG. Activate when a calling agent
builds, reviews, or debugs an ingestion pipeline that runs more than once over
a changing corpus — scheduled re-index, incremental updates, CI re-ingest, or
a "retrieval has duplicates / shows deleted docs" bug. Encodes the rule —
**ingestion must be idempotent: a document's content hash decides
insert/update/skip, so re-running over unchanged docs is a no-op** — plus the
docstore + doc-hash upsert machinery (LlamaIndex `IngestionPipeline` +
`DocstoreStrategy`), the delete-propagation problem, and cross-framework
equivalents (LangChain `index()` + `RecordManager`, manual hash table). ENHANCE
overlay over [[llamaindex]]: the IngestionPipeline exists in the base skill but
the re-ingest-correctness contract is not surfaced.
trigger_keywords:
- "idempotent ingestion"
- "re-ingest"
- "re-index"
- "docstore"
- "doc hash"
- "upsert"
- "duplicate chunks"
- "IngestionPipeline"
- "RecordManager"
- "incremental update"
- "scheduled reindex"
when_to_use:
- "any ingestion pipeline that will run more than once (cron, CI, webhook, manual re-run)"
- "a corpus where source documents are added, edited, or deleted over time"
- "debugging duplicate / stale chunks polluting retrieval after a re-run"
- "reviewing a PR that calls VectorStoreIndex.from_documents / pipeline.run without a docstore"
- "designing the ingestion side of a production RAG before first deploy"
when_not_to_use:
- "a one-shot index built once and never refreshed (static corpus, throwaway notebook)"
- "the corpus is small enough to fully rebuild from scratch in seconds and rebuild-on-every-run is genuinely acceptable (measure first)"
- "pure retrieval / query-time work with no ingestion path"
Idempotent Ingestion · Re-Ingest-Correctness SOP
> Third-person operating model for a coder agent that owns ingestion > correctness across repeated runs. The audience is the LLM agent writing or > reviewing the pipeline code — not the end user.
> **One sentence**: *The interesting run is the second one. A correct pipeline > hashes each document, looks the hash up in a docstore, and inserts / updates > / skips accordingly — so re-running over unchanged docs changes nothing.*
This skill is an **ENHANCE overlay** over [[llamaindex]]. The base skill names `IngestionPipeline` with `docstore` + `UPSERTS_AND_DELETE` as a hardening must-have (OP-08, anti-pattern A10) but stops at "use it". This overlay surfaces the *correctness contract* — what idempotency actually means, how the hash decides the action, and how it generalises beyond LlamaIndex.
---
1. 何时激活 (Activation Rules)
Activate this skill whenever **any** of the following holds:
1. The codebase contains an ingestion call (`VectorStoreIndex.from_documents`, `pipeline.run(documents=...)`, `vectorstore.add_documents`, a custom embed
- upsert loop) **and** that call will execute more than once over a corpus
that can change between runs. 2. The user mentions any of: re-ingest, re-index, scheduled / nightly index refresh, incremental document updates, docstore, doc hash, upsert, `RecordManager`, "keep the index in sync with the source". 3. A bug report says "I see the same answer chunk twice", "retrieval returns duplicates", "deleted a file but it still shows up in answers", "the index keeps growing every night even though nothing changed". 4. PR review: new ingestion code that builds the index with no docstore / no hash-keyed dedup and the corpus is live (LlamaIndex base skill A10). 5. A production RAG is about to ship and the ingestion side has only ever been tested as a cold first run.
Do **not** activate when:
- The index is built **once** from a static corpus and never refreshed — there
is no second run to make idempotent.
- The corpus is tiny and rebuilding from scratch each run is *measurably*
cheaper than maintaining a docstore (rare; verify, don't assume).
- The task is purely query-time (retrieval, rerank, synthesis) with no
ingestion path in scope.
---
2. 核心心智模型 (Core Mental Model)
Three principles. Violating any one means a second run can duplicate or corrupt the index — regardless of how good the retrieval stack downstream is.
Principle 1 — Ingestion must be idempotent; the hash is the decision
> **Re-running the pipeline over an unchanged document is a no-op.** Run it > once, run it a thousand times — same index. The mechanism: each document is > reduced to a stable **content hash** (and a stable **doc id**); that hash is > looked up in a **docstore** (a key→hash record store separate from the vector > store); the lookup result decides the action.
doc_id seen? hash changed?
│ │
┌────────────┴───────────┐ ┌──────┴──────┐
no yes no yes
│ │ │ │
INSERT (embed + upsert) │ SKIP UPDATE
└──────────────►(delete old chunks,
re-embed, upsert)The hash is the whole game. Without it, the pipeline cannot tell "I have seen this exact content" from "this is new" — so it re-embeds and re-adds everything, and the vector store accumulates duplicates. (LlamaIndex base skill failure #3 / A10; `developers.llamaindex.ai/.../loading/ingestion_pipeline/`.)
Principle 2 — The docstore is a separate ledger, not the vector store
The vector store holds embeddings keyed by node id. The **docstore** holds, per document, `{doc_id → content_hash}` (and the node ids derived from it). They are two stores with two jobs:
| Store | Holds | Answers | |---|---|---| | Docstore | `doc_id → hash`, doc→node mapping | "have I seen this content before?" | | Vector store | `node_id → embedding + metadata` | "what is semantically ne
Read more
name: agentsop-idempotent-ingestion version: 0.1.0 description: | Re-ingest-correctness SOP for production RAG. Activate when a calling agent builds, reviews, or debugs an ingestion pipeline that runs more than once over a changing corpus — scheduled re-index, incremental updates, CI re-ingest, or a "retrieval has duplicates / shows deleted docs" bug. Encodes the rule — **ingestion must be idempotent: a document's content hash decides insert/update/skip, so re-running over unchanged docs is a no-op** — plus the docstore + doc-hash upsert machinery (LlamaIndex `IngestionPipeline` + `DocstoreStrategy`), the delete-propagation problem, and cross-framework equivalents (LangChain `index()` + `RecordManager`, manual hash table). ENHANCE overlay over [[llamaindex]]: the IngestionPipeline exists in the base skill but the re-ingest-correctness contract is not surfaced. trigger_keywords: - "idempotent ingestion" - "re-ingest" - "re-index" - "docstore" - "doc hash" - "upsert" - "duplicate chunks" - "IngestionPipeline" - "RecordManager" - "incremental update" - "scheduled reindex" when_to_use: - "any ingestion pipeline that will run more than once (cron, CI, webhook, manual re-run)" - "a corpus where source documents are added, edited, or deleted over time" - "debugging duplicate / stale chunks polluting retrieval after a re-run" - "reviewing a PR that calls VectorStoreIndex.from_documents / pipeline.run without a docstore" - "designing the ingestion side of a production RAG before first deploy" when_not_to_use: - "a one-shot index built once and never refreshed (static corpus, throwaway notebook)" - "the corpus is small enough to fully rebuild from scratch in seconds and rebuild-on-every-run is genuinely acceptable (measure first)" - "pure retrieval / query-time work with no ingestion path"
Idempotent Ingestion · Re-Ingest-Correctness SOP
> Third-person operating model for a coder agent that owns ingestion > correctness across repeated runs. The audience is the LLM agent writing or > reviewing the pipeline code — not the end user.
> **One sentence**: *The interesting run is the second one. A correct pipeline > hashes each document, looks the hash up in a docstore, and inserts / updates > / skips accordingly — so re-running over unchanged docs changes nothing.*
This skill is an **ENHANCE overlay** over [[llamaindex]]. The base skill names `IngestionPipeline` with `docstore` + `UPSERTS_AND_DELETE` as a hardening must-have (OP-08, anti-pattern A10) but stops at "use it". This overlay surfaces the *correctness contract* — what idempotency actually means, how the hash decides the action, and how it generalises beyond LlamaIndex.
---
1. 何时激活 (Activation Rules)
Activate this skill whenever **any** of the following holds:
1. The codebase contains an ingestion call (`VectorStoreIndex.from_documents`, `pipeline.run(documents=...)`, `vectorstore.add_documents`, a custom embed
- upsert loop) **and** that call will execute more than once over a corpus
that can change between runs. 2. The user mentions any of: re-ingest, re-index, scheduled / nightly index refresh, incremental document updates, docstore, doc hash, upsert, `RecordManager`, "keep the index in sync with the source". 3. A bug report says "I see the same answer chunk twice", "retrieval returns duplicates", "deleted a file but it still shows up in answers", "the index keeps growing every night even though nothing changed". 4. PR review: new ingestion code that builds the index with no docstore / no hash-keyed dedup and the corpus is live (LlamaIndex base skill A10). 5. A production RAG is about to ship and the ingestion side has only ever been tested as a cold first run.
Do **not** activate when:
- The index is built **once** from a static corpus and never refreshed — there
is no second run to make idempotent.
- The corpus is tiny and rebuilding from scratch each run is *measurably*
cheaper than maintaining a docstore (rare; verify, don't assume).
- The task is purely query-time (retrieval, rerank, synthesis) with no
ingestion path in scope.
---
2. 核心心智模型 (Core Mental Model)
Three principles. Violating any one means a second run can duplicate or corrupt the index — regardless of how good the retrieval stack downstream is.
Principle 1 — Ingestion must be idempotent; the hash is the decision
> **Re-running the pipeline over an unchanged document is a no-op.** Run it > once, run it a thousand times — same index. The mechanism: each document is > reduced to a stable **content hash** (and a stable **doc id**); that hash is > looked up in a **docstore** (a key→hash record store separate from the vector > store); the lookup result decides the action.
doc_id seen? hash changed?
│ │
┌────────────┴───────────┐ ┌──────┴──────┐
no yes no yes
│ │ │ │
INSERT (embed + upsert) │ SKIP UPDATE
└──────────────►(delete old chunks,
re-embed, upsert)The hash is the whole game. Without it, the pipeline cannot tell "I have seen this exact content" from "this is new" — so it re-embeds and re-adds everything, and the vector store accumulates duplicates. (LlamaIndex base skill failure #3 / A10; `developers.llamaindex.ai/.../loading/ingestion_pipeline/`.)
Principle 2 — The docstore is a separate ledger, not the vector store
The vector store holds embeddings keyed by node id. The **docstore** holds, per document, `{doc_id → content_hash}` (and the node ids derived from it). They are two stores with two jobs:
| Store | Holds | Answers | |---|---|---| | Docstore | `doc_id → hash`, doc→node mapping | "have I seen this content before?" | | Vector store | `node_id → embedding + metadata` | "what is semantically ne
Other skills on skillalchemy.
- /LEAP
LEAP — 落地执行引擎。内含两条管线:A 分支蒸馏(从 raw data 提取 skill)、 B 分支融合(多 skill 编织为一个)。被 SkillAlchemy 编排器调用。 Use when 编排器判断需要蒸馏或融合时。
Open skill - /Lens
Lens — 给你的问题加一层认知镜片。输入任意任务描述,输出增强版 description, 发现「你不知道自己不知道」的隐性维度、前置条件和认知路线。 Use when 用户说「帮我想想」「分析一下」「生成 skill」「蒸馏」「融合」 或输入看起来太简单需要展开。
Open skill - /agentsop-agent-topology-selection
Cross-framework enhancement overlay for choosing a multi-agent topology BEFORE writing any agent. A binary-question rubric — is single-agent + tools enough? do agents need to know about each other? does the output need one voice? — maps the answer to single-agent / supervisor /
Open skill - /agentsop-aider
SOP for terminal-based, git-native AI pair programming with Aider (git work-tree + tree-sitter repo-map + edit-format + human-in-loop REPL). Use when editing code in an existing git repo via an LLM, when you need to converge a change to 2-5 files, pick an edit format that fits
Open skill - /agentsop-bio-fraud-forensics
Screens biomedical / life-science papers for signs of data fabrication, image manipulation, and statistical anomalies, using the detection techniques distilled from the field's canonical exposure platforms (PubPeer, Data Colada, Science Integrity Digest, For Better Science) and
Open skill - /agentsop-bounded-loop
Universal discipline for any LM-driven loop — agent retries, plan-act-observe, multi-agent handoffs, optimiser passes, test-fix cycles. Encodes the one rule every framework documents quietly and every team relearns expensively: the LM in the loop is NEVER a reliable terminator.
Open skill

