Skip to content

pg_lion_vector

Filtered nearest-neighbor indexes for pgvector vector and halfvec

pg_lion · Filtered nearest-neighbor indexes for pgvector vector and halfvec

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
2717pg_lion_vectorpg_lion0.3.0FEATPostgreSQLC
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-rNoYesNoYesyesno
Relationships
Requirespg_lion vector
Siblingspg_lion pg_lion_citext
pgvector >= 0.7.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY0.3.019 18 17 16 15pg_lionpg_lion, vector
RPMPIGSTY0.3.019 18 17 16 15pg_lion_$vpgvector_$v
DEBPIGSTY0.3.019 18 17 16 15postgresql-$v-pg-lionpostgresql-$v-pgvector
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0N/A
el8.aarch64N/APIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0N/A
el9.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0N/A
el9.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0N/A
el10.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0N/A
el10.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0N/A
d12.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0N/A
d12.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0N/A
d13.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0N/A
d13.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0N/A
u22.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0N/A
u22.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0N/A
u24.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0N/A
u24.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0N/A
u26.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0N/A
u26.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0N/A

Source

pig build pkg pg_lion;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_lion;		# install by package name
pig install pg_lion_vector;		# install by extension name

pig install pg_lion_vector -v 19;   # install for PG 19
pig install pg_lion_vector -v 18;   # install for PG 18
pig install pg_lion_vector -v 17;   # install for PG 17
pig install pg_lion_vector -v 16;   # install for PG 16

Create this extension with:

CREATE EXTENSION pg_lion_vector CASCADE; -- requires pg_lion, vector

Usage

Sources:

pg_lion_vector 0.3.0 adds the lionvec nearest-neighbor access method for pgvector vector and halfvec values. It uses the parent pg_lion library and requires pgvector 0.7 or later.

Core Workflow

Create the parent and vector extensions first. A separate lion index can filter candidates before distance ranking.

CREATE EXTENSION vector;
CREATE EXTENSION pg_lion;
CREATE EXTENSION pg_lion_vector;
CREATE TABLE lion_items (id integer, category integer, embedding vector(3));
INSERT INTO lion_items VALUES (1, 3, '[1,0,0]'), (2, 3, '[0,1,0]'), (3, 4, '[0,0,1]');
CREATE INDEX lion_embedding ON lion_items USING lionvec (embedding vector_cosine_ops);
CREATE INDEX lion_category ON lion_items USING lion (category);
ALTER FUNCTION cosine_distance(vector, vector) COST 100;
VACUUM ANALYZE lion_items;
SELECT id FROM lion_items
WHERE category = 3
ORDER BY embedding <=> '[1,0,0]'::vector
LIMIT 10;

Upstream recommends COST 100 for the distance function used by the chosen operator class so the planner can compare scan and sort costs. This setting is not preserved by pg_dump and may be reset by an update of vector.

Operator Classes and Tuning

TypeL2 (<->)Negative inner product (<#>)Cosine (<=>)
vectorvector_l2_ops (default)vector_ip_opsvector_cosine_ops
halfvechalfvec_l2_ops (default)halfvec_ip_opshalfvec_cosine_ops

partitions controls the index build’s clustering; maintenance_work_mem must hold an adequate sample. pg_lion.vector_margin and pg_lion.vector_patience control approximate search. Small candidate sets under a supported lion filter can use exact scoring. pg_lion.vector_postfilter controls predicates the lion indexes cannot answer; review the reference before changing it.

Operational Boundaries

Requires PostgreSQL 16 or later and superuser installation. Only one vector or halfvec column, up to 8128 dimensions, is supported; this is generally approximate search. A filter does not turn every query into exact nearest-neighbor search. Heavy churn may require occasional REINDEX. Parent custom-WAL indexes retain their preload requirement. Keep parent and companion files at the same version.

Table reader