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.

referencesvector-search.md

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

Semantic Vector Search

Use lakebase_vector for approximate nearest-neighbor retrieval over embeddings. It retains pgvector's vector types, distance operators, and query syntax; the index access method is lakebase_ann.

Contents

Create the Extension

Lakebase Search requires Postgres 16 or later. Enable the extension before creating vector columns or indexes:

CREATE EXTENSION IF NOT EXISTS lakebase_vector CASCADE;

lakebase_vector installs pgvector through CASCADE. 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 Embeddings

Use any embedding provider whose vector dimensions and distance metric match the schema and index:

CREATE TABLE documents (
  id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
  title text NOT NULL,
  body text NOT NULL,
  embedding vector(1536)
);

Replace 1536 with the embedding model's dimension. Generate stored-document and query embeddings with the same model and preprocessing. Keep embedding generation outside SQL unless the architecture already provides an in-database embedding function.

Build the Index

Choose the operator class and query operator as a matched pair:

Metric Common use Operator class Distance operator
Cosine Most text embeddings vector_cosine_ops <=>
L2 / Euclidean Absolute distance matters; vectors do not need normalization vector_l2_ops <->
Inner product Unit-normalized vectors; matches cosine for unit vectors vector_ip_ops <#>
CREATE INDEX documents_embedding_ann ON documents
  USING lakebase_ann (embedding vector_cosine_ops);

Tune the Index

The default index options suit most workloads:

  • build_mode = 'standard' balances recall and index build time. Use quality for better recall when a longer build is acceptable.
  • lists = 'auto' chooses the IVF partition layout from the number of indexed vectors. Choose between auto and a manual value case by case: test both on the target dataset and use the value that better meets recall and performance targets.

To prioritize recall over index build time:

CREATE INDEX documents_embedding_ann_quality ON documents
  USING lakebase_ann (embedding vector_cosine_ops)
  WITH (build_mode = 'quality');

To override the automatic partition layout instead:

CREATE INDEX documents_embedding_ann_lists ON documents
  USING lakebase_ann (embedding vector_cosine_ops)
  WITH (lists = '1024');

For a large table, use CREATE INDEX CONCURRENTLY to avoid locking out writes while creating the index. For a frequently changing table, periodically use REINDEX INDEX CONCURRENTLY to rebuild the index with minimal write locking.

Query

Generate the query embedding with the same model and preprocessing used for stored documents, then bind it as a parameter:

SELECT id, title, embedding <=> $1::vector AS distance
FROM documents
ORDER BY distance
LIMIT $2;

Distance sorts ascending: a smaller value is a closer match. Keep the query operator consistent with the index operator class.

To filter by a similarity radius, use the matching boolean range operator in WHERE and the distance operator in ORDER BY:

SELECT id, title
FROM documents
WHERE embedding <<=>> sphere($1::vector, 0.5)
ORDER BY embedding <=> $1::vector
LIMIT $2;

The cosine range operator <<=>> returns a boolean; do not use it as the ranking expression.

Tune Search

Inspect the index before overriding defaults:

SELECT lakebase_ann_index_info('documents_embedding_ann');

This reports lists, default_probes, and default_epsilon. Small datasets use exact flat search before IVF lists are built. In that state, lists and default_probes are empty. Leave lakebase_ann.probes set to its default of 'auto'; lakebase_ann.epsilon still controls full-precision reranking during flat search.

For an IVF index, lakebase_ann.probes controls how many partitions are searched at each level. Higher values generally improve recall at the cost of speed. Its default is 'auto'. When lists is not empty, the shape of probes must match the shape of lists: use one value for a one-level index or two comma-separated values for a two-level index. At each level, the probes value must be no larger than the corresponding lists value. A mismatched or out-of-range value causes an error.

lakebase_ann.epsilon controls how many candidates are reranked using full-precision distances. Higher values rerank more candidates and take longer. Its default is 'auto', which works well for most workloads.

Use Prefilter Selectively

By default, PostgreSQL applies non-vector filters after the ANN index returns candidate rows. Enable prefilter when a filter is cheap to evaluate and removes most rows. Leave it off for loose or expensive filters.

BEGIN;
SET LOCAL lakebase_ann.prefilter = on;

SELECT id, title
FROM documents
WHERE id % 100 = 0
ORDER BY embedding <=> $1::vector
LIMIT $2;
COMMIT;

Start with probes and epsilon set to 'auto'. Benchmark manual probe values against representative query embeddings and choose the smallest values that satisfy recall and tail-latency targets. Keep session settings and the query in the same transaction when using a connection pool or stateless driver.

Source: lakebase_vector 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.