[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M74G5M6PF51WGDX2HS5XYQMC":3,"skill-same:01M74G5M6PF51WGDX2HS5XYQMC":44},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":14,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":29,"install":30,"resources":43},"01M74G5M6PF51WGDX2HS5XYQMC","rag-design",null,"Design a retrieval-augmented generation pipeline — chunking, embeddings, retriever, reranker, prompt assembly — with the right cuts for the use case.","MohammadBafkar\u002Fpolymath","MohammadBafkar","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F34940462?v=4","01M74G540TQFZWK6KVAPKFVGNR","Mohammad Bafkar","01M74G541HG19QP9V5DQCJVKYE",0,"MIT","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-ai\u002Fskills\u002Frag-design\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: rag-design\ndescription: Design a retrieval-augmented generation pipeline — chunking, embeddings, retriever, reranker, prompt assembly — with the right cuts for the use case.\n---\n\n# rag-design\n\n> Design a RAG pipeline. Output is the architecture plus the cuts you'd make first if quality is low.\n\n**Mode:** analytical — judgment inside a fixed frame. Keep the output shape; every verdict cites its evidence; unknowns are marked `[TBD]` or `[VERIFY]`, never filled in.\n\n## When to use\n\n- A new feature needs LLM answers grounded in a corpus.\n- An existing RAG pipeline gives wrong or hallucinated answers and you want to know where to look.\n\nNot this when: the whole corpus fits comfortably in the model's context window — then put it in the prompt with prompt caching and skip retrieval (fewer moving parts, no recall misses). For the eval harness, `polymath-ai:eval-plan`; for injection defenses, `polymath-ai:llm-guardrails`.\n\n## Inputs\n\n- The user question shape (closed-domain Q&A, open-ended summarization, etc.).\n- The corpus: size, update rate, content type (docs, code, transcripts, mixed).\n- Quality bar (precision-first vs recall-first).\n\n## Procedure\n\n0. **Access control first.** If documents have different readers, filter by the requesting user's permissions *inside* retrieval (metadata filter on ACLs\u002Ftenant) — never retrieve broadly and trust the prompt to withhold. A RAG system without this leaks documents to anyone who can ask.\n1. **Decide the granularity of retrieval**.\n   - **Whole document** — small corpora; the model is fine with long context.\n   - **Section \u002F chunk** — most corpora. 200–800 tokens per chunk. Overlap 10–20% so cross-chunk references survive. Prepend a one-line context (document title \u002F section path) to each chunk before embedding so chunks stay meaningful out of context.\n   - **Hierarchical** — sentence-level retrieval that returns the surrounding paragraph for context.\n2. **Choose the index**:\n   - **Dense (embeddings)** — pgvector \u002F qdrant \u002F pinecone. Great for paraphrase recall.\n   - **Sparse (BM25)** — strong baseline; trivially explainable.\n   - **Hybrid** — almost always wins.\n3. **Embeddings**:\n   - One embedding model + version per index; mixing wrecks recall.\n   - Re-embed on chunking strategy change. Not optional.\n   - Freshness: re-index changed documents and **delete** removed ones (tombstones) on a schedule that matches the corpus update rate — stale or deleted content resurfacing is a correctness and compliance bug.\n4. **Reranker**:\n   - For top-k 5–10, a cross-encoder reranker improves precision substantially.\n   - Skip if the retriever already returns \u003C 5 highly relevant chunks.\n5. **Prompt assembly**:\n   - Put the retrieved context first and the question last (vendor long-context guidance: queries at the end of long prompts answer better), each chunk delimited (`\u003Csource id=\"3\">…\u003C\u002Fsource>`) so the model can cite. Repeat a one-line version of the question before the context if instructions depend on it.\n   - Tell the model to cite sources and to refuse if no source answers the question.\n   - Retrieved text is untrusted: a document can contain instructions aimed at the model. Keep it in delimited data positions and never let it grant tools or permissions (`polymath-ai:llm-guardrails`).\n6. **Failure-mode plan** — when quality is low, in this order:\n   - Wrong chunks retrieved → debug retrieval before prompt.\n   - Right chunks, wrong synthesis → adjust prompt; consider reranker.\n   - Right chunks, hallucinated facts → add explicit \"answer only from sources\" + abstention path; consider citation requirement.\n7. **Evaluation hook** — evaluate retrieval separately from generation (recall@k \u002F MRR on question→relevant-chunk labels) so you know which half is failing; pair with `polymath-ai:eval-plan` for end-to-end quality. Don't deploy without a held-out set.\n\n## Output\n\n```text\nRAG design: \u003Cuse case>\n\nCorpus shape: \u003Ce.g. 30k internal docs, mostly Markdown, monthly updates>\n\nPipeline:\n  Chunking: 600-token chunks, 120-token overlap. Split on Markdown headings.\n  Embedding: \u003Cprovider> (one model, version pinned).\n  Index: pgvector + BM25 hybrid.\n  Retrieval: top 20 candidates per source.\n  Rerank: cross-encoder reranker, keep top 6.\n  Access:  retrieval filtered by the caller's ACL groups (metadata filter).\n  Prompt:  \u003Csource id=\"N\">…\u003C\u002Fsource> blocks first, question last.\n           Model instructed to cite [source N] and abstain if unanswered.\n  Freshness: nightly re-index of changed docs; deletes propagate within 24h.\n\nFirst-quality-cut order (if eval is low):\n  1. Inspect 20 wrong-answer cases: did retrieval surface a relevant chunk?\n  2. If no — investigate chunking + embeddings.\n  3. If yes — investigate prompt + reranker.\n```\n\n## Anti-patterns to avoid\n\n- Choosing a vector DB before knowing the corpus size.\n- Dense-only retrieval without measuring against BM25.\n- Mixing embedding model versions across a corpus.\n- Skipping evaluation and shipping vibes.\n- Retrieving across all tenants\u002Fpermissions and asking the prompt to keep secrets.\n","# rag-design\n\n> Design a RAG pipeline. Output is the architecture plus the cuts you'd make first if quality is low.\n\n**Mode:** analytical — judgment inside a fixed frame. Keep the output shape; every verdict cites its evidence; unknowns are marked `[TBD]` or `[VERIFY]`, never filled in.\n\n## When to use\n\n- A new feature needs LLM answers grounded in a corpus.\n- An existing RAG pipeline gives wrong or hallucinated answers and you want to know where to look.\n\nNot this when: the whole corpus fits comfortably in the model's context window — then put it in the prompt with prompt caching and skip retrieval (fewer moving parts, no recall misses). For the eval harness, `polymath-ai:eval-plan`; for injection defenses, `polymath-ai:llm-guardrails`.\n\n## Inputs\n\n- The user question shape (closed-domain Q&A, open-ended summarization, etc.).\n- The corpus: size, update rate, content type (docs, code, transcripts, mixed).\n- Quality bar (precision-first vs recall-first).\n\n## Procedure\n\n0. **Access control first.** If documents have different readers, filter by the requesting user's permissions *inside* retrieval (metadata filter on ACLs\u002Ftenant) — never retrieve broadly and trust the prompt to withhold. A RAG system without this leaks documents to anyone who can ask.\n1. **Decide the granularity of retrieval**.\n   - **Whole document** — small corpora; the model is fine with long context.\n   - **Section \u002F chunk** — most corpora. 200–800 tokens per chunk. Overlap 10–20% so cross-chunk references survive. Prepend a one-line context (document title \u002F section path) to each chunk before embedding so chunks stay meaningful out of context.\n   - **Hierarchical** — sentence-level retrieval that returns the surrounding paragraph for context.\n2. **Choose the index**:\n   - **Dense (embeddings)** — pgvector \u002F qdrant \u002F pinecone. Great for paraphrase recall.\n   - **Sparse (BM25)** — strong baseline; trivially explainable.\n   - **Hybrid** — almost always wins.\n3. **Embeddings**:\n   - One embedding model + version per index; mixing wrecks recall.\n   - Re-embed on chunking strategy change. Not optional.\n   - Freshness: re-index changed documents and **delete** removed ones (tombstones) on a schedule that matches the corpus update rate — stale or deleted content resurfacing is a correctness and compliance bug.\n4. **Reranker**:\n   - For top-k 5–10, a cross-encoder reranker improves precision substantially.\n   - Skip if the retriever already returns \u003C 5 highly relevant chunks.\n5. **Prompt assembly**:\n   - Put the retrieved context first and the question last (vendor long-context guidance: queries at the end of long prompts answer better), each chunk delimited (`\u003Csource id=\"3\">…\u003C\u002Fsource>`) so the model can cite. Repeat a one-line version of the question before the context if instructions depend on it.\n   - Tell the model to cite sources and to refuse if no source answers the question.\n   - Retrieved text is untrusted: a document can contain instructions aimed at the model. Keep it in delimited data positions and never let it grant tools or permissions (`polymath-ai:llm-guardrails`).\n6. **Failure-mode plan** — when quality is low, in this order:\n   - Wrong chunks retrieved → debug retrieval before prompt.\n   - Right chunks, wrong synthesis → adjust prompt; consider reranker.\n   - Right chunks, hallucinated facts → add explicit \"answer only from sources\" + abstention path; consider citation requirement.\n7. **Evaluation hook** — evaluate retrieval separately from generation (recall@k \u002F MRR on question→relevant-chunk labels) so you know which half is failing; pair with `polymath-ai:eval-plan` for end-to-end quality. Don't deploy without a held-out set.\n\n## Output\n\n```text\nRAG design: \u003Cuse case>\n\nCorpus shape: \u003Ce.g. 30k internal docs, mostly Markdown, monthly updates>\n\nPipeline:\n  Chunking: 600-token chunks, 120-token overlap. Split on Markdown headings.\n  Embedding: \u003Cprovider> (one model, version pinned).\n  Index: pgvector + BM25 hybrid.\n  Retrieval: top 20 candidates per source.\n  Rerank: cross-encoder reranker, keep top 6.\n  Access:  retrieval filtered by the caller's ACL groups (metadata filter).\n  Prompt:  \u003Csource id=\"N\">…\u003C\u002Fsource> blocks first, question last.\n           Model instructed to cite [source N] and abstain if unanswered.\n  Freshness: nightly re-index of changed docs; deletes propagate within 24h.\n\nFirst-quality-cut order (if eval is low):\n  1. Inspect 20 wrong-answer cases: did retrieval surface a relevant chunk?\n  2. If no — investigate chunking + embeddings.\n  3. If yes — investigate prompt + reranker.\n```\n\n## Anti-patterns to avoid\n\n- Choosing a vector DB before knowing the corpus size.\n- Dense-only retrieval without measuring against BM25.\n- Mixing embedding model versions across a corpus.\n- Skipping evaluation and shipping vibes.\n- Retrieving across all tenants\u002Fpermissions and asking the prompt to keep secrets.\n",{"name":5,"description":7},"main","23f6e21841a39580c9da2b5ec941f39dda17cd86","plugins\u002Fpolymath-ai\u002Fskills\u002Frag-design","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath","https:\u002F\u002Fgithub.com\u002FMohammadBafkar","2026-10-29 18:34:59",{"source":8,"skillName":5,"commands":31,"prompt":41,"zipAvailable":42},[32,35,38],{"tool":33,"command":34},"npx","npx skills add MohammadBafkar\u002Fpolymath --skill rag-design",{"tool":36,"command":37},"bunx","bunx skills add MohammadBafkar\u002Fpolymath --skill rag-design",{"tool":39,"command":40},"pnpm","pnpm dlx skills add MohammadBafkar\u002Fpolymath --skill rag-design","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-ai\u002Fskills\u002Frag-design\u002FSKILL.md",true,[],[45,52,59,66,73,80],{"skillNo":46,"name":47,"nameZh":6,"description":48,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":49,"categories":50,"keywords":51,"publishedAt":19},"01M74GN87EBRHM9N87M7AP1HDD","runbook","Write or refresh an operational runbook for an alert\u002Fsymptom; structured as TL;DR + Pre-checks + Steps + Verification + Rollback + Escalation.","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Frunbook\u002FSKILL.md",[],[],{"skillNo":53,"name":54,"nameZh":6,"description":55,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":56,"categories":57,"keywords":58,"publishedAt":19},"01M74GN5GPKEC1JEKP2DFQNEQJ","rfc","Draft a lightweight design RFC to docs\u002Frfcs\u002F\u003Cslug>.md; Summary, Motivation, Detailed design, Drawbacks, Alternatives, Unresolved questions. A proposal to debate, not a recorded decision (adr).","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Frfc\u002FSKILL.md",[],[],{"skillNo":60,"name":61,"nameZh":6,"description":62,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":19},"01M74GN2F4CWPMV4X09TG4E304","editorial-pass","Review and tighten prose in a Markdown artifact for a target tone (terse, formal, friendly) without dropping information; preserve quotations and load-bearing constraints.","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Feditorial-pass\u002FSKILL.md",[],[],{"skillNo":67,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":19},"01M74GMZWGYMZ37C4DYGT6P23G","architecture-review-facilitation","Run an architecture review as a process — entry criteria, reviewer checklist, decision log, and follow-up actions — pairing the design artifact with a red-team pass.","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Farchitecture-review-facilitation\u002FSKILL.md",[],[],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":19},"01M74GMXVX0YX3ETDXS527XDGM","architecture-doc","Write a C4-style architecture document; System Context + Containers (+ Components when interesting) with mermaid diagrams. Describes structure, not a decision (adr) or proposal (rfc).","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Farchitecture-doc\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":19},"01M74GMVG1WSMCK066S3KE6V5K","adr","Write an Architecture Decision Record (Michael Nygard format) to docs\u002Fadrs\u002FNNNN-\u003Cslug>.md; frontmatter validated by the ADR artifact schema. Records a made decision, not a proposal to debate (rfc).","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Fadr\u002FSKILL.md",[],[]]