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)
---
name: pgvector-knowledge-patch
description: pgvector
version: "0.8.7"
license: MIT
metadata:
author: Nevaberry
---
# pgvector Knowledge Patch
Use this skill when upgrading pgvector, building vector indexes, planning
filtered nearest-neighbor queries, working with vector values, or deploying
the extension.
## Reference index
| Reference | Topics |
| --- | --- |
| [Compatibility and Deployment](references/deployment.md) | PostgreSQL and Aurora compatibility, hosted extension versions, container tags, packages, portable builds, Windows linking |
| [Indexing and Storage](references/indexing-and-storage.md) | IVFFlat upgrade requirements, build resources, vector storage, sparse casts, comparisons, norms, averages |
| [Iterative Scans and Filtered Search](references/iterative-scans.md) | Iterative scan limits, planner changes, relaxed result ordering, tenant partitions, 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, the 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 and empty averages
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.
Starting in pgvector 0.8.7, an ungrouped `avg(embedding)` query returns SQL
`NULL` when its filter matches no rows.
## Filtered nearest-neighbor queries
### Check the plan when result counts change
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 scans and their limits
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;
```
### Final sorting for a relaxed scan
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;
```
### Tenant filters and distance cutoffs
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.
To bound the nearest-neighbor result before applying a distance cutoff, place
the cutoff outside a materialized CTE. Keep ordinary filters, the distance
ordering, and the limit inside the CTE.
See [Iterative Scans and Filtered Search](references/iterative-scans.md) for
the tenant partition and distance-cutoff SQL examples.
## Vector values and storage
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;
```
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.
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);
```
## Index-build resources
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.
On the hosted service, the 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 [Indexing and Storage](references/indexing-and-storage.md) for the hosted
settings link and a 7 CU compute example.
## Installation and deployment
The hosted service offers the latest supported pgvector release and the
immediately preceding published release. Check the supported version and pin
the predecessor explicitly; see the supported-extensions link in
[Compatibility and Deployment](references/deployment.md).
The pgvector 0.8.6 images come in Bookworm and Trixie variants for PostgreSQL
13 through 18. Tags without a distribution suffix, such as `0.8.6-pg18`,
select Bookworm.
`brew install pgvector` installs the extension for the `postgresql@17` and
`postgresql@18` formulas only. On FreeBSD, install the matching PostgreSQL 18
extension with `pkg install postgresql18-pgvector`.
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.