Cognibiz

pgvector v0.7.x: vector search inside PostgreSQLgithub.com/pgvector/pgvector

AI technologies, organized by technology area.

Official pgvector repository capture: SQL nearest-neighbor example and distance operators. Documentation, not a local execution.Inset: Cognibiz educational sketch: schematic shapes and arrows, without performance measurements or interface reproduction.Credit and source

The sketch explained

pgvector — Similarity in SQL

Table rows are sorted by vector distance.

On a small screen, scroll the diagram horizontally to read its labels.

pgvector — Similarity in SQLSQL query · Vectors in a table · Distance and sorting · Selected rows1SQL query2Vectors in atable3Distance andsorting4Selected rows
SQL query
Search uses vectors compatible with the data embedding space.
Vectors in a table
The collection stores vectors and associated data; an index supports retrieval.
Distance and sorting
The engine ranks candidates by the configured metric and constraints.
Selected rows
Proximity means similarity, not guaranteed truth or usefulness.
Cognibiz educational sketch: schematic shapes and arrows, without performance measurements or interface reproduction.Technical documentation
Updated

UNDERSTANDING THE SYSTEM

pgvector v0.7.x: vector search inside PostgreSQL

pgvector adds vector types and proximity indexes to PostgreSQL. This dossier uses v0.7.4 as its precise baseline: model compatibility, exact search, HNSW graphs, IVFFlat lists, filtering, recall and operations.

02 / CHAPTER

A database extension with a dated scope

pgvector brings vectors alongside relational rows: identifiers, text, categories and access permissions can remain in PostgreSQL. The engine computes distances and searches for neighbors. The extension does not generate embeddings itself, choose the model or guarantee that a nearby document correctly answers a question.

The 0.7.x family notably introduced halfvec, sparsevec and additional binary-vector indexing capabilities. This dossier pins examples to v0.7.4, released on August 5, 2024, rather than attributing features from a current README to that family. Availability of the extension with a hosting provider still needs checking.

Keeping vectors close to business data simplifies some architectures, but also shares resources: memory, processors, storage and maintenance support both transactions and search. The decision therefore needs a representative mixed workload, including bursts of writes, rather than a single isolated query.

References for this chapter[1][2]

03 / CHAPTER

The compatibility contract starts before the index

An embedding is a learned numerical representation of content. Its coordinates are not a readable list of features. Proximity depends on training and input processing: document chunking, language, length, normalization and potentially different instructions for queries and documents.

Two vectors with the same dimensionality are not necessarily comparable. Store the model identifier and revision, dimensionality, chunking policy and expected metric together. Use the query-processing path intended by that model; a query encoder can differ from the document encoder while still belonging to a compatible pair.

When changing models, create a separate space, recompute representations and compare results before switching. Silently mixing old and new coordinates distorts distances. A good index-recall value would not necessarily reveal this error: it measures fidelity to the vector ranking, not the relevance of the model.

References for this chapter[15]

04 / CHAPTER

Distances and SQL queries must agree

L2 distance measures Euclidean separation; cosine distance compares directions. The <=> operator returns a distance, so smaller is better. Cosine similarity is 1 minus that distance. Negative inner product <#> supports ascending sorting; do not confuse its sign with that of a similarity score.

Educational example in a test database where pgvector v0.7.4 is already installed: three documents hold three-dimensional vectors. No actual semantic model produced them. For the nonzero query [1,0,0], cosine-distance arithmetic ranks identifiers 1 and then 3 first. With the category 7 filter, the eligible rows are 1 and then 2. These results follow from the chosen vectors, not an executed benchmark.

For a cosine index, use vector_cosine_ops; for L2, use <-> with vector_l2_ops; for negative inner product, use <#> with vector_ip_ops. Keep the distance operator directly in ORDER BY and add LIMIT. Rewriting it as a similarity expression can prevent the expected index plan.

CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE documents (
  id bigint PRIMARY KEY,
  category_id int,
  embedding vector(3)
);
INSERT INTO documents VALUES
  (1, 7, '[1,0,0]'),
  (2, 7, '[0,1,0]'),
  (3, 9, '[1,1,0]');

SELECT id, embedding <=> '[1,0,0]'::vector AS distance
FROM documents
ORDER BY embedding <=> '[1,0,0]'::vector
LIMIT 2;

SELECT id, embedding <=> '[1,0,0]'::vector AS distance
FROM documents
WHERE category_id = 7
ORDER BY embedding <=> '[1,0,0]'::vector
LIMIT 2;
SQL example for a test database, not executed in this session. The two queries show the filter’s effect; three rows cannot evaluate an approximate index.

References for this chapter[3][1]

05 / CHAPTER

Exact search provides the comparison baseline

Exact search evaluates distances across the entire eligible set and retains the best k neighbors. It can read the whole table or just rows selected by a relational filter. Its ranking is the baseline for evaluating the index; that ranking is not human ground truth about document relevance.

An approximate index avoids examining every vector and can miss closer neighbors. Adding this index can therefore change results even when the SQL query stays identical. Choose approximation only after establishing the recall loss and latency acceptable to the service.

A small, highly selective subset can make exact search sufficient. Conversely, a large table does not automatically require HNSW: also measure dimensionality, filters, concurrent queries and available memory. NULL values and zero vectors for cosine require an explicit policy; they do not form an ordinary neighbor population.

References for this chapter[1]

06 / CHAPTER

HNSW builds a network of neighborhoods

HNSW organizes vectors into a multilayer graph. Search follows links to a promising region, then expands candidates at the lower level. It does not require prior training of cluster centers; the index can be created on an empty table. This removes neither insertion costs nor construction costs.

m and ef_construction affect the graph being built. hnsw.ef_search affects exploration during reads. These settings address different problems; increasing ef_search does not rebuild existing links.

Construction starts in memory and can move to disk when its budget is exceeded. maintenance_work_mem must remain compatible with other server activity. The graph generally needs more memory and construction effort than IVFFlat; its expected benefit is a better speed–recall tradeoff, which needs confirmation on the relevant data.

From a constructed graph to candidates

Conceptual diagram: steps represent functions, without measured distances, durations or topology.

Construction
Create neighbor links using m and ef_construction.
Upper levels
Reach a promising region of the graph.
Lower level
Explore candidates according to hnsw.ef_search.
Results
Return candidates; completeness still needs measuring.
CREATE INDEX documents_hnsw ON documents
USING hnsw (embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 64);
HNSW construction example, to compare separately with IVFFlat.

References for this chapter[4][5][1]

07 / CHAPTER

IVFFlat distributes vectors across lists

IVFFlat learns centers from a sample and assigns vectors to lists. During reads, it visits some lists near the query. Building after a representative load provides data for this training. An index built too early can poorly cover future neighborhoods.

This example assumes another sufficiently populated table, not the three demonstration rows. lists fixes the partition during construction; ivfflat.probes sets how many lists are visited during reads. The two proposed indexes are alternatives to compare separately.

Increasing probes explores more lists and requires more work. The probes/lists ratio is not a recall formula: neighbors are not distributed uniformly. Significant corpus drift warrants reassessing centers and rebuilding. The expected reduction in construction and memory costs relative to HNSW must be weighed against achieved recall.

CREATE INDEX documents_ivf ON documents
USING ivfflat (embedding vector_cosine_ops)
WITH (lists = 100);
IVFFlat example for a representative loaded corpus, not a recommendation to use one hundred lists for three rows.

References for this chapter[6][7][1]

08 / CHAPTER

A filter can exhaust the candidates

Consider WHERE category_id = 7 together with vector ranking. If the plan scans a global approximate index and then removes other categories, candidates can run out before LIMIT is satisfied. A short result therefore does not prove that the category contains few rows. Never remove an authorization filter to fill the result.

ANALYZE actually executes the query. Check the scan type, rows removed by filtering, reads and duration; estimated costs are not milliseconds. Three rows can legitimately produce a sequential scan.

Compare a relational index on category_id followed by exact ranking, a partial vector index for a stable category, or suitable partitioning. The planner must recognize the predicate of a partial index. In 0.7.4, increasing the search budget remains an explicit adjustment; iterative scans introduced in 0.8.0 are unavailable.

Two paths for the same filtered request

The path chosen by the planner changes cost and coverage. The filter remains mandatory in both cases.

  1. Request

    Find k neighbors in the authorized category.

  2. Exact path

    Select eligible rows, then calculate their distances.

  3. Approximate path

    Find global candidates, then remove ineligible rows.

  4. Check

    Compare recall and result count within the same population.

EXPLAIN (ANALYZE, BUFFERS)
SELECT id FROM documents
WHERE category_id = 7
ORDER BY embedding <=> '[1,0,0]'::vector
LIMIT 2;
Inspecting a filtered search plan. EXPLAIN ANALYZE executes the query; no actual timing is reported here.

References for this chapter[8][9][12][2]

09 / CHAPTER

Measure recall against a constant population

Define E_k as the identifiers of the k eligible exact neighbors and A_k as those returned by approximation. Index recall@k equals |E_k ∩ A_k| / |E_k|. Fix the same model, metric, filter and snapshot. For tied distances, declare a shared convention; otherwise identifier comparisons can penalize equivalent neighbors.

Synthetic example, with no executed benchmark: k = 5, at least five eligible rows and distinct distances. The sets are E_5 = {1,2,3,4,5} and A_5 = {1,2,4,8,9}. Three identifiers overlap, so recall@5 = 3/5 = 0.60. If filtering allows only {1,2,8} to return, recall is 2/5 = 0.40: the denominator remains five.

To establish the baseline, follow the project’s documented procedure: BEGIN ISOLATION LEVEL REPEATABLE READ; then SET LOCAL enable_indexscan = off; and run the exact query. Reenable enable_indexscan in that same transaction for the approximate trial, confirm plans and finish with COMMIT;. On an immutable corpus, also compare several hnsw.ef_search or ivfflat.probes settings, median and 95th-percentile latency, rare filters and incomplete results.

Three of the five right neighbors: make recall visible

Synthetic identifiers, distinct distances and at least five eligible rows. Blue: identifiers in the exact reference; amber: other candidates. Dashed slots indicate missing results. No database performance is measured.

Exact reference · 5 neighbors

Identifiers 1, 2, 3, 4 and 5 form the reference within the same authorized population.

Approximation · 5 results

Identifiers 1, 2 and 4 are recovered; 8 and 9 are outside the five nearest neighbors. Recall: 3/5.

Incomplete return · 3 results

Only 1, 2 and 8 are returned. Two reference neighbors are recovered: recall is 2/5, not 2/3.

References for this chapter[1][10][9]

10 / CHAPTER

Transactions, writes and maintenance remain essential

Updating text and its embedding in the same transaction avoids committing an inconsistent row when the vector is already available. If encoding is asynchronous, record content state and version, then exclude or flag stale representations. A PostgreSQL transaction does not automatically encompass a remote model call.

Inserts, updates and deletes maintain indexes and consume resources. Track size, writes, dead row versions and autovacuum; ANALYZE refreshes planner statistics. Test restoration and extension migration with the versions actually deployed before relying on recovery.

CREATE INDEX CONCURRENTLY reduces write blocking but adds work and waits; it cannot run inside a transaction block. After failure, check for an invalid index. For HNSW, the 0.7.4 documentation suggests considering reindexing before VACUUM when vacuuming becomes costly. Schedule these operations around resources and service windows rather than making them a universal automatic rule.

References for this chapter[10][11][13][1]

11 / CHAPTER

Combine signals and decide from evidence

Hybrid search combines vector candidates with PostgreSQL full-text search. The latter uses tsvector, tsquery and a language configuration; it can recover explicit terms that the embedding ranks poorly. Apply the same permissions and filters to both branches, then merge identifiers and deduplicate before presentation.

Rank-based fusion avoids assuming that cosine distance and lexical score share a scale. Reranking can then reassess candidates with a suitable model. These steps cannot recover a document missing from both initial lists. Candidate-list size, language and relevance judgments must be part of evaluation.

Choose an exact baseline first, then a solution meeting recall, latency and write requirements on the real corpus. Include embedding generation, index memory, backups and staff in total cost. No price or quantified vendor advantage is inferred here from the mechanisms described.

Combine signals and decide from evidence
SituationOption to tryEvidence required
Small filtered subsetRelational filter followed by exact searchAcceptable latency with no index-related loss.
Read-heavy workload, available memoryHNSWTarget recall with acceptable construction and write costs.
Representative corpus already loadedIVFFlatList and probe counts meeting measured recall requirements.
Explicit terms complement semantic similarityHybrid searchImproved business relevance judgments, permissions enforced in both branches.

References for this chapter[14][1]

ORIGINAL DOCUMENT

Catalog record

5. Vector databases and semantic indexing

pgvector github.com/pgvector/pgvector v0.7.x — Innovation: 7, Adoption: 9

7/10Innovation
9/10Adoption

Editorial source: Taxonomie des Technologies d'Intelligence Artificielle · § 7535. Addresses restored with dots; innovation and adoption scores remain those of the document.

VERIFY AND EXPLORE

References

The editorial entry retains v0.7.x and the Innovation 7 / Adoption 9 scores; these are source assessments, not independent measurements. Examples target pgvector v0.7.4 with PostgreSQL 16. Iterative scans introduced in v0.8.0 are excluded. SQL examples and figures are educational; no PostgreSQL benchmark was run for this guide.

  1. 01
    pgvector — v0.7.4 documentation

    Features and syntax of the selected version; no measurements in this dossier come from this document.

    raw.githubusercontent.com ·
  2. 02
    pgvector — release history through v0.8.0

    Dates of 0.7.x releases and introduction of iterative scans in 0.8.0.

    raw.githubusercontent.com ·
  3. 03
    pgvector v0.7.4 — SQL operators

    Distance declarations and operator classes associated with index methods.

    raw.githubusercontent.com ·
  4. 04
    pgvector v0.7.4 — HNSW parameters

    Separation of construction and search parameters.

    raw.githubusercontent.com ·
  5. 05
    pgvector v0.7.4 — HNSW construction

    In-memory and on-disk phases controlled by maintenance_work_mem.

    raw.githubusercontent.com ·
  6. 06
    pgvector v0.7.4 — IVFFlat parameters

    Lists, probes and scan-cost estimation.

    raw.githubusercontent.com ·
  7. 07
    pgvector v0.7.4 — IVFFlat construction

    Sampling and construction of cluster centers.

    raw.githubusercontent.com ·
  8. 08
    pgvector v0.7.4 — HNSW scans

    Initial candidate selection and MVCC snapshot requirements.

    raw.githubusercontent.com ·
  9. 09
    PostgreSQL 16 — reading execution plans

    EXPLAIN, actual measurements and the distinction between estimated costs and durations.

    www.postgresql.org ·
  10. 10
    PostgreSQL 16 — transaction isolation

    Read snapshots and the difference between Read Committed and Repeatable Read.

    www.postgresql.org ·
  11. 11
    PostgreSQL 16 — index creation

    Concurrent creation, waits, invalid indexes and transaction restrictions.

    www.postgresql.org ·
  12. 12
    PostgreSQL 16 — partial indexes

    Indexed subsets and planner recognition of predicates.

    www.postgresql.org ·
  13. 13
    PostgreSQL 16 — routine maintenance

    Row versions, VACUUM, ANALYZE and database maintenance.

    www.postgresql.org ·
  14. 14
    PostgreSQL 16 — full-text search

    tsvector, tsquery, language configurations and lexical ranking.

    www.postgresql.org ·
  15. 15
    Google — learned vector representations

    Introduction to embeddings; migration advice is editorial analysis.

    developers.google.com ·

Catalog provenance

Taxonomie des Technologies d'Intelligence Artificielle · Google Docs

Source document consulted October 20, 2026; reread November 2, 2026 for this update. § 7535.

Websites cited in the record

A website’s inclusion in the catalog does not verify the versions, projections or results mentioned in the document.

FROM KNOWLEDGE TO PROJECT

Apply this knowledge to your context.

Scope, architecture, roadmap and notes: keep your decisions in the dedicated space.

Open dedicated space