build-rag-pipeline
Skill7 starsChanged 18 days agoMITView on GitHub
Use when building retrieval-augmented answers over your own documents — structure-aware chunking, pinned embeddings in pgvector, hybrid vector plus full-text search with RRF, tenant isolation in the query, citations, an "I don't know" path, retrieval evals before prompt tuning.
- Reads credentials
- Installs packages
1 other project uses a version of this.
Adopted by
Most recently taken up by
- VelimirMueller/claude-skillsword for word, first seen Oct 11, 2026
Other versions1 project uses a version of this.
Word for word · 1
- VelimirMueller/claude-skills★ 7100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository156 other files it gives its agents.
- skills/swift/swiftui-design-principles/AGENTS.mdAGENTS.md
- skills/swift/ios-code-audit/CLAUDE.mdCLAUDE.md
- skills/swift/swift-focusengine-pro/llms.txtllms.txt
- build-llm-seamSkill
- build-mcp-serverSkill
- secure-llm-featuresSkill
- set-up-llm-evalsSkill
- build-nextjs-backendSkill
- build-supabase-edge-functionSkill
- configure-backend-testsSkill
- design-http-apiSkill
- harden-backendSkill
- scaffold-fastapi-serviceSkill
- scaffold-go-serviceSkill
- scaffold-hono-serviceSkill
- secure-supabase-rlsSkill
- set-up-backend-authSkill
- set-up-background-jobsSkill
- set-up-databaseSkill
- set-up-nextjs-supabase-authSkill
- set-up-observabilitySkill
- set-up-supabaseSkill
- build-cliSkill
- release-cliSkill
- set-up-dev-toolchainSkill
- audit-securitySkill
- audit-toolchainSkill
- extend-skillsetSkill
- promote-releaseSkill
- set-up-stack-profileSkill
- write-commit-messagesSkill
- write-pull-requestsSkill
- analyze-complexitySkill
- apply-algorithmsSkill
- apply-design-patternsSkill
- apply-design-principlesSkill
- apply-solidSkill
- choose-data-structureSkill
- debug-systematicallySkill
- enforce-dependency-ruleSkill
- refactor-safelySkill
- slice-and-estimateSkill
- write-clean-testsSkill
- write-readable-codeSkill
- clean-frontend-scaffoldingSkill
- configure-accessibilitySkill
- configure-analyticsSkill
- configure-ciSkill
- configure-error-trackingSkill
- configure-lintingSkill
- configure-test-stackSkill
- configure-typescriptSkill
- create-moduleSkill
- optimize-performanceSkill
- scaffold-frontend-projectSkill
- set-up-authSkill
- set-up-design-systemSkill
- set-up-document-headSkill
- set-up-error-boundariesSkill
- set-up-feature-flagsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 12
Read .claude/stack-profile.md (database, ai.rag_store, ai.provider, languages, backend.track).
- Very specific: line 26
No seam yet → run build-llm-seam first.
- Distinctive: line 27
No vector schema → full install (steps 4–6).
- Very specific: line 73
Freshness: After each full sync call removeMissing(pool, tenantId, liveUris).
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Build a RAG Pipeline
Ingest, normalize, chunk, embed, store, retrieve, answer with citations. The order of work matters: build retrieval and measure it (recall@k, MRR) before touching the answer prompt. Most bad RAG answers are retrieval failures that a prompt cannot fix. Store default: ai.rag_store: pgvector in the profile.
1. Audit current state
Read .claude/stack-profile.md (database, ai.rag_store, ai.provider, languages, backend.track). If absent, detect per stack-profile.md. Change nothing yet:
grep -rln "pgvector\|halfvec\|vector(" migrations drizzle alembic src 2>/dev/null # existing vector schema
grep -rniE "embed|chunk|similarity|cosine|<=>" src --include=*.ts --include=*.py | head # ad hoc retrieval code
ls src/platform/llm src/rag evals/datasets 2>/dev/null # seam, RAG module, golden sets
grep -rn "tenant_id\|row level security\|enable row level" migrations drizzle alembic 2>/dev/null | head
psql "$DATABASE_URL" -c "select extname, extversion from pg_extension where extname='vector'" # expect 0.8.3 or laterReport: model calls outside the seam (build-llm-seam comes first), embeddings without a recorded model id, retrieval without a tenant filter, no golden queries, chunking by fixed characters.
2. Decide what to do
- No seam yet → run
build-llm-seamfirst; the answer step calls it. - No vector schema → full install (steps 4–6).
- Schema exists, embeddings carry no model id → add
rag_embeddingsand backfill (step 5); this is the one change that is hard to do later. - Retrieval works, answers are wrong → do not edit prompts yet: build the retrieval eval (step 7).
- Everything present and
Verifypasses → "already in place".
3. Detect the store track
| Signal | Branch |
ai.rag_store: pgvector, or Postgres in the profile | pgvector: this skill's code. Default, justified in rag-patterns.md |
database.host: supabase | pgvector is available there; same SQL. Check select extversion first |
sqlite-vec, local single-user tool | Keep the Embedder and chunker; write the store against sqlite-vec; no RLS, so isolation is by file per tenant |
qdrant, or a measured need the store cannot meet | Keep the interfaces (Embedder, search, answer); replace store.ts. The measured need is a retrieval p95 above budget after tuning ef_search and indexes at your corpus size |
languages: python | Same SQL; rag-code.md has store.py |
4. Install only what's missing
# Postgres: the extension (pgvector 0.8.7 on the image tested; managed hosts: enable "vector")
psql "$DATABASE_URL" -c "create extension if not exists vector"
pnpm add pg zod && pnpm add -D @types/pg # TypeScript
uv add "psycopg[binary]" psycopg-pool # PythonEmbeddings: Anthropic offers no embedding model; use Voyage AI (voyage-4, 1024 dims). Add VOYAGE_API_KEY and VOYAGE_BASE_URL (https://ai.mongodb.com/v1 for Atlas keys, https://api.voyageai.com/v1 for Voyage platform keys) to the service config. If text may not leave your network, run voyage-4-nano (open weights) or another model behind the same Embedder interface.
5. Generate the seams
Layout (the store is the repository layer, answer is the service, see service-layout.md):
migrations/0001_rag.sql # tables, HNSW index, FTS index, RLS
src/rag/chunk.ts # markdown-aware chunker
src/rag/embed.ts # Embedder interface + Voyage adapter
src/rag/store.ts # withTenant, upsertDocument, search: the only SQL
src/rag/ingest.ts # normalize, ingest, removeMissing
src/rag/answer.ts # context, citations, "I don't know"
prompts/rag-answer.md # versioned prompt
evals/datasets/retrieval.jsonlAll code: rag-code.md. Run the migration as a role that owns the tables; the application connects as a different role without bypassrls. Edit: the model id and dimension in the index (voyage-4@1024), the FTS config (simple mixes languages safely; use german, english … when the corpus is one language), the similarity floor in answer.ts (calibrate on the eval set).
6. Wire it up
- Ingest job. A CLI or queue consumer reads sources, calls
ingest(pool, embedder, doc). It is idempotent: an unchangedcontent_hashreturnsunchangedand costs nothing. - Freshness. After each full sync call
removeMissing(pool, tenantId, liveUris). Schedule the sync (cron, or a webhook from the source for changes). - Retrieval endpoint. Derive
tenantIdfrom the verified session, never from the request body.withTenant(pool, tenantId, c => search(c, embedder, { tenantId, text })), thenanswer(llm, question, hits). Returnsourceswith the answer. - Re-embedding is a deliberate act: new migration with the new partial index, backfill into
rag_embeddingsunder the new id, run the retrieval eval on both, flip the config, drop the old rows and index. See rag-patterns.md.
7. Verify
TEST_DATABASE_URL=postgres://app_role:…@localhost/test pnpm vitest run tests/rag.test.ts # Python: uv run pytest tests/test_rag.pyExpected: chunker tests pass; the retrieval test shows tenant A's search never returns tenant B's text, even when the query itself names tenant B (RLS wins); an unchanged document returns unchanged; a weak match returns the fixed "I don't know".
Then the part that matters. Write 30 or more golden queries into evals/datasets/retrieval.jsonl ({id, tenant, query, relevant: [source_uri]}), including a few that have no answer in the corpus, and run:
pnpm tsx evals/retrieval.ts evals/datasets/retrieval.jsonl # prints recall@5, recall@20, MRR and the worst query idsRecord the numbers. Change one thing at a time (chunk size, candidates, hybrid on or off, reranker) and keep a change only if recall@k or MRR improves. In psql, explain the vector leg once: expect Index Scan using rag_emb_… (hnsw). Eval design: set-up-llm-evals.
References
- rag-patterns.md: rules and why. rag-code.md: all code.
- llm-seam-ts.md: the answer step goes through the seam.
- llm-security.md: documents are untrusted text; tenant isolation is LLM02 and LLM09.
- stack-versions.md: pgvector, Voyage, driver lines.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

