All skills
neondatabase avatar

/neon-postgres

@dd290a9 official

Guides and best practices for working with Lakebase Postgres on Neon: connections, pooled vs direct, schema migrations, branching, autoscaling, scale-to-zero, instant restore, read replicas, IP allow lists, logical replication, and Lakebase Search. Use when the work is an existing DATABASE_URL, SQL, schema, inspect, or search. New backends, Auth, files, Functions, and LLM calls go to the parent `neon` skill. Also use for "@neondatabase/serverless", "@neondatabase/neon-js", "neon inspect db", "semantic search", "vector search", "full-text search", "BM25", or "hybrid search".

Use this Skill: https://skilld.dev/gh/neondatabase/agent-skills/neon-postgres

This session only. Nothing lands on disk.

referenceshybrid-search.md

≈1.1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Hybrid Search

Use hybrid search when either semantic similarity or exact vocabulary can identify a relevant document. Lakebase Search does not provide a built-in hybrid function: run vector and BM25 retrieval separately, then combine their results with a fusion strategy suited to the workload.

Lakebase Search requires Postgres 16 or later. Hybrid search uses both extensions:

CREATE EXTENSION IF NOT EXISTS lakebase_vector CASCADE;
CREATE EXTENSION IF NOT EXISTS lakebase_text;

lakebase_vector installs pgvector through CASCADE; lakebase_text has no extension dependency. Both rely on preloaded libraries that Neon enables by default. If the project customized its preloaded-library list, confirm both libraries remain enabled.

Prepare a table with both vector and text-search columns:

CREATE TABLE documents (
  id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
  title text NOT NULL,
  body text NOT NULL,
  embedding vector(1536),
  body_tsv tsvector GENERATED ALWAYS AS
    (to_tsvector('english', body)) STORED
);

Replace 1536 with the embedding model's dimension. Use the same model and preprocessing for stored-document and query embeddings, and choose a PostgreSQL text-search configuration appropriate for the corpus.

Create and validate each retriever independently before combining them. Follow Vector search and Full-text search for their indexes, query operators, and tuning.

Reciprocal Rank Fusion (RRF) is the approach in the Lakebase Search get-started guide and a useful default because it combines ranks instead of incomparable raw distances and scores. It is not the only option: weighted rank fusion, normalized score fusion, or a reranker may fit applications with different relevance signals.

RRF Example

For rank r and constant k, each retriever contributes 1 / (k + r). The documented starting point uses 40 candidates per retriever and k = 60; tune both for the corpus and workload.

Bind the query embedding as $1, query text as $2, and final result count as $3:

WITH vector_ranked AS (
  SELECT id, RANK() OVER (ORDER BY distance) AS rank
  FROM (
    SELECT id, embedding <=> $1::vector AS distance
    FROM documents
    ORDER BY distance
    FETCH FIRST 40 ROWS WITH TIES
  ) AS vector_candidates
),
keyword_ranked AS (
  SELECT id, RANK() OVER (ORDER BY score) AS rank
  FROM (
    SELECT
      id,
      body_tsv <@> to_bm25query(
        to_tsvector('english', $2),
        'documents_body_bm25'::regclass
      ) AS score
    FROM documents
    ORDER BY score
    FETCH FIRST 40 ROWS WITH TIES
  ) AS keyword_candidates
)
SELECT
  d.id,
  d.title,
  COALESCE(1.0 / (60 + v.rank), 0) +
    COALESCE(1.0 / (60 + k.rank), 0) AS rrf_score
FROM documents AS d
LEFT JOIN vector_ranked AS v ON v.id = d.id
LEFT JOIN keyword_ranked AS k ON k.id = d.id
WHERE v.id IS NOT NULL OR k.id IS NOT NULL
ORDER BY rrf_score DESC, d.id
LIMIT $3;

RANK() gives tied retrieval scores the same rank. Sort by rrf_score descending and use the stable ID as a final tie-breaker.

FETCH FIRST ... ROWS WITH TIES keeps every candidate tied at the cutoff, so RANK() receives the complete boundary tie group. The candidate set can therefore exceed 40 rows. lakebase_bm25.default_limit defaults to 1000; increase it only when the BM25 candidate set needs to exceed that value.

Adapt the Hybrid Search

  • Retrieve more candidates from each source than the final result count; otherwise one retriever can dominate before fusion has enough overlap. Keep lakebase_bm25.default_limit above the BM25 candidate target and allow room for boundary ties.
  • Keep each retriever's operator and index configuration correct independently before tuning RRF.
  • Tune candidate counts and the RRF constant with judged or behavioral relevance data, plus latency measurements.
  • Add weights only when product evidence shows one retriever should contribute more. Weight the reciprocal-rank contributions, not the raw vector distance and negative BM25 score.
  • Apply the same access-control and tenant filters to both candidate CTEs. If BM25 filters are strict and cheap, evaluate whether lakebase_bm25.prefilter improves the filtered query.

Source: Lakebase Search get-started guide.

Source: SKILL.md on GitHub

No alerts7d5 checks · Risk SAFE
  • Gen Agent Trust Hub7d

    The skill provides a comprehensive set of instructions and references for managing Neon Postgres databases. It includes procedures for project setup, connection management, schema migrations, and performance diagnostics using the official Neon CLI and MCP server. It also features detailed technical guides for semantic vector search, full-text search, and hybrid search strategies. No security issues were detected, and the skill follows industry best practices for environment variable management and vendor tool utilization.

  • Socket7d

    No alerts

  • Snyk7d

    Risk: LOW · No issues

  • Runlayer7mo

    4/14 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at dd290a9. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last week.

Activeupdated last week
Other metadata
metadata
{
  "parent": "neon",
  "source": "https://github.com/neondatabase/agent-skills/tree/main/skills/neon-postgres"
}

README badge

README badge for neondatabase/agent-skills/neon-postgres

Guides setup, connections, branching, and advanced features for Neon Serverless Postgres. Covers the Neon CLI, MCP server, REST API, TypeScript and Python SDKs, connection pooling strategies for different runtimes (node-postgres vs. serverless driver), Neon Auth, and infrastructure-as-code via neon.ts. Use when a user asks about Neon setup, DATABASE_URL, scale-to-zero, autoscaling, read replicas, or connecting an ORM like Drizzle.

Generated from the current SKILL.md.

Does Neon work with my ORM or database client?
Yes. Neon is fully compatible with Postgres, so it works with any language, framework, or ORM that supports Postgres — including Drizzle, Prisma, TypeORM, node-postgres, and the Neon serverless driver. Pick the driver based on your runtime: use node-postgres for long-running environments and the serverless driver for fully-isolated serverless platforms like Netlify.
What's the difference between the serverless driver and node-postgres?
The serverless driver (@neondatabase/serverless) queries over HTTP and is designed for fully-isolated serverless runtimes like Netlify where a persistent TCP connection can't be reused per request. node-postgres (pg) maintains a persistent connection pool and is better for long-running or shared-runtime environments like Vercel Fluid compute or Neon Functions.
Can I use this skill to set up a new Neon project from scratch?
Yes. Run `npx -y neonctl@latest init --agent <agent-name>` to automatically create an API key, set up the MCP server or extension, install the skill, and guide you through project selection or creation. This is the recommended starting point.
Does this skill cover Neon Auth setup?
Yes. The skill covers Neon Auth setup, including provisioning it via the MCP server and integrating it with the Neon JS SDK for combined auth and data API workflows. Skip it if your app doesn't need user authentication.
Can I use infrastructure-as-code to configure Neon branches?
Yes, via `neon.ts` (from @neondatabase/config). Declare which services (Neon Auth, Data API) your branches need and per-branch compute settings like autoscaling and scale-to-zero, then use `neonctl config apply` to provision them.

Generated from the current SKILL.md. These answers refresh after source changes.