vector
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pgvector | 0.8.6 | RAG | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 1800 | vector | No | Yes | No | Yes | No | Yes | - |
| Related | vchord vectorscale pgcontext vectorize pg_rrf pg_search vchord_bm25 pg_bestmatch pgml pg4ml |
|---|---|
| Depended By | ai alloydb_scann avocado documentdb embedding_search hybrid_search maludb_core pg_cuvs pg_diskann pg_gembed pg_knowledge_graph pg_llm pg_llm_helper pg_search pg_semantic_cache pg_sentence_transformer pg_splade pg_turboquant pgcontext_pgvector pgedge_vectorizer pgmnemo pgpu pgturbohybrid pgvecutils rag rag_bge_small_en_v15 rag_jina_reranker_v1_tiny_en rds_ai rds_embedding vchord vectorize vectorscale |
Upstream and source archive are at pgvector 0.8.6; indexed PGDG RPM and DEB packages remain at 0.8.5 for PostgreSQL 14-18.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PGDG | 0.8.6 | 1817161514 | pgvector | - |
| RPM | PGDG | 0.8.6 | 1817161514 | pgvector_$v | - |
| DEB | PGDG | 0.8.6 | 1817161514 | postgresql-$v-pgvector | - |
Build
You can build the RPM / DEB packages for pgvector using pig build:
Install
You can install pgvector directly. First, make sure the PGDG repository is added and enabled:
Install the extension using pig or apt/yum/dnf:
Create Extension:
Usage
Sources:
pgvector provides vector similarity search inside PostgreSQL. The extension name is vector, while Pigsty packages it as pgvector. It supports exact search, approximate nearest-neighbor search with HNSW and IVFFlat indexes, and multiple vector representations for dense, half-precision, binary, and sparse embeddings.
Version 0.8.6 is a focused correctness release. It retains the 0.8.x HNSW iterative-scan and maintenance improvements documented in the current README.
Create and Query Vectors
Common distance operators:
<->for L2 distance<#>for negative inner product<=>for cosine distance<+>for L1 distance<~>for Hamming distance on binary vectors<%>for Jaccard distance on binary vectors
Because PostgreSQL indexes scan in ascending order, <#> returns the negative inner product; multiply by -1 when displaying the actual inner product.
Vector Types
vector is the standard single-precision type. Use halfvec to reduce storage and memory pressure, bit for binary signatures, and sparsevec for high-dimensional sparse vectors.
Aggregates such as avg() and sum() can be used with vector columns:
HNSW Indexes
HNSW gives strong speed/recall tradeoffs and does not require a training step.
Choose the operator class that matches the distance:
Useful tuning settings include hnsw.ef_search, hnsw.iterative_scan, hnsw.max_scan_tuples, and hnsw.scan_mem_multiplier.
IVFFlat Indexes
IVFFlat requires representative data before index creation because it trains cluster lists at build time.
Increase lists for larger tables and increase ivfflat.probes for higher recall. For filtered queries, test whether an exact btree filter, a partial vector index, or partitioning gives better plans.
Filtering and Hybrid Search
Normal PostgreSQL filters can be combined with vector ordering:
For hybrid search, combine pgvector with PostgreSQL full text search, trigram search, or an external ranking expression:
Maintenance
HNSW indexes can be large and expensive to build. Use maintenance_work_mem for builds, monitor build notices, and schedule REINDEX when index bloat or recall drift matters.
Caveats
- Version
0.8.6fixes an IVFFlat build overflow on 32-bit systems, enforcement of the nonzero-element limit when casting an array tosparsevec, and memory growth during IVFFlat scans inside nested loops. It does not add a new SQL feature surface. RunALTER EXTENSION vector UPDATEafter installing new extension files when the database reports an older SQL version. - Use the operator class that matches the query operator. A cosine index will not accelerate an L2
ORDER BY. - Approximate indexes trade exact recall for speed. Validate recall with representative data and query filters.
- Build IVFFlat after loading data. If data distribution changes substantially, rebuild the index.
- Keep pgvector updated when using HNSW with heavy writes and vacuum activity; the
0.8.xline includes important HNSW maintenance fixes.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)