Getting it into your agent
It runs from inside its repository, so the clone comes first — what it calls does not travel with the file alone.
git clone --depth 1 https://github.com/mytk2012/python_agentnpx agentmods add skills/mytk2012/python_agent/ragWrote 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.
[](https://agentmods.dev/skills/mytk2012/python_agent/rag)<a href="https://agentmods.dev/skills/mytk2012/python_agent/rag"><img src="https://agentmods.dev/badge/skills/mytk2012/python_agent/rag/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/skills/mytk2012/python_agent/rag"><img src="https://agentmods.dev/badge/skills/mytk2012/python_agent/rag.svg" alt="Reviewed on agentmods" width="80" height="20"></a>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.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00007 | $0.01617 |
| Opus 5.5 | $0.00003 | $0.00647 |
| Sonnet 5.5 | $0.00001 | $0.00323 |
| Haiku 4.5 | $0.00001 | $0.00162 |
Grade A, and why
rag 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 1mo 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.
How it starts
The opening of the file, as written. The whole thing — 242 lines — stays where its author put it; the contents beside it link to each section on GitHub.
RAG Skill
检索增强生成(Retrieval-Augmented Generation)能力,结合文档检索和LLM生成。
功能
- 文档摄入(PDF、DOCX、TXT、Markdown)
- 文本分块(Chunking)
- 向量嵌入生成
- 向量数据库管理
- 语义搜索
- 混合搜索(向量 + 关键词)
- 知识库管理
快速开始
1. 启动 Docker 服务
cd rag/docker && docker-compose up -d
启动的服务包括:
- Weaviate(向量数据库)
- Elasticsearch(关键词检索)
- Redis(缓存存储)
- nginx(代理)
2. 配置环境变量
确保 .env 文件包含以下配置:
# Elasticsearch(必须与 docker/.env 中配置一致)
ELASTICSEARCH_USER=elastic
ELASTICSEARCH_PASSWORD="difyai123456"
# Weaviate
WEAVIATE_API_KEY=jane-secret-key
# Redis
REDIS_PASSWD="difyai123456"
# Embedding 服务(用于向量检索和 RAG Pipeline)
EMBEDDING_MODEL=bge-large-zh-v1.5
EMBEDDING_API_URL=http://localhost:9997/v1
EMBEDDING_API_KEY=sk-your-api-key
# LLM 服务(用于 RAG Pipeline)
LLM_MODEL=glm-5
LLM_API_URL=https://api.example.com/v1
LLM_API_KEY=sk-your-api-key
3. 运行示例代码
import asyncio
from rag import (
KnowledgeBaseConfig,
kb_manager,
)
# 必须先导入以注册内置分块策略
from rag.extensions.custom_line_split import * # noqa: F401
async def main():
# 创建知识库(ELAS_ONLY 模式,仅使用 Elasticsearch)
config = KnowledgeBaseConfig(
kb_id="my_kb",
kb_name="我的知识库",
KNOWLEDGE_PATH="rag/test_document/",
ELAS_ONLY=True,
)
kb = await kb_manager.create_knowledge_base(**config.to_dict())
print("✅ 知识库创建成功")
# 加载并添加文档
await kb_manager.load_and_add_documents("my_kb", "rag/test_document/")
print("✅ 文档加载成功")
# 检索
results = await kb_manager.retrieve("my_kb", "查询内容", k=5)
print(f"✅ 检索返回 {len(results)} 条结果")
# 清理
await kb_manager.delete_knowledge_base("my_kb")
print("✅ 知识库已删除")
asyncio.run(main())
验证功能
运行完整测试脚本:
uv run python tests/test_knowledge_base_complete.py
测试覆盖:
- 多知识库管理
- 文档处理和分块
- 向量存储连接
- 检索功能
检索模式
三种模式互斥,只能启用一种:
| 模式 | 说明 | 配置 |
|---|---|---|
ELAS_ONLY |
仅关键词检索(Elasticsearch) | ELAS_ONLY=True |
VECTOR_ONLY |
仅向量检索(Weaviate) | VECTOR_ONLY=True |
MIXED |
混合检索 | MIXED=True |
ELAS_ONLY 模式(推荐入门)
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.
- 1mo ago First seen · 242 lines · 7 tokens per session scan A 6fbee8cc4c59
rag is a skill published in the GitHub repository mytk2012/python_agent (22 stars, last pushed 6mo ago), licensed Apache-2.0. It adds 7 tokens to every session and 1,617 once invoked, about $0.0000 per session on Opus 5.5. 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.
Other skills, from other repositories
molecular-rag
Retrieve structurally similar compounds with known properties from ChEMBL/ZINC to ground predictions and inform optimization. Based on MolRAG (Xian 2025, ACL).
nemotron-retrieval-recipes
Use when planning, debugging, tuning, evaluating, exporting, or deploying public Nemotron embed/rerank retrieval recipes.
llamaindex
Use when building RAG and agent applications over documents with LlamaIndex — SimpleDirectoryReader loading, node parsers, VectorStoreIndex with local or external vector stores (Chroma, PGVector, Qdrant), query engines and response modes, chat engines, RouterQueryEngine routing, event-driven Workflows, and…
rag-expert
Design retrieval-augmented generation systems: chunking, embeddings, vector and hybrid search, reranking, grounding and evaluation. Use when the user mentions RAG, retrieval, semantic search, embeddings, vector databases, pgvector, Chroma, Qdrant, Pinecone, chunking or reranking, wants an assistant answering over…
rag-blueprint
NVIDIA RAG Blueprint deployment, configuration, troubleshooting, and shutdown guidance for Docker, Helm, and library-based RAG stacks.
rag-eval
NVIDIA RAG Blueprint evaluation guidance for measuring retrieval and answer quality with stable datasets, baselines, and reproducible scoring workflows.