跳转到主要内容

pg_lion_vector

Filtered nearest-neighbor indexes for pgvector vector and halfvec

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

Overview

ID Extension Package Version Category License Language
2717 pg_lion_vector pg_lion 0.3.0 FEAT PostgreSQL C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d-r No Yes No Yes yes no
Relationships
Requires pg_lion vector
Siblings pg_lion pg_lion_citext
pgvector >= 0.7.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT PIGSTY 0.3.0 19 18 17 16 15 pg_lion pg_lion, vector
RPM PIGSTY 0.3.0 19 18 17 16 15 pg_lion_$v pgvector_$v
DEB PIGSTY 0.3.0 19 18 17 16 15 postgresql-$v-pg-lion postgresql-$v-pgvector
Linux / PG PG19 PG18 PG17 PG16 PG15
el8.x86_64 N/A PIGSTY 0.3.0 PIGSTY 0.3.0 PIGSTY 0.3.0 N/A
el8.aarch64 N/A PIGSTY 0.3.0 PIGSTY 0.3.0 PIGSTY 0.3.0 N/A
el9.x86_64 MISS PIGSTY 0.3.0 PIGSTY 0.3.0 PIGSTY 0.3.0 N/A
el9.aarch64 MISS PIGSTY 0.3.0 PIGSTY 0.3.0 PIGSTY 0.3.0 N/A
el10.x86_64 MISS PIGSTY 0.3.0 PIGSTY 0.3.0 PIGSTY 0.3.0 N/A
el10.aarch64 MISS PIGSTY 0.3.0 PIGSTY 0.3.0 PIGSTY 0.3.0 N/A
d12.x86_64 MISS PIGSTY 0.3.0 PIGSTY 0.3.0 PIGSTY 0.3.0 N/A
d12.aarch64 MISS PIGSTY 0.3.0 PIGSTY 0.3.0 PIGSTY 0.3.0 N/A
d13.x86_64 MISS PIGSTY 0.3.0 PIGSTY 0.3.0 PIGSTY 0.3.0 N/A
d13.aarch64 MISS PIGSTY 0.3.0 PIGSTY 0.3.0 PIGSTY 0.3.0 N/A
u22.x86_64 MISS PIGSTY 0.3.0 PIGSTY 0.3.0 PIGSTY 0.3.0 N/A
u22.aarch64 MISS PIGSTY 0.3.0 PIGSTY 0.3.0 PIGSTY 0.3.0 N/A
u24.x86_64 MISS PIGSTY 0.3.0 PIGSTY 0.3.0 PIGSTY 0.3.0 N/A
u24.aarch64 MISS PIGSTY 0.3.0 PIGSTY 0.3.0 PIGSTY 0.3.0 N/A
u26.x86_64 MISS PIGSTY 0.3.0 PIGSTY 0.3.0 PIGSTY 0.3.0 N/A
u26.aarch64 MISS PIGSTY 0.3.0 PIGSTY 0.3.0 PIGSTY 0.3.0 N/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 via package name, for the active PG version
pig install pg_lion_vector;		# install by extension name, for the current active PG version

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

Type L2 (<->) Negative inner product (<#>) Cosine (<=>)
vector vector_l2_ops (default) vector_ip_ops vector_cosine_ops
halfvec halfvec_l2_ops (default) halfvec_ip_ops halfvec_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.

表格阅读