mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-22 03:57:34 +08:00
Compare commits
17 Commits
cb246cb72d
...
hnsw-tidst
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0587d4b834 | ||
|
|
89fda3e100 | ||
|
|
30d8654b47 | ||
|
|
a846385cc7 | ||
|
|
98d7c4124e | ||
|
|
2a2b4a0b58 | ||
|
|
f15a50387f | ||
|
|
971b7d7fd6 | ||
|
|
f51d8ed989 | ||
|
|
a76a18d526 | ||
|
|
b383e4d191 | ||
|
|
1d458ad5d7 | ||
|
|
9fa17c10b8 | ||
|
|
14149b19f5 | ||
|
|
34d796fbab | ||
|
|
53341bb6c7 | ||
|
|
0d9720f440 |
@@ -1,7 +1,12 @@
|
||||
## 0.8.4 (unreleased)
|
||||
## 0.8.5 (unreleased)
|
||||
|
||||
- Reduced memory usage for small tables for IVFFlat index builds
|
||||
|
||||
## 0.8.4 (2026-06-30)
|
||||
|
||||
- Fixed `hnsw graph not repaired` error with HNSW vacuuming
|
||||
- Fixed possible error with inserts during HNSW vacuuming
|
||||
- Fixed memory exceeding `maintenance_work_mem` with IVFFlat index builds
|
||||
|
||||
## 0.8.3 (2026-06-17)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ ARG DEBIAN_CODENAME=bookworm
|
||||
FROM postgres:$PG_MAJOR-$DEBIAN_CODENAME
|
||||
ARG PG_MAJOR
|
||||
|
||||
ADD https://github.com/pgvector/pgvector.git#v0.8.3 /tmp/pgvector
|
||||
ADD https://github.com/pgvector/pgvector.git#v0.8.4 /tmp/pgvector
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-mark hold locales && \
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "vector",
|
||||
"abstract": "Open-source vector similarity search for Postgres",
|
||||
"description": "Supports L2 distance, inner product, and cosine distance",
|
||||
"version": "0.8.3",
|
||||
"version": "0.8.4",
|
||||
"maintainer": [
|
||||
"Andrew Kane <andrew@ankane.org>"
|
||||
],
|
||||
@@ -20,7 +20,7 @@
|
||||
"vector": {
|
||||
"file": "sql/vector.sql",
|
||||
"docfile": "README.md",
|
||||
"version": "0.8.3",
|
||||
"version": "0.8.4",
|
||||
"abstract": "Open-source vector similarity search for Postgres"
|
||||
}
|
||||
},
|
||||
|
||||
2
Makefile
2
Makefile
@@ -1,5 +1,5 @@
|
||||
EXTENSION = vector
|
||||
EXTVERSION = 0.8.3
|
||||
EXTVERSION = 0.8.4
|
||||
|
||||
MODULE_big = vector
|
||||
DATA = $(wildcard sql/*--*--*.sql)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
EXTENSION = vector
|
||||
EXTVERSION = 0.8.3
|
||||
EXTVERSION = 0.8.4
|
||||
|
||||
DATA_built = sql\$(EXTENSION)--$(EXTVERSION).sql
|
||||
OBJS = src\bitutils.obj src\bitvec.obj src\halfutils.obj src\halfvec.obj src\hnsw.obj src\hnswbuild.obj src\hnswinsert.obj src\hnswscan.obj src\hnswutils.obj src\hnswvacuum.obj src\ivfbuild.obj src\ivfflat.obj src\ivfinsert.obj src\ivfkmeans.obj src\ivfscan.obj src\ivfutils.obj src\ivfvacuum.obj src\sparsevec.obj src\vector.obj
|
||||
|
||||
30
README.md
30
README.md
@@ -23,7 +23,7 @@ Compile and install the extension (supports Postgres 13+)
|
||||
|
||||
```sh
|
||||
cd /tmp
|
||||
git clone --branch v0.8.3 https://github.com/pgvector/pgvector.git
|
||||
git clone --branch v0.8.4 https://github.com/pgvector/pgvector.git
|
||||
cd pgvector
|
||||
make
|
||||
make install # may need sudo
|
||||
@@ -40,7 +40,7 @@ Ensure [C++ support in Visual Studio](https://learn.microsoft.com/en-us/cpp/buil
|
||||
```cmd
|
||||
set "PGROOT=C:\Program Files\PostgreSQL\18"
|
||||
cd %TEMP%
|
||||
git clone --branch v0.8.3 https://github.com/pgvector/pgvector.git
|
||||
git clone --branch v0.8.4 https://github.com/pgvector/pgvector.git
|
||||
cd pgvector
|
||||
nmake /F Makefile.win
|
||||
nmake /F Makefile.win install
|
||||
@@ -1151,23 +1151,23 @@ This adds pgvector to the [Postgres image](https://hub.docker.com/_/postgres) (r
|
||||
|
||||
Supported tags are:
|
||||
|
||||
- `pg18-trixie`, `0.8.3-pg18-trixie`
|
||||
- `pg18-bookworm`, `0.8.3-pg18-bookworm`, `pg18`, `0.8.3-pg18`
|
||||
- `pg17-trixie`, `0.8.3-pg17-trixie`
|
||||
- `pg17-bookworm`, `0.8.3-pg17-bookworm`, `pg17`, `0.8.3-pg17`
|
||||
- `pg16-trixie`, `0.8.3-pg16-trixie`
|
||||
- `pg16-bookworm`, `0.8.3-pg16-bookworm`, `pg16`, `0.8.3-pg16`
|
||||
- `pg15-trixie`, `0.8.3-pg15-trixie`
|
||||
- `pg15-bookworm`, `0.8.3-pg15-bookworm`, `pg15`, `0.8.3-pg15`
|
||||
- `pg14-trixie`, `0.8.3-pg14-trixie`
|
||||
- `pg14-bookworm`, `0.8.3-pg14-bookworm`, `pg14`, `0.8.3-pg14`
|
||||
- `pg13-trixie`, `0.8.3-pg13-trixie`
|
||||
- `pg13-bookworm`, `0.8.3-pg13-bookworm`, `pg13`, `0.8.3-pg13`
|
||||
- `pg18-trixie`, `0.8.4-pg18-trixie`
|
||||
- `pg18-bookworm`, `0.8.4-pg18-bookworm`, `pg18`, `0.8.4-pg18`
|
||||
- `pg17-trixie`, `0.8.4-pg17-trixie`
|
||||
- `pg17-bookworm`, `0.8.4-pg17-bookworm`, `pg17`, `0.8.4-pg17`
|
||||
- `pg16-trixie`, `0.8.4-pg16-trixie`
|
||||
- `pg16-bookworm`, `0.8.4-pg16-bookworm`, `pg16`, `0.8.4-pg16`
|
||||
- `pg15-trixie`, `0.8.4-pg15-trixie`
|
||||
- `pg15-bookworm`, `0.8.4-pg15-bookworm`, `pg15`, `0.8.4-pg15`
|
||||
- `pg14-trixie`, `0.8.4-pg14-trixie`
|
||||
- `pg14-bookworm`, `0.8.4-pg14-bookworm`, `pg14`, `0.8.4-pg14`
|
||||
- `pg13-trixie`, `0.8.4-pg13-trixie`
|
||||
- `pg13-bookworm`, `0.8.4-pg13-bookworm`, `pg13`, `0.8.4-pg13`
|
||||
|
||||
You can also build the image manually:
|
||||
|
||||
```sh
|
||||
git clone --branch v0.8.3 https://github.com/pgvector/pgvector.git
|
||||
git clone --branch v0.8.4 https://github.com/pgvector/pgvector.git
|
||||
cd pgvector
|
||||
docker build --pull --build-arg PG_MAJOR=18 -t myuser/pgvector .
|
||||
```
|
||||
|
||||
2
sql/vector--0.8.3--0.8.4.sql
Normal file
2
sql/vector--0.8.3--0.8.4.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "ALTER EXTENSION vector UPDATE TO '0.8.4'" to load this file. \quit
|
||||
10
src/hnsw.c
10
src/hnsw.c
@@ -290,7 +290,11 @@ hnswhandler(PG_FUNCTION_ARGS)
|
||||
.amcanparallel = false,
|
||||
.amcanbuildparallel = true,
|
||||
.amcaninclude = false,
|
||||
#if PG_VERSION_NUM >= 170000
|
||||
.amusemaintenanceworkmem = true,
|
||||
#else
|
||||
.amusemaintenanceworkmem = false,
|
||||
#endif
|
||||
.amsummarizing = false,
|
||||
.amparallelvacuumoptions = VACUUM_OPTION_PARALLEL_BULKDEL,
|
||||
.amkeytype = InvalidOid,
|
||||
@@ -351,7 +355,11 @@ hnswhandler(PG_FUNCTION_ARGS)
|
||||
amroutine->amcanbuildparallel = true;
|
||||
#endif
|
||||
amroutine->amcaninclude = false;
|
||||
amroutine->amusemaintenanceworkmem = false; /* not used during VACUUM */
|
||||
#if PG_VERSION_NUM >= 170000
|
||||
amroutine->amusemaintenanceworkmem = true;
|
||||
#else
|
||||
amroutine->amusemaintenanceworkmem = false;
|
||||
#endif
|
||||
#if PG_VERSION_NUM >= 160000
|
||||
amroutine->amsummarizing = false;
|
||||
#endif
|
||||
|
||||
@@ -26,6 +26,12 @@
|
||||
typedef Pointer Item;
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM >= 170000
|
||||
#define HnswTidStore TidStore
|
||||
#else
|
||||
#define HnswTidStore tidhash_hash
|
||||
#endif
|
||||
|
||||
#define HNSW_MAX_DIM 2000
|
||||
#define HNSW_MAX_NNZ 1000
|
||||
|
||||
@@ -427,7 +433,7 @@ typedef struct HnswVacuumState
|
||||
HnswSupport support;
|
||||
|
||||
/* Variables */
|
||||
struct tidhash_hash *deleting;
|
||||
struct HnswTidStore *deleting;
|
||||
BufferAccessStrategy bas;
|
||||
HnswNeighborTuple ntup;
|
||||
HnswElementData highestPoint;
|
||||
|
||||
@@ -10,6 +10,12 @@
|
||||
#include "utils/memutils.h"
|
||||
#include "utils/rel.h"
|
||||
|
||||
#if PG_VERSION_NUM >= 170000
|
||||
#include "access/tidstore.h"
|
||||
#include "miscadmin.h"
|
||||
#include "postmaster/autovacuum.h"
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM >= 160000
|
||||
#include "varatt.h"
|
||||
#endif
|
||||
@@ -22,9 +28,13 @@
|
||||
* Check if deletion list contains an element
|
||||
*/
|
||||
static bool
|
||||
DeletingElement(tidhash_hash * deleting, ItemPointer indextid)
|
||||
DeletingElement(HnswTidStore * deleting, ItemPointer indextid)
|
||||
{
|
||||
#if PG_VERSION_NUM >= 170000
|
||||
return TidStoreIsMember(deleting, indextid);
|
||||
#else
|
||||
return tidhash_lookup(deleting, *indextid) != NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -60,6 +70,10 @@ RemoveHeapTids(HnswVacuumState * vacuumstate)
|
||||
OffsetNumber offno;
|
||||
OffsetNumber maxoffno;
|
||||
bool updated = false;
|
||||
#if PG_VERSION_NUM >= 170000
|
||||
OffsetNumber deletedoffs[MaxOffsetNumber];
|
||||
int ndeletedoffs = 0;
|
||||
#endif
|
||||
|
||||
vacuum_delay_point();
|
||||
|
||||
@@ -121,6 +135,9 @@ RemoveHeapTids(HnswVacuumState * vacuumstate)
|
||||
|
||||
if (!ItemPointerIsValid(&etup->heaptids[0]))
|
||||
{
|
||||
#if PG_VERSION_NUM >= 170000
|
||||
deletedoffs[ndeletedoffs++] = offno;
|
||||
#else
|
||||
ItemPointerData indextid;
|
||||
bool found;
|
||||
|
||||
@@ -129,6 +146,7 @@ RemoveHeapTids(HnswVacuumState * vacuumstate)
|
||||
|
||||
tidhash_insert(vacuumstate->deleting, indextid, &found);
|
||||
Assert(!found);
|
||||
#endif
|
||||
}
|
||||
else if (etup->level > highestLevel)
|
||||
{
|
||||
@@ -157,6 +175,10 @@ RemoveHeapTids(HnswVacuumState * vacuumstate)
|
||||
}
|
||||
}
|
||||
|
||||
#if PG_VERSION_NUM >= 170000
|
||||
TidStoreSetBlockOffsets(vacuumstate->deleting, blkno, deletedoffs, ndeletedoffs);
|
||||
#endif
|
||||
|
||||
blkno = HnswPageGetOpaque(page)->nextblkno;
|
||||
|
||||
if (updated)
|
||||
@@ -756,7 +778,11 @@ InitVacuumState(HnswVacuumState * vacuumstate, IndexVacuumInfo *info, IndexBulkD
|
||||
HnswGetMetaPageInfo(index, &vacuumstate->m, NULL);
|
||||
|
||||
/* Create hash table */
|
||||
#if PG_VERSION_NUM >= 170000
|
||||
vacuumstate->deleting = TidStoreCreateLocal((AmAutoVacuumWorkerProcess() && autovacuum_work_mem != -1) ? autovacuum_work_mem : maintenance_work_mem, true);
|
||||
#else
|
||||
vacuumstate->deleting = tidhash_create(CurrentMemoryContext, 256, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -765,7 +791,11 @@ InitVacuumState(HnswVacuumState * vacuumstate, IndexVacuumInfo *info, IndexBulkD
|
||||
static void
|
||||
FreeVacuumState(HnswVacuumState * vacuumstate)
|
||||
{
|
||||
#if PG_VERSION_NUM >= 170000
|
||||
TidStoreDestroy(vacuumstate->deleting);
|
||||
#else
|
||||
tidhash_destroy(vacuumstate->deleting);
|
||||
#endif
|
||||
FreeAccessStrategy(vacuumstate->bas);
|
||||
pfree(vacuumstate->ntup);
|
||||
MemoryContextDelete(vacuumstate->tmpCtx);
|
||||
|
||||
@@ -438,15 +438,22 @@ ComputeCenters(IvfflatBuildState * buildstate)
|
||||
|
||||
pgstat_progress_update_param(PROGRESS_CREATEIDX_SUBPHASE, PROGRESS_IVFFLAT_PHASE_KMEANS);
|
||||
|
||||
/* Target 50 samples per list, with at least 10000 samples */
|
||||
/* The number of samples has a large effect on index build time */
|
||||
numSamples = buildstate->lists * 50;
|
||||
if (numSamples < 10000)
|
||||
numSamples = 10000;
|
||||
|
||||
/* Skip samples for unlogged table */
|
||||
if (buildstate->heap == NULL)
|
||||
numSamples = 1;
|
||||
else
|
||||
{
|
||||
int64 maxTuples = (int64) RelationGetNumberOfBlocks(buildstate->heap) * MaxHeapTuplesPerPage;
|
||||
|
||||
/* Target 50 samples per list, with at least 10000 samples */
|
||||
/* The number of samples has a large effect on index build time */
|
||||
numSamples = buildstate->lists * 50;
|
||||
if (numSamples < 10000)
|
||||
numSamples = 10000;
|
||||
|
||||
/* Save memory since will not have more than max tuples */
|
||||
numSamples = Max(Min(numSamples, maxTuples), 1);
|
||||
}
|
||||
|
||||
/* Sample rows */
|
||||
buildstate->memoryUsed += VECTOR_ARRAY_SIZE(numSamples, buildstate->itemsize);
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM >= 180000
|
||||
PG_MODULE_MAGIC_EXT(.name = "vector", .version = "0.8.3");
|
||||
PG_MODULE_MAGIC_EXT(.name = "vector", .version = "0.8.4");
|
||||
#else
|
||||
PG_MODULE_MAGIC;
|
||||
#endif
|
||||
|
||||
@@ -49,3 +49,11 @@ CREATE INDEX ON t USING hnsw ((val::bit(3)) bit_hamming_ops);
|
||||
CREATE INDEX ON t USING hnsw ((val::bit(64001)) bit_hamming_ops);
|
||||
ERROR: column cannot have more than 64000 dimensions for hnsw index
|
||||
DROP TABLE t;
|
||||
-- dimensions
|
||||
CREATE TABLE t (val bit(64000));
|
||||
CREATE INDEX ON t USING hnsw (val bit_hamming_ops);
|
||||
DROP TABLE t;
|
||||
CREATE TABLE t (val bit(64001));
|
||||
CREATE INDEX ON t USING hnsw (val bit_hamming_ops);
|
||||
ERROR: column cannot have more than 64000 dimensions for hnsw index
|
||||
DROP TABLE t;
|
||||
|
||||
@@ -100,3 +100,11 @@ SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <+> (SELECT NULL::halfvec)) t
|
||||
(1 row)
|
||||
|
||||
DROP TABLE t;
|
||||
-- dimensions
|
||||
CREATE TABLE t (val halfvec(4000));
|
||||
CREATE INDEX ON t USING hnsw (val halfvec_l2_ops);
|
||||
DROP TABLE t;
|
||||
CREATE TABLE t (val halfvec(4001));
|
||||
CREATE INDEX ON t USING hnsw (val halfvec_l2_ops);
|
||||
ERROR: column cannot have more than 4000 dimensions for hnsw index
|
||||
DROP TABLE t;
|
||||
|
||||
@@ -161,6 +161,7 @@ ERROR: value 1001 out of bounds for option "ef_construction"
|
||||
DETAIL: Valid values are between "4" and "1000".
|
||||
CREATE INDEX ON t USING hnsw (val vector_l2_ops) WITH (m = 16, ef_construction = 31);
|
||||
ERROR: ef_construction must be greater than or equal to 2 * m
|
||||
DROP TABLE t;
|
||||
SHOW hnsw.ef_search;
|
||||
hnsw.ef_search
|
||||
----------------
|
||||
@@ -198,4 +199,11 @@ SET hnsw.scan_mem_multiplier = 0;
|
||||
ERROR: 0 is outside the valid range for parameter "hnsw.scan_mem_multiplier" (1 .. 1000)
|
||||
SET hnsw.scan_mem_multiplier = 1001;
|
||||
ERROR: 1001 is outside the valid range for parameter "hnsw.scan_mem_multiplier" (1 .. 1000)
|
||||
-- dimensions
|
||||
CREATE TABLE t (val vector(2000));
|
||||
CREATE INDEX ON t USING hnsw (val vector_l2_ops);
|
||||
DROP TABLE t;
|
||||
CREATE TABLE t (val vector(2001));
|
||||
CREATE INDEX ON t USING hnsw (val vector_l2_ops);
|
||||
ERROR: column cannot have more than 2000 dimensions for hnsw index
|
||||
DROP TABLE t;
|
||||
|
||||
@@ -35,3 +35,32 @@ NOTICE: ivfflat index created with little data
|
||||
DETAIL: This will cause low recall.
|
||||
HINT: Drop the index until the table has more data.
|
||||
DROP TABLE t;
|
||||
-- dimensions
|
||||
CREATE TABLE t (val bit(64000));
|
||||
CREATE INDEX ON t USING ivfflat (val bit_hamming_ops);
|
||||
NOTICE: ivfflat index created with little data
|
||||
DETAIL: This will cause low recall.
|
||||
HINT: Drop the index until the table has more data.
|
||||
DROP TABLE t;
|
||||
CREATE TABLE t (val bit(64001));
|
||||
CREATE INDEX ON t USING ivfflat (val bit_hamming_ops);
|
||||
ERROR: column cannot have more than 64000 dimensions for ivfflat index
|
||||
DROP TABLE t;
|
||||
-- memory
|
||||
SET maintenance_work_mem = '1MB';
|
||||
CREATE TABLE t (val bit(64000));
|
||||
CREATE INDEX ON t USING ivfflat (val bit_hamming_ops);
|
||||
NOTICE: ivfflat index created with little data
|
||||
DETAIL: This will cause low recall.
|
||||
HINT: Drop the index until the table has more data.
|
||||
DROP TABLE t;
|
||||
RESET maintenance_work_mem;
|
||||
SET maintenance_work_mem = '29MB';
|
||||
CREATE TABLE t (val bit(64000));
|
||||
INSERT INTO t (val) VALUES (B'0'::bit(64000));
|
||||
CREATE INDEX ON t USING ivfflat (val bit_hamming_ops);
|
||||
NOTICE: ivfflat index created with little data
|
||||
DETAIL: This will cause low recall.
|
||||
HINT: Drop the index until the table has more data.
|
||||
DROP TABLE t;
|
||||
RESET maintenance_work_mem;
|
||||
|
||||
@@ -82,3 +82,32 @@ SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <=> (SELECT NULL::halfvec)) t
|
||||
(1 row)
|
||||
|
||||
DROP TABLE t;
|
||||
-- dimensions
|
||||
CREATE TABLE t (val halfvec(4000));
|
||||
CREATE INDEX ON t USING ivfflat (val halfvec_l2_ops);
|
||||
NOTICE: ivfflat index created with little data
|
||||
DETAIL: This will cause low recall.
|
||||
HINT: Drop the index until the table has more data.
|
||||
DROP TABLE t;
|
||||
CREATE TABLE t (val halfvec(4001));
|
||||
CREATE INDEX ON t USING ivfflat (val halfvec_l2_ops);
|
||||
ERROR: column cannot have more than 4000 dimensions for ivfflat index
|
||||
DROP TABLE t;
|
||||
-- memory
|
||||
SET maintenance_work_mem = '1MB';
|
||||
CREATE TABLE t (val halfvec(4000));
|
||||
CREATE INDEX ON t USING ivfflat (val halfvec_l2_ops);
|
||||
NOTICE: ivfflat index created with little data
|
||||
DETAIL: This will cause low recall.
|
||||
HINT: Drop the index until the table has more data.
|
||||
DROP TABLE t;
|
||||
RESET maintenance_work_mem;
|
||||
SET maintenance_work_mem = '6MB';
|
||||
CREATE TABLE t (val halfvec(4000));
|
||||
INSERT INTO t (val) VALUES (array_fill(0, ARRAY[4000]));
|
||||
CREATE INDEX ON t USING ivfflat (val halfvec_l2_ops);
|
||||
NOTICE: ivfflat index created with little data
|
||||
DETAIL: This will cause low recall.
|
||||
HINT: Drop the index until the table has more data.
|
||||
DROP TABLE t;
|
||||
RESET maintenance_work_mem;
|
||||
|
||||
@@ -143,6 +143,7 @@ DETAIL: Valid values are between "1" and "32768".
|
||||
CREATE INDEX ON t USING ivfflat (val vector_l2_ops) WITH (lists = 32769);
|
||||
ERROR: value 32769 out of bounds for option "lists"
|
||||
DETAIL: Valid values are between "1" and "32768".
|
||||
DROP TABLE t;
|
||||
SHOW ivfflat.probes;
|
||||
ivfflat.probes
|
||||
----------------
|
||||
@@ -172,4 +173,32 @@ SET ivfflat.max_probes = 0;
|
||||
ERROR: 0 is outside the valid range for parameter "ivfflat.max_probes" (1 .. 32768)
|
||||
SET ivfflat.max_probes = 32769;
|
||||
ERROR: 32769 is outside the valid range for parameter "ivfflat.max_probes" (1 .. 32768)
|
||||
-- dimensions
|
||||
CREATE TABLE t (val vector(2000));
|
||||
CREATE INDEX ON t USING ivfflat (val vector_l2_ops);
|
||||
NOTICE: ivfflat index created with little data
|
||||
DETAIL: This will cause low recall.
|
||||
HINT: Drop the index until the table has more data.
|
||||
DROP TABLE t;
|
||||
CREATE TABLE t (val vector(2001));
|
||||
CREATE INDEX ON t USING ivfflat (val vector_l2_ops);
|
||||
ERROR: column cannot have more than 2000 dimensions for ivfflat index
|
||||
DROP TABLE t;
|
||||
-- memory
|
||||
SET maintenance_work_mem = '1MB';
|
||||
CREATE TABLE t (val vector(2000));
|
||||
CREATE INDEX ON t USING ivfflat (val vector_l2_ops);
|
||||
NOTICE: ivfflat index created with little data
|
||||
DETAIL: This will cause low recall.
|
||||
HINT: Drop the index until the table has more data.
|
||||
DROP TABLE t;
|
||||
RESET maintenance_work_mem;
|
||||
SET maintenance_work_mem = '5MB';
|
||||
CREATE TABLE t (val vector(2000));
|
||||
INSERT INTO t (val) VALUES (array_fill(0, ARRAY[2000]));
|
||||
CREATE INDEX ON t USING ivfflat (val vector_l2_ops);
|
||||
NOTICE: ivfflat index created with little data
|
||||
DETAIL: This will cause low recall.
|
||||
HINT: Drop the index until the table has more data.
|
||||
DROP TABLE t;
|
||||
RESET maintenance_work_mem;
|
||||
|
||||
@@ -33,3 +33,13 @@ CREATE INDEX ON t USING hnsw (val bit_hamming_ops);
|
||||
CREATE INDEX ON t USING hnsw ((val::bit(3)) bit_hamming_ops);
|
||||
CREATE INDEX ON t USING hnsw ((val::bit(64001)) bit_hamming_ops);
|
||||
DROP TABLE t;
|
||||
|
||||
-- dimensions
|
||||
|
||||
CREATE TABLE t (val bit(64000));
|
||||
CREATE INDEX ON t USING hnsw (val bit_hamming_ops);
|
||||
DROP TABLE t;
|
||||
|
||||
CREATE TABLE t (val bit(64001));
|
||||
CREATE INDEX ON t USING hnsw (val bit_hamming_ops);
|
||||
DROP TABLE t;
|
||||
|
||||
@@ -56,3 +56,13 @@ SELECT * FROM t ORDER BY val <+> '[3,3,3]';
|
||||
SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <+> (SELECT NULL::halfvec)) t2;
|
||||
|
||||
DROP TABLE t;
|
||||
|
||||
-- dimensions
|
||||
|
||||
CREATE TABLE t (val halfvec(4000));
|
||||
CREATE INDEX ON t USING hnsw (val halfvec_l2_ops);
|
||||
DROP TABLE t;
|
||||
|
||||
CREATE TABLE t (val halfvec(4001));
|
||||
CREATE INDEX ON t USING hnsw (val halfvec_l2_ops);
|
||||
DROP TABLE t;
|
||||
|
||||
@@ -95,23 +95,28 @@ CREATE INDEX ON t USING hnsw (val vector_l2_ops) WITH (m = 101);
|
||||
CREATE INDEX ON t USING hnsw (val vector_l2_ops) WITH (ef_construction = 3);
|
||||
CREATE INDEX ON t USING hnsw (val vector_l2_ops) WITH (ef_construction = 1001);
|
||||
CREATE INDEX ON t USING hnsw (val vector_l2_ops) WITH (m = 16, ef_construction = 31);
|
||||
DROP TABLE t;
|
||||
|
||||
SHOW hnsw.ef_search;
|
||||
|
||||
SET hnsw.ef_search = 0;
|
||||
SET hnsw.ef_search = 1001;
|
||||
|
||||
SHOW hnsw.iterative_scan;
|
||||
|
||||
SET hnsw.iterative_scan = on;
|
||||
|
||||
SHOW hnsw.max_scan_tuples;
|
||||
|
||||
SET hnsw.max_scan_tuples = 0;
|
||||
|
||||
SHOW hnsw.scan_mem_multiplier;
|
||||
|
||||
SET hnsw.scan_mem_multiplier = 0;
|
||||
SET hnsw.scan_mem_multiplier = 1001;
|
||||
|
||||
-- dimensions
|
||||
|
||||
CREATE TABLE t (val vector(2000));
|
||||
CREATE INDEX ON t USING hnsw (val vector_l2_ops);
|
||||
DROP TABLE t;
|
||||
|
||||
CREATE TABLE t (val vector(2001));
|
||||
CREATE INDEX ON t USING hnsw (val vector_l2_ops);
|
||||
DROP TABLE t;
|
||||
|
||||
@@ -21,3 +21,28 @@ CREATE INDEX ON t USING ivfflat ((val::bit(3)) bit_hamming_ops) WITH (lists = 1)
|
||||
CREATE INDEX ON t USING ivfflat ((val::bit(64001)) bit_hamming_ops) WITH (lists = 1);
|
||||
CREATE INDEX ON t USING ivfflat ((val::bit(2)) bit_hamming_ops) WITH (lists = 5);
|
||||
DROP TABLE t;
|
||||
|
||||
-- dimensions
|
||||
|
||||
CREATE TABLE t (val bit(64000));
|
||||
CREATE INDEX ON t USING ivfflat (val bit_hamming_ops);
|
||||
DROP TABLE t;
|
||||
|
||||
CREATE TABLE t (val bit(64001));
|
||||
CREATE INDEX ON t USING ivfflat (val bit_hamming_ops);
|
||||
DROP TABLE t;
|
||||
|
||||
-- memory
|
||||
|
||||
SET maintenance_work_mem = '1MB';
|
||||
CREATE TABLE t (val bit(64000));
|
||||
CREATE INDEX ON t USING ivfflat (val bit_hamming_ops);
|
||||
DROP TABLE t;
|
||||
RESET maintenance_work_mem;
|
||||
|
||||
SET maintenance_work_mem = '29MB';
|
||||
CREATE TABLE t (val bit(64000));
|
||||
INSERT INTO t (val) VALUES (B'0'::bit(64000));
|
||||
CREATE INDEX ON t USING ivfflat (val bit_hamming_ops);
|
||||
DROP TABLE t;
|
||||
RESET maintenance_work_mem;
|
||||
|
||||
@@ -43,3 +43,28 @@ SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <=> '[0,0,0]') t2;
|
||||
SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <=> (SELECT NULL::halfvec)) t2;
|
||||
|
||||
DROP TABLE t;
|
||||
|
||||
-- dimensions
|
||||
|
||||
CREATE TABLE t (val halfvec(4000));
|
||||
CREATE INDEX ON t USING ivfflat (val halfvec_l2_ops);
|
||||
DROP TABLE t;
|
||||
|
||||
CREATE TABLE t (val halfvec(4001));
|
||||
CREATE INDEX ON t USING ivfflat (val halfvec_l2_ops);
|
||||
DROP TABLE t;
|
||||
|
||||
-- memory
|
||||
|
||||
SET maintenance_work_mem = '1MB';
|
||||
CREATE TABLE t (val halfvec(4000));
|
||||
CREATE INDEX ON t USING ivfflat (val halfvec_l2_ops);
|
||||
DROP TABLE t;
|
||||
RESET maintenance_work_mem;
|
||||
|
||||
SET maintenance_work_mem = '6MB';
|
||||
CREATE TABLE t (val halfvec(4000));
|
||||
INSERT INTO t (val) VALUES (array_fill(0, ARRAY[4000]));
|
||||
CREATE INDEX ON t USING ivfflat (val halfvec_l2_ops);
|
||||
DROP TABLE t;
|
||||
RESET maintenance_work_mem;
|
||||
|
||||
@@ -81,19 +81,40 @@ DROP TABLE t;
|
||||
CREATE TABLE t (val vector(3));
|
||||
CREATE INDEX ON t USING ivfflat (val vector_l2_ops) WITH (lists = 0);
|
||||
CREATE INDEX ON t USING ivfflat (val vector_l2_ops) WITH (lists = 32769);
|
||||
DROP TABLE t;
|
||||
|
||||
SHOW ivfflat.probes;
|
||||
|
||||
SET ivfflat.probes = 0;
|
||||
SET ivfflat.probes = 32769;
|
||||
|
||||
SHOW ivfflat.iterative_scan;
|
||||
|
||||
SET ivfflat.iterative_scan = on;
|
||||
|
||||
SHOW ivfflat.max_probes;
|
||||
|
||||
SET ivfflat.max_probes = 0;
|
||||
SET ivfflat.max_probes = 32769;
|
||||
|
||||
-- dimensions
|
||||
|
||||
CREATE TABLE t (val vector(2000));
|
||||
CREATE INDEX ON t USING ivfflat (val vector_l2_ops);
|
||||
DROP TABLE t;
|
||||
|
||||
CREATE TABLE t (val vector(2001));
|
||||
CREATE INDEX ON t USING ivfflat (val vector_l2_ops);
|
||||
DROP TABLE t;
|
||||
|
||||
-- memory
|
||||
|
||||
SET maintenance_work_mem = '1MB';
|
||||
CREATE TABLE t (val vector(2000));
|
||||
CREATE INDEX ON t USING ivfflat (val vector_l2_ops);
|
||||
DROP TABLE t;
|
||||
RESET maintenance_work_mem;
|
||||
|
||||
SET maintenance_work_mem = '5MB';
|
||||
CREATE TABLE t (val vector(2000));
|
||||
INSERT INTO t (val) VALUES (array_fill(0, ARRAY[2000]));
|
||||
CREATE INDEX ON t USING ivfflat (val vector_l2_ops);
|
||||
DROP TABLE t;
|
||||
RESET maintenance_work_mem;
|
||||
|
||||
38
test/t/046_hnsw_vacuum_scan.pl
Normal file
38
test/t/046_hnsw_vacuum_scan.pl
Normal file
@@ -0,0 +1,38 @@
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use PostgreSQL::Test::Cluster;
|
||||
use PostgreSQL::Test::Utils;
|
||||
use Test::More;
|
||||
|
||||
my $dim = 3;
|
||||
my $array_sql = join(",", ('random()') x $dim);
|
||||
|
||||
# Initialize node
|
||||
my $node = PostgreSQL::Test::Cluster->new('node');
|
||||
$node->init;
|
||||
$node->start;
|
||||
|
||||
# Create table and index
|
||||
$node->safe_psql("postgres", "CREATE EXTENSION vector;");
|
||||
$node->safe_psql("postgres", "CREATE TABLE tst (i serial, v vector($dim));");
|
||||
$node->safe_psql("postgres", "ALTER TABLE tst SET (autovacuum_enabled = false);");
|
||||
$node->safe_psql("postgres",
|
||||
"INSERT INTO tst (v) SELECT ARRAY[$array_sql] FROM generate_series(1, 1000) i;"
|
||||
);
|
||||
$node->safe_psql("postgres", "CREATE INDEX ON tst USING hnsw (v vector_l2_ops);");
|
||||
$node->safe_psql("postgres", "DELETE FROM tst");
|
||||
|
||||
# Test HNSW_SCAN_LOCK at the beginning of MarkDeleted is effective
|
||||
$node->pgbench(
|
||||
"--no-vacuum --client=5 --transactions=1000",
|
||||
0,
|
||||
[qr{actually processed}],
|
||||
[qr{^$}],
|
||||
"concurrent SELECTs and VACUUM",
|
||||
{
|
||||
"046_hnsw_vacuum_scan_select\@1000" => "SELECT i FROM tst ORDER BY v <-> '[0,0,0]' LIMIT 10;",
|
||||
"046_hnsw_vacuum_scan_vacuum\@1" => "VACUUM tst;"
|
||||
}
|
||||
);
|
||||
|
||||
done_testing();
|
||||
39
test/t/047_hnsw_vacuum_insert.pl
Normal file
39
test/t/047_hnsw_vacuum_insert.pl
Normal file
@@ -0,0 +1,39 @@
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use PostgreSQL::Test::Cluster;
|
||||
use PostgreSQL::Test::Utils;
|
||||
use Test::More;
|
||||
|
||||
my $dim = 3;
|
||||
my $array_sql = join(",", ('random()') x $dim);
|
||||
|
||||
# Initialize node
|
||||
my $node = PostgreSQL::Test::Cluster->new('node');
|
||||
$node->init;
|
||||
$node->start;
|
||||
|
||||
# Create table and index
|
||||
$node->safe_psql("postgres", "CREATE EXTENSION vector;");
|
||||
$node->safe_psql("postgres", "CREATE TABLE tst (i serial, v vector($dim));");
|
||||
$node->safe_psql("postgres", "ALTER TABLE tst SET (autovacuum_enabled = false);");
|
||||
$node->safe_psql("postgres",
|
||||
"INSERT INTO tst (v) SELECT ARRAY[$array_sql] FROM generate_series(1, 1000) i;"
|
||||
);
|
||||
$node->safe_psql("postgres", "CREATE INDEX ON tst USING hnsw (v vector_l2_ops);");
|
||||
|
||||
# Test no "hnsw graph not repaired" errors
|
||||
$node->pgbench(
|
||||
"--no-vacuum --client=5 --transactions=1000",
|
||||
0,
|
||||
[qr{actually processed}],
|
||||
[qr{^$}],
|
||||
"concurrent INSERTs, DELETEs, SELECTs, and VACUUM",
|
||||
{
|
||||
"047_hnsw_vacuum_insert_insert\@500" => "INSERT INTO tst (v) VALUES (ARRAY[$array_sql]);",
|
||||
"047_hnsw_vacuum_insert_delete\@500" => "DELETE FROM tst WHERE i = (SELECT i FROM tst LIMIT 1);",
|
||||
"047_hnsw_vacuum_insert_select\@20" => "SELECT i FROM tst ORDER BY v <-> '[0,0,0]' LIMIT 10;",
|
||||
"047_hnsw_vacuum_insert_vacuum\@1" => "VACUUM tst;"
|
||||
}
|
||||
);
|
||||
|
||||
done_testing();
|
||||
@@ -1,4 +1,4 @@
|
||||
comment = 'vector data type and ivfflat and hnsw access methods'
|
||||
default_version = '0.8.3'
|
||||
default_version = '0.8.4'
|
||||
module_pathname = '$libdir/vector'
|
||||
relocatable = true
|
||||
|
||||
Reference in New Issue
Block a user