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.

referencesfull-text-search.md

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

Full-Text Search with BM25 Ranking

Use lakebase_text for BM25 relevance ranking with PostgreSQL's standard tsvector type. The lakebase_bm25 index adds corpus-aware ranking and top-K pushdown.

Lakebase Search requires Postgres 16 or later. Enable the extension before creating the index:

CREATE EXTENSION IF NOT EXISTS lakebase_text;

lakebase_text has no extension dependency. It relies on a preloaded library that Neon enables by default; if the project customized its preloaded-library list, confirm the library remains enabled.

Prepare and Index Text

Prefer a stored generated tsvector when search text comes from stable table columns:

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

Create the index after the initial corpus has been inserted so build-time corpus statistics are meaningful. BM25 scoring is tuned by two storage parameters set at index-build time:

  • k1 controls term-frequency saturation (default 1.2, range 1.2–2.0): higher values let repeated terms keep adding relevance.

  • b controls document-length normalization (default 0.75, range 0.0–1.0): higher values penalize longer documents more.

Both can only be set in the WITH clause, and updating them rebuilds the index:

CREATE INDEX documents_body_bm25 ON documents
  USING lakebase_bm25 (body_tsv)
  WITH (k1 = 1.2, b = 0.75);

After a large bulk load, run VACUUM to refresh the statistics used by BM25 scoring.

Query and Interpret Scores

to_bm25query binds the query tsvector to the BM25 index whose corpus statistics should be used. The <@> operator returns a negative BM25 score, so lower (more negative) values are more relevant and must sort ascending:

SELECT
  id,
  title,
  body_tsv <@> to_bm25query(
    to_tsvector('english', $1),
    'documents_body_bm25'::regclass
  ) AS score
FROM documents
ORDER BY score
LIMIT $2;

Use the same text-search configuration for document and query vectors. Select a language-specific or custom configuration that matches the corpus.

Set the Candidate Limit

lakebase_bm25.default_limit controls how many rows the index returns before PostgreSQL applies the SQL LIMIT. Its default is 1000; setting it close to the requested top-K avoids unnecessary scoring.

Use Prefilter Selectively

Enable prefilter when a WHERE condition is strict or unpredictable and cheap to evaluate. It lets the index prune rows before BM25 scoring. A loose or expensive filter can be slower with prefilter enabled.

BEGIN;
SET LOCAL lakebase_bm25.default_limit = 20;
SET LOCAL lakebase_bm25.prefilter = on;

SELECT
  id,
  title,
  body_tsv <@> to_bm25query(
    to_tsvector('english', $1),
    'documents_body_bm25'::regclass
  ) AS score
FROM documents
WHERE id % 1000 = 0
ORDER BY score
LIMIT $2;
COMMIT;

Set Parameters at Build Time or Per Query

Several BM25 parameters can be set in two places. As an index storage parameter in the CREATE INDEX WITH clause, a value is fed into the index as its build-time default. As a session GUC via SET (or SET LOCAL), it applies per query and takes precedence over the stored default when both are present.

  • default_limit and prefilter exist in both forms: set an index default that fits the common case, then override it per query with a GUC without rebuilding.
  • k1 (default 1.2) and b (default 0.75) are storage parameters only. There is no GUC for them.
  • enable_scan (default on) is a GUC only.

The examples use SET LOCAL so each override is scoped to its own transaction, which is required behind a connection pool or stateless driver.

Source: lakebase_text documentation.

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.