---
name: "postgres-pgvector-index"
description: "Store and query dense vector embeddings alongside relational data using pgvector HNSW and IVFFlat."
metadata:
  author: "pgvector"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "create pgvector index"
  - "query vector distance postgresql"
  - "tune hnsw index params"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# PostgreSQL pgvector Vector Search Tuning

Implements pgvector similarity search on PostgreSQL: creating vector columns, configuring HNSW vs IVFFlat indexes, tuning m and ef_construction parameters, and writing fast cosine distance (<=>) queries.

## When to Invoke
Invoke this skill whenever you need to:
- create pgvector index
- query vector distance postgresql
- tune hnsw index params

## Execution SOP & Rules
1. Enable extension with CREATE EXTENSION IF NOT EXISTS vector;
2. Define column data type as vector(dimension) according to embedding model specifications.
3. Build HNSW index with USING hnsw (embedding vector_cosine_ops) WITH (m = 16, ef_construction = 64).
4. Set local query parameter SET hnsw.ef_search = 40 before running low-latency similarity queries.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
