‹ 首页

rag-and-memory

@developersglobal · 收录于 1 周前

Patterns for Retrieval-Augmented Generation (RAG) and agent memory systems. Retrieves only relevant context, prevents context bloat, and maintains coherent state across sessions.

适合你,如果需要在对话中精准检索信息并保持长期记忆

/ 下载安装
rag-and-memory.skill双击,或拖进 Claude 桌面版 / Cowork,即完成安装↓ .skill↓ .zip
用别的 agent?下载 .zip 解压,把文件夹放进它的技能目录
Claude Code~/.claude/skills/(项目级 .claude/skills/)
Codex CLI~/.codex/skills/
Cursor自动读取上面两处目录
其他工具见其文档的「skills」目录;两个下载是同一份文件,只是名字不同
/ 通过 npx 安装 校验哈希
npx oh-my-skill add developersglobal/ai-agent-skills/rag-and-memory
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- developersglobal/ai-agent-skills/rag-and-memory
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify developersglobal/ai-agent-skills/rag-and-memory
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
64GitHub stars
~1.1K上下文体积 · 单文件
镜像托管

怎么用

技能原文 SKILL.md作者撰写 · MIT · f47f948
Overview

RAG and memory systems are how AI agents work with knowledge that exceeds their context window. Done well: agents give accurate, grounded answers. Done poorly: context overflow, hallucination from stale retrieval, and performance degradation.

This skill covers the design principles and failure modes of RAG and memory architectures for production AI systems.

When to Use
  • Building any AI system that needs to access external knowledge
  • When agent context windows are being exceeded
  • When agents need to remember information across sessions
  • When building Q&A, document analysis, or knowledge base systems
Process
Step 1: Choose the Right Memory Architecture
  1. Identify what the agent needs to remember:
  2. Ephemeral: Within a single session (use in-context memory)
  3. Session-persistent: Across a user's sessions (use external key-value store)
  4. Knowledge base: Organizational or domain knowledge (use vector DB + RAG)
  5. Procedural: How to do tasks (encode in SKILL.md / system prompt)
  6. Match the memory type to the store:

| Memory Type | Recommended Store | |------------|------------------| | In-session facts | Context window (summarized) | | User preferences | Key-value store (Redis, DynamoDB) | | Document corpus | Vector database (Pinecone, Weaviate, pgvector) | | Long-term facts | Structured DB + caching |

Verify: Each type of information the agent needs has a defined storage mechanism.

Step 2: Design the RAG Pipeline
  1. Chunking strategy: Break documents into chunks at semantic boundaries (paragraphs, sections) — not arbitrary character counts.
  2. Embedding model: Match the embedding model to your query type. Use the same model for indexing and retrieval.
  3. Retrieval: Retrieve top-K most semantically similar chunks. K = 3–7 is usually optimal.
  4. Re-ranking: After retrieval, re-rank by relevance using a cross-encoder. Top K becomes top 3–5 for the prompt.
  5. Context injection: Inject retrieved chunks into the prompt with clear source citations.

Verify: Retrieved chunks are genuinely relevant to the query before injecting into context.

Step 3: Prevent Context Bloat
  1. Summarize, don't accumulate: For long sessions, summarize previous turns rather than appending them indefinitely.
  2. Retrieve, don't pre-load: Only load context relevant to the current query. Don't pre-load everything.
  3. Set context budgets: Define maximum token allocations for: system prompt, retrieved context, conversation history, user message.
  4. Compress before injecting: Summarize long retrieved documents to extract the relevant portion only.

Verify: Total prompt length is within model limits with buffer. Retrieved context is relevant to current query.

Step 4: Handle Retrieval Failures Gracefully
  1. If retrieval returns no relevant results: say so — do not hallucinate an answer.
  2. If retrieved documents are outdated: surface the document date to the user.
  3. If confidence is low: present the retrieved source and let the user evaluate.
  4. Design for "no relevant information found" as a first-class outcome.

Verify: System has defined behavior for failed/empty retrieval.

Step 5: Measure and Optimize
  1. Track retrieval quality:
  2. Precision: Are retrieved chunks relevant to the query?
  3. Recall: Are relevant chunks being retrieved at all?
  4. Track answer quality: Use RAGAS or similar evaluation framework.
  5. Monitor: context length per query, retrieval latency, hallucination rate.

Verify: Baseline metrics established. Retrieval precision > 80%.

Common Rationalizations (and Rebuttals)

| Excuse | Rebuttal | |--------|----------| | "Let's just put everything in the context" | Context bloat degrades quality and costs money. Retrieve what's needed. | | "The model knows this from training" | Training knowledge is stale. Use RAG for current information. | | "Vector search is good enough without re-ranking" | Re-ranking improves precision significantly. It's a small cost for large quality gain. | | "We'll fix retrieval quality later" | Poor retrieval quality compounds into poor answer quality. Fix it now. |

Red Flags
  • Entire document corpus pre-loaded into every prompt
  • Retrieval returning chunks from unrelated documents
  • No defined behavior for empty retrieval results
  • Context window regularly at 90%+ capacity
  • Agent answering from "training knowledge" instead of retrieved documents
  • No source citations for retrieved information
Verification
  • [ ] Memory architecture matches the type of information needed
  • [ ] RAG pipeline: chunk → embed → retrieve → re-rank → inject
  • [ ] Context budgets defined for all prompt sections
  • [ ] Empty retrieval has a defined graceful fallback
  • [ ] Retrieval precision measured and > 80%
  • [ ] Source citations included in AI responses
References
  • [hallucination-prevention skill](../hallucination-prevention/SKILL.md)
  • [multi-agent-orchestration skill](../multi-agent-orchestration/SKILL.md)
  • [ai-output-validation skill](../ai-output-validation/SKILL.md)
按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。