mcpField
N
ns-postgres-rag

ns-postgres-rag

github.com/nextstage-brasilData & databases076 installsUpdated 1w ago
Repository

About ns-postgres-rag

ns-postgres-rag is a skill for planning retrieval systems on PostgreSQL. It guides teams through corpus assessment, retrieval-mode selection, and an approval-gated design report, without writing application code.

Key features

  1. 01Inventory corpus size and characteristics
  2. 02Choose a retrieval base mode
  3. 03Prepare a retrieval design report
  4. 04Require evidence and provenance for graph links
  5. 05Plan evaluation gates and scaling

Use cases

  1. 01Select an approach for a new PostgreSQL retrieval project
  2. 02Review existing DDL and indexes
  3. 03Assess whether multi-hop GraphRAG is needed

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/nextstage-brasil/skills --skill ns-postgres-rag

After installing, type/ns-postgres-ragin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

evals/
evals.json
references/
anti-patterns.md
corpus-assessment.md
entity-resolution.md
evaluation-and-gates.md
ingestion-pipeline.md
multi-hop-traversal.md
operations-and-scale.md
retrieval-augmentations.md
retrieval-contract.md
retrieval-decision.md
schema-and-indexes.md
templates/
retrieval-design-report.md
templates/snippets/
chunk-schema.sql.snippet
entity-edge-schema.sql.snippet
hnsw-index.sql.snippet
hybrid-search.sql.snippet
multi-hop-cte.sql.snippet
retrieval-result.ts.snippet

Details

From the project README

PostgreSQL retrieval (RAG / GraphRAG)

Postgres retrieval doctrine: pgvector, FTS, entity/edge, multi-hop.

Analyze. Recommend. No app code. Required reports approved (Retrieval Design Report; plus GraphRAG Process Report when mode is relational GraphRAG and ns-graphrag is installed) → ns-spec-driven (Specify / Tasks).

Central rule

Link = query result, never text inference. Vector = candidate. Edge only after key/rule confirm + stored provenance. Path always path + provenance + confidence.

Canonical hop (illustration only, English artifacts): company → contract → invoice → payment. Derive the corpus chain in GraphRAG Process Report.

Required: pgvector. Timescale: optional — temporal volume, retention, or time partition. Scale: 1MM+ files, document links.

Applicability

ContextStrength
Greenfield retrieval on PostgresMUST Gates 1–3 before DDL counts as approved
Brownfield schema / indexesMUST inventory DDL first; diagnose similarity-as-link
Approved required reports, human wants codeStop. ns-spec-driven owns Specify / Tasks (Process Report required first when GraphRAG + ns-graphrag installed)

Read repo (DDL, migrations, Postgres version, extensions, source formats). Do not ask human for facts tree already shows.

Routing (read first)

SignalAction
Wants app implementation nowFill required reports if missing (Retrieval Design Report; Process Report when GraphRAG + ns-graphrag); else ns-spec-driven. No app code
Similarity used as stored linkreferences/anti-patterns.md + references/entity-resolution.md
Answer needs N≥2 hops; no single document holds chainGraphRAG mode — references/retrieval-decision.md. If ns-graphrag is installed: after Retrieval Design Report, continue there for ontology / extract / answer shapes / cite-or-refuse (Process Report) before ns-spec-driven
Ontology, schema-locked extract, answer-shape routing, cite-or-refusens-graphrag when installed — not this skill
Topic search, small corpus, no hop chainVector-only — refuse graph tables
GitLab ISSUE_URL or SDD version scopeDefer ../../ns-harness/references/code-skill-routing.md

Boot (mandatory)

See ../../ns-harness/references/session-boot.md — complete Session boot (blocking). Then scan:

  1. DDL / migrations (tables, indexes, vector, tsvector, entity/edge)
  2. Postgres version; extensions (pgvector required; Timescale if present or Gate 2 trigger)
  3. Source formats, corpus paths, counts if inferable
  4. Continue this skill

Success: inventory from tree + project rules. Failure: invented schema or asking human for facts in repo.

Flow

boot. Gate 1 Corpus Inventory. Gate 2 Retrieval Decision. Vector or hybrid RRF or GraphRAG in Postgres. Gate 3 Retrieval Design Report. Human approve. If mode is relational GraphRAG and ns-graphrag is installed: GraphRAG Process Report there (approve) before ns-spec-driven. Else ns-spec-driven (or loop inventory).

Gate 1 — Corpus Inventory (blocking)

Fill from repo + data sample. Human only for gaps tree cannot show. Fields: templates/retrieval-design-report.md. Method: references/corpus-assessment.md.

FieldWhy
Volume (files, bytes, chunk estimate)Index + storage at 1MM+
Growth / mutabilityRe-embed rate, upsert vs rebuild
Entity densityGraph tables vs vector-only
Question archetypesMode
Latency budget (p95)HNSW / filter / hop caps

No skip. Missing inventory = no Gate 2.

Gate 2 — Retrieval Decision (blocking)

Pick exactly one base mode. Matrix: references/retrieval-decision.md.

ModeWhen
Vector-onlyTopic / similarity; no hop chain
Hybrid (tsvector + vector, rank fusion)Keyword + semantic; one document often answers
Relational GraphRAGN≥2 hops and no single document contains chain

Augmentations (additive — base mode unchanged): none | multi-index | agentic | both. Each non-none choice needs measured symptom that justifies it. Doctrine: references/retrieval-augmentations.md. Default none. Refuse stacking without symptom.

Extensions: pgvector always. Timescale only references/operations-and-scale.md — not default.

Post base mode + augmentation lock + one-paragraph why before full report. Wrong mode = rewrite Gate 2, not paper over in DDL.

Gate 3 — Retrieval Design Report

Copy templates/retrieval-design-report.md. Fill every section. No application code. SQL = target DDL / query shape, not shipped migration.

Human approve. Reject: loop Gate 1 or Gate 2.

If mode is relational GraphRAG and ns-graphrag is installed: do not jump to ns-spec-driven yet — follow ns-graphrag through the GraphRAG Process Report (ontology, extract, persistence model, answer shapes, cite-or-refuse). Both reports approved → then ns-spec-driven. If ns-graphrag is absent, say so and hand off with retrieval-only scope (process gaps remain open).

Reference map

Load on demand.

ReferenceRead when
references/corpus-assessment.mdGate 1; 1MM+ projection
references/retrieval-decision.mdGate 2 base mode + partition / Timescale
references/retrieval-augmentations.mdGate 2 augmentations (multi-index, agentic); symptom lock
references/schema-and-indexes.mdTarget DDL, HNSW, filters, partition
references/entity-resolution.mdMerge, aliases, no edge without evidence
references/ingestion-pipeline.mdExtract, chunk, embed, idempotent upsert
references/multi-hop-traversal.mdRecursive SQL caps; company/contract/invoice/payment
references/retrieval-contract.mdReturn shape; path / provenance / confidence
references/evaluation-and-gates.mdGolden questions, recall, false-link, EXPLAIN
references/operations-and-scale.md1MM+ build, storage, retention, Timescale
references/anti-patterns.mdBefore marking report done

Snippets (illustrative SQL / one return type): templates/snippets/.

Handoff to ns-spec-driven

After human approval of Retrieval Design Report — and, when mode is relational GraphRAG and ns-graphrag is installed, after human approval of the GraphRAG Process Report:

## Retrieval implementation planning
- Report: path/to/retrieval-design-report.md (approved)
- GraphRAG Process Report: path/to/graphrag-process-report.md (approved | N/A if not GraphRAG or skill absent)
- Mode: vector-only | hybrid | relational GraphRAG
- Target DDL: [tables]
- Indexes: [HNSW / GIN / partition]
- Ingestion: [idempotent key + hash]
- Eval gates: [recall@k, path precision, false-link, p95]
- Out of scope for this skill: application code; GraphRAG process when ns-graphrag owns it

ns-spec-driven owns Specify / Tasks. This skill writes no application code. Do not add ns-graphrag to this skill’s depends.

Stop conditions

ConditionAction
Human asks for app implementationRequired reports first (incl. Process Report when GraphRAG + ns-graphrag); then ns-spec-driven only
Similarity proposed as stored edgeRefuse; candidate + confirm + provenance
Graph mode without N≥2 hop needRefuse graph; vector or hybrid
Competing vector store as defaultStay Postgres + pgvector
Unbounded recursive walkCap depth, fanout, cycles, score prune
Timescale with no temporal triggerDo not recommend
Inventory skippedBlock Gate 2

Forbidden

  • Implement retrieval layer (consumer migrations, workers, HTTP)
  • Embedding distance as link
  • External graph store as default
  • Treating the canonical hop illustration as the only allowed corpus chain without P0 derivation
  • Name application languages or frameworks (SQL/DDL allowed; one illustrative return-type snippet)

Comments

Markdown supported