← All skills
AI https://ai-skills-vault.pages.dev/skills/rag-knowledge-base.md

RAG Knowledge Base

Retrieval that answers correctly, with citations you can click.

Download .md All skills
Install URLhttps://ai-skills-vault.pages.dev/skills/rag-knowledge-base.md
Install prompt tap to copy
Read the skill at https://ai-skills-vault.pages.dev/skills/rag-knowledge-base.md and install it as a skill in your agent. Follow it exactly, including its checklists. Then ask me the questions it requires and do the work.

Most "RAG is bad" complaints are chunking problems wearing a model costume. Fix retrieval and the answer quality follows.

When to use this skill

Do NOT use for: tasks needing the whole document at once (summarise this 200-page report - use long context), or data that changes per second (query the API instead).

Stage 1 - Corpus audit

  1. What is the source of truth - which files, which system, who owns them?
  2. Volume - number of documents, pages, tokens. Under ~2,000 pages, retrieval beats fine-tuning.
  3. Structure - are documents prose, tables, FAQs, code, scanned PDFs? Each needs a different parser.
  4. Freshness - how often does it change, and how will re-indexing trigger?
  5. Permissions - does every user get every document? If not, filter at query time, never post-filter the answer.
  6. Question inventory - collect 50 real questions people actually ask. This becomes your evaluation set before you write any code.

Stage 2 - Ingestion and parsing

Stage 3 - Chunking (spend your time here)

Stage 4 - Retrieval

Use hybrid search, always:

  1. Dense vector search (embeddings) for meaning.
  2. Sparse BM25 for exact terms: SKUs, error codes, names, acronyms. Dense search fails on these and they are usually the query.
  3. Fuse with reciprocal rank fusion.
  4. Rerank the top 30-50 with a cross-encoder to the top 5-8. This is the single highest-value upgrade after chunking.
  5. Apply metadata filters (tenant, date, doc type) inside the query, before ranking.

Vector store choice: pgvector if you already run Postgres (simplest, transactional, one backup story). A dedicated store only when scale or features demand it.

Stage 5 - Answering

Stage 6 - Evaluation (do this before tuning anything)

Build a 100-question set with the correct answer and the correct source document for each. Measure:

MetricMeaningTarget
Recall@kcorrect doc in retrieved k> 0.9
MRRhow high the correct doc ranks> 0.7
Faithfulnessanswer supported by context> 0.95
Answer correctnessmatches the reference answer> 0.85
Refusal rate on unanswerablecorrectly says "not in the docs"> 0.9

Run it on every change. A prompt tweak that feels better but drops recall is a regression. Add every real failure to the set permanently.

Stage 7 - Failure diagnosis table

SymptomReal causeFix
Answer ignores the right docChunking split the factSemantic chunking, add context header
Retrieves similar but wrong topicNo rerankingAdd cross-encoder rerank
Fails on part numbers, codesDense-only searchAdd BM25 + RRF
Confident wrong answerNo refusal instructionGrounding prompt + low-temperature + eval
Good answer, bad citationCitation not tied to chunk idNumbered chunks, require inline markers
SlowLarge k, no cacheRerank fewer, cache embeddings and results
Different answer per userPermission post-filteringFilter inside the retrieval query

Stage 8 - Operations

Quality checklist

Copy-ready agent prompt

Read the skill at the URL above. Ask me for the corpus, the users and 50 real questions first. Then design the ingestion schema, the chunking strategy with context headers, hybrid retrieval with reranking, and the grounded answering prompt with inline citations and an explicit refusal path. Give me the eval script with recall@k, MRR and faithfulness, and run it against my sample set before you call it done.
Copied