LmCast :: Stay tuned in

Pg_vectorsearch: An index that is faster than pgvector's IVFFlat and HNSW

Recorded: Oct. 14, 2026, 12:10 p.m.

Original Summarized

GitHub - timescale/pg_vectorsearch: High-performance vector search for PostgreSQL · GitHub

Skip to content

Navigation MenuSign inAppearance settingsPlatformAI CODE CREATIONGitHub CopilotWrite better code with AIGitHub Copilot appDirect agents from issue to mergeMCP RegistryIntegrate external toolsDEVELOPER WORKFLOWSActionsAutomate any workflowCodespacesInstant dev environmentsIssuesPlan and track workCode ReviewManage code changesCode QualityEnforce quality at mergeAPPLICATION SECURITYGitHub Advanced SecurityFind and fix vulnerabilitiesCode securitySecure your code as you buildSecret protectionStop leaks before they startEXPLOREWhy GitHubDocumentationBlogChangelogMarketplaceView all featuresSolutionsBY COMPANY SIZEEnterprisesSmall and medium teamsStartupsNonprofitsBY USE CASEApp ModernizationDevSecOpsDevOpsCI/CDView all use casesBY INDUSTRYHealthcareFinancial servicesManufacturingGovernmentView all industriesView all solutionsResourcesEXPLORE BY TOPICAISoftware DevelopmentDevOpsSecurityView all topicsEXPLORE BY TYPECustomer storiesEvents & webinarsEbooks & reportsBusiness insightsGitHub SkillsSUPPORT & SERVICESDocumentationCustomer supportCommunity forumTrust centerPartnersView all resourcesOpen SourceCOMMUNITYGitHub SponsorsFund open source developersPROGRAMSSecurity LabMaintainer CommunityGitHub StarsArchive ProgramREPOSITORIESTopicsTrendingCollectionsEnterpriseENTERPRISE SOLUTIONSEnterprise platformAI-powered developer platformAVAILABLE ADD-ONSGitHub Advanced SecurityEnterprise-grade security featuresCopilot for BusinessEnterprise-grade AI featuresPremium SupportEnterprise-grade 24/7 supportPricingSearch/Sign inSign upAppearance settings

You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.
You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

timescalepg_vectorsearchRepository navigationCodeIssues29 (29)Pull requests8 (8)DiscussionsActionsProjectsSecurity and qualityInsightsMore items

pg_vectorsearchPublicNotificationsYou must be signed in to change notification settingsFork5 (5)Star76 (76)You must be signed in to star a repositoryAboutHigh-performance vector search for PostgreSQLResourcesReadmePostgreSQL licenseActivityCustom propertiesStars76 starsWatchers1 watchingForks5 forksReport repositorymainBranchesTagsGo to fileCodeOpen more actions menuLatest commit History437 Commits437 CommitsFolders and filesNameNameLast commit messageLast commit date.claude/skills.claude/skills  .github.github  docsdocs  imagesimages  scriptsscripts  sqlsql  srcsrc  testtest  third-partythird-party  .clang-format.clang-format  .clang-format-ignore.clang-format-ignore  .clang-tidy.clang-tidy  .clangd.clangd  .commitlintrc.yaml.commitlintrc.yaml  .gitattributes.gitattributes  .gitignore.gitignore  .markdownlint.json.markdownlint.json  .pre-commit-config.yaml.pre-commit-config.yaml  .release-notes-template.md.release-notes-template.md  .squawk.toml.squawk.toml  AGENTS.mdAGENTS.md  CHANGELOG.mdCHANGELOG.md  CLAUDE.mdCLAUDE.md  LICENSELICENSE  MakefileMakefile  README.mdREADME.md  VERSIONVERSION  clang-format-ignore.inclang-format-ignore.in  cliff.tomlcliff.toml  meson.buildmeson.build  meson_options.txtmeson_options.txt  pg_vectorsearch.control.inpg_vectorsearch.control.in  renovate.jsonrenovate.json  View all filesRepository files navigationREADMEPostgreSQL licenseMore itemspg_vectorsearch

A PostgreSQL extension for high-performance approximate nearest neighbor (ANN)
search.

Status: alpha. Meant for testing, not production. Upgrading
between prereleases may not be possible; plan to drop and recreate the
extension and its indexes. See the changelog for
known issues.

PRISM index (100M+ vectors) — IVF-style, with hierarchical routing
RaBitQ quantization with theoretical error bounds for two-stage search
SIMD-optimized distance computation (AVX2, AVX512, NEON)
Dynamic updates — inserts, updates and deletes, with posting-list
splits via prism_rebalance (see Maintenance)
pgvector compatible — index existing vector and halfvec columns
as-is (see Existing pgvector tables)

PRISM Index

PRISM (Partitioned Routing Index for Similarity Matching) is a PostgreSQL-native
index access method that is conceptually similar to pgvector's
IVFFlat, but it is built around state-of-the-art quantization, routing, and
partitioning techniques. It is implemented in C for high performance and
seamless integration with PostgreSQL.
The result: an index that is significantly faster than
pgvector's IVFFlat and HNSW, for both querying and index building. In fact,
compared to graph-based HNSW, PRISM is faster at equivalent recall on a
100-million-vector dataset, on an instance with a quarter of the memory.
To achieve this performance, PRISM uses a hierarchical centroid tree to
partition vectors into clusters, and relies on the PostgreSQL buffer cache to
keep that tree warm in memory. Vectors are RaBitQ-quantized and stored
in posting lists with a page layout optimized for SIMD distance computation. The
RaBitQ encoding carries error bounds that let a search rule out vectors that
cannot possibly be nearest neighbors, so far fewer of them need reranking
against the full-precision vectors stored in the table.
Query Flow:
1. Traverse centroid tree to find nearest clusters (buffer cache)
2. Scan posting lists for candidates (buffer cache, async I/O)
3. RaBitQ two-stage filtering: estimate → error bound → rerank
4. Full-precision reranking from heap
5. Return k nearest neighbors

For detailed architecture, see docs/architecture.md.
Usage
Install the extension first; see Building.
There are two ways to use a PRISM index. Pick the one that matches where
your vectors live:

Native types. Starting fresh, or not using
pgvector? Store vectors in pg_vectorsearch's own vec32 (float32) or
vec16 (float16) columns. No other extension is needed.
Existing pgvector tables. Already have
vector or halfvec columns? Install pg_vectorsearch next to
pgvector and build a PRISM index on those columns as they are. Your
table and queries stay unchanged.

Both paths build the same index and use the same operators (<->,
<#>, <=>) and tuning knobs.
Native types
CREATE EXTENSION pg_vectorsearch;

-- PLAIN keeps the vector inline. EXTERNAL (the default) toasts a value
-- over ~2 kB, and rerank then pays an extra fetch the planner does not cost.
CREATE TABLE items (
id serial PRIMARY KEY,
embedding vec32(3) STORAGE PLAIN
);

-- Load first; the index is sized from the row count at CREATE INDEX.
-- 500 rows is enough for the planner to use the index.
INSERT INTO items (embedding)
SELECT ARRAY[i::real, (i % 7)::real, (i % 5)::real]::vec32
FROM generate_series(1, 1000) i;

-- For inner product or cosine, see Operator classes below.
CREATE INDEX ON items USING prism (embedding vec32_l2_ops);

-- 0 = auto (~0.95 recall). Raise for recall, lower for speed.
SET prism.nprobe = 40;

SELECT * FROM items
ORDER BY embedding <-> '[3,1,2]'
LIMIT 5;
Use vec16 instead of vec32 to halve the space vectors take in the
table, with the matching vec16_* operator classes.
Existing pgvector tables
If you already have a table with pgvector's vector or halfvec
columns, you can build a PRISM index on it directly. Nothing about the
table or your queries needs to change.
vec32 and vec16 are binary-compatible with pgvector's vector and
halfvec but have different names, so the two extensions can be
installed side by side, even in the same schema.
-- The table you already have, included so the example runs on its own.
CREATE EXTENSION vector;

CREATE TABLE documents (
id bigserial PRIMARY KEY,
body text,
embedding vector(384)
);
CREATE INDEX documents_embedding_hnsw
ON documents USING hnsw (embedding vector_l2_ops);

-- Install pg_vectorsearch next to pgvector and build the index on the
-- existing column. The column is not rewritten or copied.
CREATE EXTENSION pg_vectorsearch;

CREATE INDEX documents_embedding_prism
ON documents USING prism (embedding vec32_l2_ops);

-- Your queries keep working as before. PRISM is normally faster, so
-- the planner should prefer it over the HNSW index while both exist.
-- Verify with an EXPLAIN:
EXPLAIN (COSTS OFF)
SELECT id, body
FROM documents
ORDER BY embedding <-> (SELECT embedding FROM documents WHERE id = 42)
LIMIT 10;
-- Limit
-- InitPlan 1
-- -> Index Scan using documents_pkey on documents documents_1
-- Index Cond: (id = 42)
-- -> Index Scan using documents_embedding_prism on documents
-- Order By: (embedding <-> (InitPlan 1).col1)

-- Once you are happy with it, drop the HNSW index.
DROP INDEX documents_embedding_hnsw;
Use the PRISM operator class for the same distance
metric as your HNSW index.
Operator classes
Pick the operator class for your distance metric and column type. L2 is
the default.

Distance
Operator
vec32 / vector
vec16 / halfvec

L2
<->
vec32_l2_ops
vec16_l2_ops

Inner product
<#>
vec32_ip_ops
vec16_ip_ops

Cosine
<=>
vec32_cosine_ops
vec16_cosine_ops

When replacing an HNSW index, pgvector's vector_<metric>_ops maps to
vec32_<metric>_ops and halfvec_<metric>_ops to vec16_<metric>_ops.
Tuning
Defaults are tuned from large-scale benchmarks; most deployments only
ever adjust prism.nprobe.
See the tuning guide for every index parameter and GUC,
their tradeoffs, and when changing them makes sense.
Maintenance
An insert appends to whichever posting list its vector routes to, so lists
grow as rows arrive and never split on their own. Besides REINDEX, the
prism_rebalance procedure splits oversized lists in place.
See the maintenance guide for how it works and its current
limitations.
Building
Requirements:

PostgreSQL 18+ (with development headers)
GNU C11 compiler (GCC 11+ or Clang 14+)
Meson build system
Optional: CBLAS, for faster RaBitQ encoding. See
Development.

# Release build
meson setup builddir --buildtype=release

# Build and install to PostgreSQL
meson install -C builddir
See the development guide for build
options.
Documentation

Tuning - Index parameters, GUCs, tradeoffs, defaults
Maintenance - Rebalancing and splitting posting lists
Architecture - High-level design and data structures
SIMD - SIMD build options and distance computation
Development - Build options, testing, CI scripts

References
Research

RaBitQ - Binary quantization with theoretical error bounds
(SIGMOD 2024)
SPFresh - LIRE protocol for incremental updates (SOSP 2023)
SPANN - Billion-scale ANN with boundary replication
(NeurIPS 2021)
ScaNN for AlloyDB - Hierarchical clustering (Google)

Related Projects

pgvector - Vector type and operators for PostgreSQL
pgvectorscale - DiskANN-based vector index for PostgreSQL

License
The PostgreSQL License
AboutHigh-performance vector search for PostgreSQLResourcesReadmePostgreSQL licenseActivityCustom propertiesStars76 starsWatchers1 watchingForks5 forksReport repositoryReleasesPackagesUsed byContributorsLanguages

Footer

© 2026 GitHub, Inc.

Footer navigation

Terms

Privacy

Security

Status

Community

Docs

Contact

Manage cookies

Do not share my personal information

You can’t perform that action at this time.

The pg_vectorsearch repository introduces a PostgreSQL extension designed to facilitate high-performance approximate nearest neighbor (ANN) search capabilities. At its core, the project implements the PRISM index, which is a PostgreSQL-native access method conceptually similar to pgvector's IVFFlat but built upon advanced quantization, routing, and partitioning techniques. This implementation is written in C to ensure high performance and seamless integration within the PostgreSQL environment.

The PRISM index achieves superior performance compared to methods like pgvector's IVFFlat and HNSW for both querying and index building. For instance, the system demonstrates speed advantages, achieving equivalent recall on a one-hundred-million-vector dataset while utilizing only a quarter of the memory required by graph-based HNSW structures. This performance gain is realized through several architectural choices. PRISM employs a hierarchical centroid tree to partition vectors into clusters, leveraging the PostgreSQL buffer cache to maintain this tree in memory. Vectors are further optimized by being RaBitQ-quantized, which involves encoding vectors using theoretical error bounds to allow the system to preemptively rule out vectors that cannot be nearest neighbors, thus reducing the necessity for full-precision reranking. The data is stored in posting lists with a page layout optimized for efficient SIMD distance computation using instructions like AVX2, AVX512, and NEON.

The query flow for a PRISM index involves a multi-stage process: first, traversing the centroid tree to locate the nearest clusters; second, scanning the corresponding posting lists for candidate vectors using the buffer cache and asynchronous input/output; third, performing a RaBitQ two-stage filtering process based on error estimation and bounds; fourth, executing full-precision reranking against the vectors stored in the heap; and finally, returning the top k nearest neighbors.

The implementation supports flexibility in how vectors are stored. Users have two primary paths for deployment: storing vectors in native columns within pg_vectorsearch, or building the index directly on existing vector or halfvec columns already present in pgvector tables. Both paths ultimately yield the same index structure and utilize consistent operators for distance metrics. The system defines specific operator classes for various distance metrics, including L2, inner product, and cosine similarity, which map to specific vector types such as vec32 and vec16.

Maintenance of the index is handled dynamically through posting lists, where inserts and updates append vectors to relevant lists. To manage growing lists without slow splitting operations, the system includes the prism_rebalance procedure, which splits oversized lists in place. Beyond indexing, the framework provides detailed options for tuning index parameters and Generalized Uncommitted Control (GUC) settings, which are based on large-scale benchmark results.

The development requires specific compiler and build system prerequisites, including PostgreSQL version 18 or later, a GNU C11 compiler (GCC 11+ or Clang 14+), and the Meson build system. The repository also references foundational research in approximate nearest neighbor search, including concepts from RaBitQ quantization, incremental update protocols, and hierarchical clustering methods. This foundation places pg_vectorsearch within the context of advanced machine learning algorithms applied to database indexing.