rag-lifecycle-management

rag-lifecycle-management is a command for Claude Code from lucky-aeon/AgentX. It costs 0 tokens per session (2,038 once invoked), scanned A, original, Apache-2.0.

A design and implementation proposal for managing RAG systems. RAG, or retrieval-augmented generation, lets an agent answer using information from document collections.

In plain words
What is it for?
Use it to plan database changes and installation rules that distinguish live references from fixed snapshots and let users switch between available RAG versions.
Why use it?
It addresses the difficulty of updating private document collections, switching versions, and keeping data sources consistent.

Command for Claude Code

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/lucky-aeon/agentx/rag-lifecycle-management
Clone the repo
git clone --depth 1 https://github.com/lucky-aeon/AgentX

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for rag-lifecycle-management

README.md
[![agentmods](https://agentmods.dev/badge/commands/lucky-aeon/agentx/rag-lifecycle-management.svg)](https://agentmods.dev/commands/lucky-aeon/agentx/rag-lifecycle-management)
Your own site
<a href="https://agentmods.dev/commands/lucky-aeon/agentx/rag-lifecycle-management"><img src="https://agentmods.dev/badge/commands/lucky-aeon/agentx/rag-lifecycle-management.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,038 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.02038
Opus 5 $0.00000 $0.01019
Sonnet 5 $0.00000 $0.00408
Haiku 4.5 $0.00000 $0.00204

Measured 5d ago against content hash 3c8e97232f53, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

rag-lifecycle-management scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/commands/rag-lifecycle-management.md · 243 lines

How it starts

The opening of the file, as written. The whole thing — 243 lines — stays where its author put it; the contents beside it link to each section on GitHub.

RAG生命周期管理重构方案

问题背景

当前RAG管理系统存在以下核心问题:

  1. 私有RAG使用困难:用户创建的RAG添加新文档后,需要重新发布并审核才能在Agent中使用最新数据
  2. 版本管理不灵活:每个版本需要单独安装,无法像工具市场一样在已安装RAG中切换版本
  3. 数据来源不统一:Agent需要从多个数据源获取RAG,增加了复杂度

解决方案

核心设计思路

引入动态引用机制,区分两种安装类型:

  • REFERENCE类型:引用原始数据集,支持实时更新(用于私有RAG)
  • SNAPSHOT类型:使用版本快照,内容固定(用于公开RAG)

版本管理模式

对标工具市场的版本管理:

  1. 安装RAG本身(而不是特定版本)
  2. 支持在已安装RAG中切换版本
  3. 统一从user_rags表获取可用RAG

技术实施方案

1. 数据库表结构调整

user_rags表重新设计
ALTER TABLE user_rags ADD COLUMN original_rag_id VARCHAR(64) COMMENT '原始RAG数据集ID';
ALTER TABLE user_rags ADD COLUMN install_type VARCHAR(20) DEFAULT 'SNAPSHOT' COMMENT '安装类型:REFERENCE/SNAPSHOT';
ALTER TABLE user_rags ADD COLUMN current_version_id VARCHAR(64) COMMENT '当前选择的版本ID';

-- 为向后兼容,保留 rag_version_id 字段
-- 新增复合索引
CREATE INDEX idx_user_original_rag ON user_rags(user_id, original_rag_id);
CREATE INDEX idx_user_install_type ON user_rags(user_id, install_type);
安装类型枚举
  • REFERENCE:动态引用原始数据集,数据实时更新
  • SNAPSHOT:使用版本快照数据,内容固定不变

2. 领域模型重构

新增InstallType枚举
public enum InstallType {
    REFERENCE("REFERENCE", "引用类型"),
    SNAPSHOT("SNAPSHOT", "快照类型");
}
UserRagEntity实体扩展

新增字段:

  • originalRagId:原始RAG数据集ID
  • installType:安装类型
  • currentVersionId:当前选择的版本ID

3. 核心业务逻辑重构

创建RAG时的自动安装
// RagQaDatasetAppService.createDataset()
1. 创建原始数据集
2. 创建0.0.1私有版本(用于版本管理)
3. 自动为创建者安装REFERENCE类型记录
   - originalRagId: 数据集ID
   - installType: REFERENCE  
   - currentVersionId: 0.0.1版本ID
RAG安装逻辑重构
// UserRagDomainService.installRag()
1. 检查是否已安装同一个RAG(按originalRagId检查)
2. 如果已安装,则更新版本;如果未安装,则创建新记录
3. 自己的RAG:安装REFERENCE类型
4. 他人的RAG:安装SNAPSHOT类型
版本切换功能
// UserRagDomainService.switchRagVersion()
1. 验证用户是否已安装该RAG
2. 验证目标版本是否可用
3. 更新currentVersionId
4. 如果切换到私有版本,更新installType为REFERENCE

4. Agent集成机制

统一RAG数据获取
// RagDataService.getRagData()
根据installType决定数据来源:
- REFERENCE类型:从原始数据集表获取最新数据
- SNAPSHOT类型:从版本快照表获取固定数据
检索服务适配
// 检索时的数据路由
if (userRag.getInstallType() == REFERENCE) {
    // 从 rag_qa_dataset, rag_files, rag_documents 表查询
    return getRealTimeRagData(userRag.getOriginalRagId());
} else {
    // 从 rag_version_files, rag_version_documents 表查询  
    return getSnapshotRagData(userRag.getCurrentVersionId());
}

Read the full file on GitHub · 243 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 243 lines · 0 tokens per session scan A 3c8e97232f53

Subscribe to this mod's changes

rag-lifecycle-management is a command published in the GitHub repository lucky-aeon/AgentX (834 stars, last pushed 2mo ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 2,038 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.