Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Pgvector Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-pgvector-knowledge-patch-nevaberry-plugins)
---
name: pgvector-knowledge-patch
description: pgvector
version: "0.8.7"
license: MIT
metadata:
author: Nevaberry
---
# pgvector Knowledge Patch
Use this skill when upgrading pgvector, investigating filtered nearest-neighbor
results, working with vector types, or configuring builds and deployments.
## Reference index
| Reference | Topics |
| --- | --- |
| [Deployment](references/deployment.md) | PostgreSQL and Aurora compatibility, containers, packages, portable builds, Windows linking, hosted versions and resources |
| [Indexing and storage](references/indexing-and-storage.md) | IVFFlat upgrade requirements, tenant-local indexes, array casts, comparisons, storage, norms, empty averages |
| [Iterative scans and filtered search](references/iterative-scans.md) | Candidate limits, planner changes, relaxed-result sorting, distance cutoffs |
## Upgrade requirements and changed behavior
### PostgreSQL compatibility
pgvector 0.8.0 drops PostgreSQL 12 support. Upgrade the PostgreSQL server before
installing this extension release on a PostgreSQL 12 deployment.
For pgvector 0.8.0, minimum Aurora PostgreSQL engine versions are 13.20, 14.17,
15.12, 16.8, and 17.4 in their respective major series.
pgvector added support for PostgreSQL 18 RC1 in 0.8.1.
### IVFFlat upgrade and build requirements
When upgrading from 0.2.7 or 0.3.0 to 0.3.1 or later, recreate every existing
IVFFlat index after the upgrade to ensure all rows are indexed.
Upgrade to pgvector 0.8.6 or later before building IVFFlat indexes on 32-bit
systems. This release fixes a buffer overflow during index creation.
### Sparse array casts can now fail
Starting in 0.8.6, casting an array to `sparsevec` rejects inputs that exceed the
type's limit on nonzero elements. An array that cast successfully on an older
release can now raise an error.
### Empty averages
Starting in pgvector 0.8.7, an ungrouped `avg(embedding)` query returns SQL `NULL`
when its filter matches no rows.
## Filtered nearest-neighbor queries
### Investigate changed row counts
The revised index costing in 0.8.0 can change which plan serves a filtered
nearest-neighbor query even when `hnsw.iterative_scan` is `off`.
If a query returns more rows after upgrading, use `EXPLAIN` to check whether the
planner switched from an HNSW index scan to an exact scan followed by a sort.
### Iterative scan budgets
When filters leave too few matches in the initial index scan,
`hnsw.iterative_scan` and `ivfflat.iterative_scan` let their respective indexes
search for more candidates.
The search can still return fewer rows than the query's `LIMIT` if it reaches
`hnsw.max_scan_tuples` for HNSW or `ivfflat.max_probes` for IVFFlat.
The HNSW tuple budget is approximate and applies only after the initial scan.
For IVFFlat, `ivfflat.probes` is the minimum effective value of
`ivfflat.max_probes`.
```sql
SET ivfflat.iterative_scan = relaxed_order;
SET ivfflat.max_probes = 20;
```
### Sort relaxed-scan candidates
Keep the nearest-neighbor `ORDER BY` and `LIMIT` inside a subquery, then order by
`distance * 1` outside it to force a final sort of the returned candidates.
```sql
SET hnsw.iterative_scan = relaxed_order;
SELECT id, distance
FROM (
SELECT id, embedding <=> '[1,2,3]'::vector AS distance
FROM filtest
WHERE category = 1
ORDER BY distance
LIMIT 3
) AS candidates
ORDER BY candidates.distance * 1;
```
### Apply a distance cutoff after bounding results
Place the distance cutoff outside a materialized CTE. Keep ordinary filters,
the distance ordering, and the limit inside the CTE.
```sql
WITH nearest AS MATERIALIZED (
SELECT id, embedding <-> '[1,2,3]' AS distance
FROM items
WHERE category_id = 123
ORDER BY distance
LIMIT 5
)
SELECT id, distance FROM nearest WHERE distance < 5;
```
### Tenant-local approximate indexes
With a shared approximate index, other tenants' vectors can reduce recall for
a tenant-filtered search. List-partition by tenant so each partition has its
own vector index, and constrain the query by tenant to prune other partitions.
See [Indexing and storage](references/indexing-and-storage.md) for the SQL example.
## Vector types and functions
### Direct sparse casts
pgvector 0.8.0 can cast a numeric array directly to `sparsevec`. The array length
determines the vector dimension, and zero entries are omitted from storage.
```sql
SELECT ARRAY[0, 1, 0, 2]::sparsevec;
```
### Comparisons and storage
Starting in 0.7.0, comparison operators accept `vector` values with different
dimensions.
pgvector 0.6.0 changed the default storage strategy for `vector` from `EXTENDED`
to `EXTERNAL`. PostgreSQL can store large values out of line without compressing
them.
### Euclidean norms
Use `vector_norm()` for `vector` and `l2_norm()` for `halfvec` and `sparsevec`.
Both functions return `double precision`.
```sql
SELECT vector_norm('[3,4]'::vector),
l2_norm('[3,4]'::halfvec),
l2_norm('{1:3,2:4}/2'::sparsevec);
```
## Build and deployment quick reference
When raising `maintenance_work_mem` for a parallel HNSW build in a container,
set Docker's `--shm-size` to at least that value to avoid a build failure.
Some builds use `-march=native` by default. Compile with `make OPTFLAGS=""`
when deploying the resulting extension to a machine with a different CPU to
avoid illegal-instruction errors.
If building on Windows with PostgreSQL 17.0 through 17.2 fails to resolve
`float_to_shortest_decimal_bufn`, upgrade PostgreSQL to 17.3 or later before
rebuilding.
See [Deployment](references/deployment.md) for container tags, Homebrew targets,
the FreeBSD package, and hosted extension version selection.
### Hosted index builds
The hosted service's default `maintenance_work_mem` depends on compute size.
Before an HNSW or IVFFlat build, set it for the session to roughly the index
build's working-set size, capped at 50–60% of available RAM.
Raise `max_parallel_maintenance_workers` from its default of 2 toward the
available CPU count as needed, subject to `max_parallel_workers` (8) and
`max_worker_processes` (10).
See the [hosted deployment guidance](references/deployment.md#hosted-index-build-resources)
for the compute-dependent settings source and the 7 CU example.