Rag architect

From seaworld008/Commonly-used-high-value-skills · View interactive version

Rag architect is an AI agent skill from the GitHub repository seaworld008/Commonly-used-high-value-skills. Design or diagnose RAG ingestion, retrieval, permissions, reranking, citations, and evaluation when answers must be grounded in a specialized corpus.

How to use this skill

Skill file

RAG Architect

Design from measured retrieval failures, not from a fashionable vector

database or chunk size.

Start With the Product Contract

Define:

Do not build RAG when direct context, structured queries, a conventional search

index, or a deterministic API is simpler and more reliable.

Build the Evaluation Set First

Create a versioned dataset before tuning:

{
  "id": "policy-017",
  "query": "Can a contractor export customer data?",
  "expected_source_ids": ["policy-access-4.2"],
  "required_facts": ["contractors cannot export", "exception requires DPO approval"],
  "forbidden_claims": ["contractors always have export access"],
  "user_acl": ["policy:employee"],
  "as_of": "2026-07-01",
  "answerable": true
}

Include:

Keep a held-out set. Do not tune and report on the same examples.

Measure the Pipeline in Layers

Evaluate retrieval separately from generation.

Retrieval

Answering

Always inspect failures by slice. One aggregate score can hide catastrophic

permission or freshness failures.

Ingestion Contract

Preserve provenance:

source_id
document_version
canonical_uri
content_hash
effective_at
expires_at
acl
parser_version
chunker_version
indexed_at

Make ingestion idempotent. Support updates and deletions. A deleted or

permission-revoked document must stop appearing without rebuilding unrelated

content.

Reject or quarantine parser failures instead of silently indexing empty or

garbled text.

Chunking

Select chunking from document structure and evaluation results:

Do not choose a universal token count or overlap percentage without evidence.

Record the chunker version so retrieval regressions are reproducible.

Retrieval Architecture

Start with the simplest baseline:

  1. metadata and ACL filtering
  2. lexical search
  3. dense retrieval
  4. reciprocal-rank fusion or another explicit hybrid strategy
  5. reranking when the evaluation set proves it adds value

Apply authorization before returning content to the model. Post-filtering an

over-retrieved unauthorized result set is not a sufficient security boundary.

Use query rewriting only when it measurably helps specific query classes.

Preserve the original query for audit and fallback.

Structured and Multi-Source Data

Route structured questions to databases or APIs rather than embedding every

row. When combining structured and unstructured evidence:

Answer Generation

Require the answerer to:

Do not treat a fluent answer as evidence of retrieval quality.

Failure Diagnosis

Classify every failed example:

| Failure | Typical evidence | Fix layer |

|---|---|---|

| Missing content | source absent from index | ingestion |

| Wrong boundary | fact split or table lost | parsing/chunking |

| Low recall | expected source below k | retrieval |

| Bad ordering | source found but ranked low | fusion/reranking |

| Permission leak | unauthorized source returned | filtering/security |

| Unsupported answer | source present, claim absent | generation |

| Wrong citation | answer true, citation unrelated | citation mapping |

| Stale answer | old version outranks current | freshness/versioning |

Change one layer at a time and rerun the same evaluation slices.

Production Monitoring

Track:

Log query, retrieved source identifiers, scores, pipeline versions, and final

citations subject to privacy policy. Avoid storing sensitive raw content when

identifiers and hashes are sufficient.

Rollout

Use shadow evaluation or canaries for index, embedding, chunker, or reranker

changes. Keep the previous index addressable until rollback is proven.

Block rollout when:

Output Contract

Return:

Prefer a measured baseline over an elaborate untested architecture.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.