Compare commits

...

15 Commits

Author SHA1 Message Date
Andrew Kane
c95732340a Version bump to 0.1.6 [skip ci] 2021-06-09 20:48:50 -07:00
Andrew Kane
2af9bdefbb Added link to pgvector.rs [skip ci] 2021-06-09 19:42:40 -07:00
Andrew Kane
bd36231871 Less space [skip ci] 2021-06-09 04:03:06 -07:00
Andrew Kane
523788d964 Improved code 2021-06-09 03:59:00 -07:00
Andrew Kane
1eed57310a Use DBL_MAX for cost 2021-06-09 03:31:41 -07:00
Andrew Kane
57e6a01214 Fixed segmentation fault with COUNT - fixes #9 2021-06-09 03:13:22 -07:00
Andrew Kane
b713cbc3b6 Added instructions for Azure [skip ci] 2021-06-08 23:36:47 -07:00
Andrew Kane
ebeac156c0 Require unused to be 0 2021-05-26 13:40:38 -07:00
Andrew Kane
60bc93f938 Version bump to 0.1.5 [skip ci] 2021-05-25 17:31:02 -07:00
Andrew Kane
87a1b3365e Simplified logic 2021-05-24 18:58:11 -07:00
Andrew Kane
e9a762223b Moved line [skip ci] 2021-05-24 18:48:49 -07:00
Andrew Kane
db83f4faa8 Reduced memory usage during index build - #7 2021-05-24 18:40:34 -07:00
Andrew Kane
2cf71ec6bd Moved test [skip ci] 2021-05-15 00:29:52 -07:00
Andrew Kane
a7510430e3 Added test for max dimensions 2021-05-15 00:28:02 -07:00
Andrew Kane
ea8f06e8f4 Updated readme [skip ci] 2021-05-14 22:05:07 -07:00
15 changed files with 61 additions and 12 deletions

View File

@@ -1,3 +1,11 @@
## 0.1.6 (2021-06-09)
- Fixed segmentation fault with `COUNT`
## 0.1.5 (2021-05-25)
- Reduced memory usage during index creation
## 0.1.4 (2021-05-09) ## 0.1.4 (2021-05-09)
- Fixed kmeans for inner product - Fixed kmeans for inner product

View File

@@ -2,7 +2,7 @@
"name": "vector", "name": "vector",
"abstract": "Open-source vector similarity search for Postgres", "abstract": "Open-source vector similarity search for Postgres",
"description": "Supports L2 distance, inner product, and cosine distance", "description": "Supports L2 distance, inner product, and cosine distance",
"version": "0.1.4", "version": "0.1.6",
"maintainer": [ "maintainer": [
"Andrew Kane <andrew@ankane.org>" "Andrew Kane <andrew@ankane.org>"
], ],
@@ -20,7 +20,7 @@
"vector": { "vector": {
"file": "sql/vector.sql", "file": "sql/vector.sql",
"docfile": "README.md", "docfile": "README.md",
"version": "0.1.4", "version": "0.1.6",
"abstract": "Open-source vector similarity search for Postgres" "abstract": "Open-source vector similarity search for Postgres"
} }
}, },

View File

@@ -1,5 +1,5 @@
EXTENSION = vector EXTENSION = vector
EXTVERSION = 0.1.4 EXTVERSION = 0.1.6
MODULE_big = vector MODULE_big = vector
DATA = $(wildcard sql/*--*.sql) DATA = $(wildcard sql/*--*.sql)

View File

@@ -17,7 +17,7 @@ Supports L2 distance, inner product, and cosine distance
Compile and install the extension (supports Postgres 9.6+) Compile and install the extension (supports Postgres 9.6+)
```sh ```sh
git clone --branch v0.1.4 https://github.com/ankane/pgvector.git git clone --branch v0.1.6 https://github.com/ankane/pgvector.git
cd pgvector cd pgvector
make make
make install # may need sudo make install # may need sudo
@@ -137,6 +137,7 @@ vector_norm(vector) | Euclidean norm
Libraries that use pgvector: Libraries that use pgvector:
- [Neighbor](https://github.com/ankane/neighbor) (Ruby) - [Neighbor](https://github.com/ankane/neighbor) (Ruby)
- [pgvector.rs](https://github.com/ankane/pgvector.rs) (Rust)
## Additional Installation Methods ## Additional Installation Methods
@@ -153,7 +154,7 @@ This adds pgvector to the [Postgres image](https://hub.docker.com/_/postgres).
You can also build the image manually You can also build the image manually
```sh ```sh
git clone --branch v0.1.4 https://github.com/ankane/pgvector.git git clone --branch v0.1.6 https://github.com/ankane/pgvector.git
cd pgvector cd pgvector
docker build -t pgvector . docker build -t pgvector .
``` ```
@@ -181,10 +182,11 @@ Some Postgres providers only support specific extensions. To request a new exten
- Amazon RDS - follow the instructions on [this page](https://aws.amazon.com/rds/postgresql/faqs/) - Amazon RDS - follow the instructions on [this page](https://aws.amazon.com/rds/postgresql/faqs/)
- Google Cloud SQL - follow the instructions on [this page](https://cloud.google.com/sql/docs/postgres/extensions#requesting-support-for-a-new-extension) - Google Cloud SQL - follow the instructions on [this page](https://cloud.google.com/sql/docs/postgres/extensions#requesting-support-for-a-new-extension)
- DigitalOcean Managed Databases - follow the instructions on [this page](https://docs.digitalocean.com/products/databases/postgresql/resources/supported-extensions/#supported-extensions) - DigitalOcean Managed Databases - follow the instructions on [this page](https://docs.digitalocean.com/products/databases/postgresql/resources/supported-extensions/#supported-extensions)
- Azure Database for PostgreSQL - follow the instructions on [this page](https://docs.microsoft.com/en-us/azure/postgresql/concepts-extensions#next-steps)
## Upgrading ## Upgrading
Compile and install the latest version and run: Install the latest version and run:
```sql ```sql
ALTER EXTENSION vector UPDATE; ALTER EXTENSION vector UPDATE;
@@ -232,7 +234,7 @@ make prove_installcheck # TAP tests
To run single tests: To run single tests:
```sh ```sh
make installcheck REGRESS=vector # regression test make installcheck REGRESS=functions # regression test
make prove_installcheck PROVE_TESTS=test/t/001_wal.pl # TAP test make prove_installcheck PROVE_TESTS=test/t/001_wal.pl # TAP test
``` ```

View 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.1.5'" to load this file. \quit

View 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.1.6'" to load this file. \quit

View File

@@ -241,6 +241,8 @@ InsertTuples(Relation index, IvfflatBuildState * buildstate, ForkNumber forkNum)
if (PageAddItem(page, (Item) itup, itemsz, InvalidOffsetNumber, false, false) == InvalidOffsetNumber) if (PageAddItem(page, (Item) itup, itemsz, InvalidOffsetNumber, false, false) == InvalidOffsetNumber)
elog(ERROR, "failed to add index item to \"%s\"", RelationGetRelationName(index)); elog(ERROR, "failed to add index item to \"%s\"", RelationGetRelationName(index));
pfree(itup);
buildstate->indtuples += 1; buildstate->indtuples += 1;
GetNextTuple(buildstate->sortstate, tupdesc, slot, &itup, &list); GetNextTuple(buildstate->sortstate, tupdesc, slot, &itup, &list);

View File

@@ -1,5 +1,7 @@
#include "postgres.h" #include "postgres.h"
#include <float.h>
#include "access/amapi.h" #include "access/amapi.h"
#include "commands/vacuum.h" #include "commands/vacuum.h"
#include "ivfflat.h" #include "ivfflat.h"
@@ -44,18 +46,29 @@ ivfflatcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
int lists; int lists;
double ratio; double ratio;
Relation indexRel; Relation indexRel;
#if PG_VERSION_NUM < 120000 #if PG_VERSION_NUM < 120000
List *qinfos; List *qinfos;
qinfos = deconstruct_indexquals(path);
#endif #endif
/* Never use index without order */
if (path->indexorderbys == NULL)
{
*indexStartupCost = DBL_MAX;
*indexTotalCost = DBL_MAX;
*indexSelectivity = 0;
*indexCorrelation = 0;
#if PG_VERSION_NUM >= 100000
*indexPages = 0;
#endif
return;
}
MemSet(&costs, 0, sizeof(costs)); MemSet(&costs, 0, sizeof(costs));
#if PG_VERSION_NUM >= 120000 #if PG_VERSION_NUM >= 120000
genericcostestimate(root, path, loop_count, &costs); genericcostestimate(root, path, loop_count, &costs);
#else #else
qinfos = deconstruct_indexquals(path);
genericcostestimate(root, path, loop_count, qinfos, &costs); genericcostestimate(root, path, loop_count, qinfos, &costs);
#endif #endif

View File

@@ -251,6 +251,10 @@ ivfflatgettuple(IndexScanDesc scan, ScanDirection dir)
{ {
Datum value; Datum value;
/* Safety check */
if (scan->orderByData == NULL)
elog(ERROR, "cannot scan ivfflat index without order");
/* No items will match if null */ /* No items will match if null */
if (scan->orderByData->sk_flags & SK_ISNULL) if (scan->orderByData->sk_flags & SK_ISNULL)
return false; return false;

View File

@@ -244,14 +244,20 @@ vector_recv(PG_FUNCTION_ARGS)
int32 typmod = PG_GETARG_INT32(2); int32 typmod = PG_GETARG_INT32(2);
Vector *result; Vector *result;
int16 dim; int16 dim;
int16 unused;
int i; int i;
dim = pq_getmsgint(buf, sizeof(int16)); dim = pq_getmsgint(buf, sizeof(int16));
pq_getmsgint(buf, sizeof(int16)); /* unused */ unused = pq_getmsgint(buf, sizeof(int16));
CheckDim(dim); CheckDim(dim);
CheckExpectedDim(typmod, dim); CheckExpectedDim(typmod, dim);
if (unused != 0)
ereport(ERROR,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("expected unused to be 0, not %d", unused)));
result = InitVector(dim); result = InitVector(dim);
for (i = 0; i < dim; i++) for (i = 0; i < dim; i++)
result->x[i] = pq_getmsgfloat4(buf); result->x[i] = pq_getmsgfloat4(buf);

View File

@@ -28,3 +28,5 @@ SELECT '{-Infinity}'::real[]::vector;
ERROR: infinite value not allowed in vector ERROR: infinite value not allowed in vector
SELECT '{}'::real[]::vector; SELECT '{}'::real[]::vector;
ERROR: vector must have at least 1 dimension ERROR: vector must have at least 1 dimension
SELECT array_agg(n)::vector FROM generate_series(1, 1025) n;
ERROR: vector cannot have more than 1024 dimensions

View File

@@ -19,4 +19,10 @@ SELECT * FROM t ORDER BY val <-> (SELECT NULL::vector);
----- -----
(0 rows) (0 rows)
SELECT COUNT(*) FROM t;
count
-------
5
(1 row)
DROP TABLE t; DROP TABLE t;

View File

@@ -9,3 +9,4 @@ SELECT '{NaN}'::real[]::vector;
SELECT '{Infinity}'::real[]::vector; SELECT '{Infinity}'::real[]::vector;
SELECT '{-Infinity}'::real[]::vector; SELECT '{-Infinity}'::real[]::vector;
SELECT '{}'::real[]::vector; SELECT '{}'::real[]::vector;
SELECT array_agg(n)::vector FROM generate_series(1, 1025) n;

View File

@@ -10,5 +10,6 @@ INSERT INTO t (val) VALUES ('[1,2,4]');
SELECT * FROM t ORDER BY val <-> '[3,3,3]'; SELECT * FROM t ORDER BY val <-> '[3,3,3]';
SELECT * FROM t ORDER BY val <-> (SELECT NULL::vector); SELECT * FROM t ORDER BY val <-> (SELECT NULL::vector);
SELECT COUNT(*) FROM t;
DROP TABLE t; DROP TABLE t;

View File

@@ -1,4 +1,4 @@
comment = 'vector data type and ivfflat access method' comment = 'vector data type and ivfflat access method'
default_version = '0.1.4' default_version = '0.1.6'
module_pathname = '$libdir/vector' module_pathname = '$libdir/vector'
relocatable = true relocatable = true