mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-23 04:20:56 +08:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c20f04a11 | ||
|
|
7c12d100ce | ||
|
|
d97d9a6561 | ||
|
|
f15ea301c5 | ||
|
|
cfa23f2c7a | ||
|
|
b5b7035edc | ||
|
|
478d62cdbd | ||
|
|
c7df9ef3a1 |
@@ -1,6 +1,10 @@
|
|||||||
## 0.1.7 (unreleased)
|
## 0.1.8 (2021-09-07)
|
||||||
|
|
||||||
- Added cast for `numeric[]`
|
- Added cast for `vector` to `real[]`
|
||||||
|
|
||||||
|
## 0.1.7 (2021-06-13)
|
||||||
|
|
||||||
|
- Added cast for `numeric[]` to `vector`
|
||||||
|
|
||||||
## 0.1.6 (2021-06-09)
|
## 0.1.6 (2021-06-09)
|
||||||
|
|
||||||
|
|||||||
@@ -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.7",
|
"version": "0.1.8",
|
||||||
"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.7",
|
"version": "0.1.8",
|
||||||
"abstract": "Open-source vector similarity search for Postgres"
|
"abstract": "Open-source vector similarity search for Postgres"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -1,5 +1,5 @@
|
|||||||
EXTENSION = vector
|
EXTENSION = vector
|
||||||
EXTVERSION = 0.1.7
|
EXTVERSION = 0.1.8
|
||||||
|
|
||||||
MODULE_big = vector
|
MODULE_big = vector
|
||||||
DATA = $(wildcard sql/*--*.sql)
|
DATA = $(wildcard sql/*--*.sql)
|
||||||
|
|||||||
16
README.md
16
README.md
@@ -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.7 https://github.com/ankane/pgvector.git
|
git clone --branch v0.1.8 https://github.com/ankane/pgvector.git
|
||||||
cd pgvector
|
cd pgvector
|
||||||
make
|
make
|
||||||
make install # may need sudo
|
make install # may need sudo
|
||||||
@@ -106,6 +106,16 @@ SELECT ...
|
|||||||
COMMIT;
|
COMMIT;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Partial Indexes
|
||||||
|
|
||||||
|
Consider [partial indexes](https://www.postgresql.org/docs/current/indexes-partial.html) for queries with a `WHERE` clause
|
||||||
|
|
||||||
|
```sql
|
||||||
|
CREATE INDEX ON table USING ivfflat (column) WHERE (other_column = 123);
|
||||||
|
```
|
||||||
|
|
||||||
|
To index many different values of `other_column`, consider [partitioning](https://www.postgresql.org/docs/current/ddl-partitioning.html) on `other_column`.
|
||||||
|
|
||||||
## Reference
|
## Reference
|
||||||
|
|
||||||
### Vector Type
|
### Vector Type
|
||||||
@@ -138,6 +148,8 @@ Libraries that use pgvector:
|
|||||||
|
|
||||||
- [pgvector-python](https://github.com/ankane/pgvector-python) (Python)
|
- [pgvector-python](https://github.com/ankane/pgvector-python) (Python)
|
||||||
- [Neighbor](https://github.com/ankane/neighbor) (Ruby)
|
- [Neighbor](https://github.com/ankane/neighbor) (Ruby)
|
||||||
|
- [pgvector-node](https://github.com/ankane/pgvector-node) (Node.js)
|
||||||
|
- [pgvector-go](https://github.com/ankane/pgvector-go) (Go)
|
||||||
- [pgvector-rust](https://github.com/ankane/pgvector-rust) (Rust)
|
- [pgvector-rust](https://github.com/ankane/pgvector-rust) (Rust)
|
||||||
|
|
||||||
## Additional Installation Methods
|
## Additional Installation Methods
|
||||||
@@ -155,7 +167,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.7 https://github.com/ankane/pgvector.git
|
git clone --branch v0.1.8 https://github.com/ankane/pgvector.git
|
||||||
cd pgvector
|
cd pgvector
|
||||||
docker build -t pgvector .
|
docker build -t pgvector .
|
||||||
```
|
```
|
||||||
|
|||||||
8
sql/vector--0.1.7--0.1.8.sql
Normal file
8
sql/vector--0.1.7--0.1.8.sql
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION vector UPDATE TO '0.1.8'" to load this file. \quit
|
||||||
|
|
||||||
|
CREATE FUNCTION vector_to_float4(vector, integer, boolean) RETURNS real[]
|
||||||
|
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
||||||
|
|
||||||
|
CREATE CAST (vector AS real[])
|
||||||
|
WITH FUNCTION vector_to_float4(vector, integer, boolean) AS IMPLICIT;
|
||||||
@@ -100,6 +100,9 @@ CREATE FUNCTION array_to_vector(double precision[], integer, boolean) RETURNS ve
|
|||||||
CREATE FUNCTION array_to_vector(numeric[], integer, boolean) RETURNS vector
|
CREATE FUNCTION array_to_vector(numeric[], integer, boolean) RETURNS vector
|
||||||
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
||||||
|
|
||||||
|
CREATE FUNCTION vector_to_float4(vector, integer, boolean) RETURNS real[]
|
||||||
|
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
||||||
|
|
||||||
-- casts
|
-- casts
|
||||||
|
|
||||||
CREATE CAST (vector AS vector)
|
CREATE CAST (vector AS vector)
|
||||||
@@ -117,6 +120,9 @@ CREATE CAST (double precision[] AS vector)
|
|||||||
CREATE CAST (numeric[] AS vector)
|
CREATE CAST (numeric[] AS vector)
|
||||||
WITH FUNCTION array_to_vector(numeric[], integer, boolean) AS IMPLICIT;
|
WITH FUNCTION array_to_vector(numeric[], integer, boolean) AS IMPLICIT;
|
||||||
|
|
||||||
|
CREATE CAST (vector AS real[])
|
||||||
|
WITH FUNCTION vector_to_float4(vector, integer, boolean) AS IMPLICIT;
|
||||||
|
|
||||||
-- operators
|
-- operators
|
||||||
|
|
||||||
CREATE OPERATOR <-> (
|
CREATE OPERATOR <-> (
|
||||||
|
|||||||
27
src/vector.c
27
src/vector.c
@@ -16,6 +16,10 @@
|
|||||||
#include "utils/float.h"
|
#include "utils/float.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if PG_VERSION_NUM < 130000
|
||||||
|
#define TYPALIGN_INT 'i'
|
||||||
|
#endif
|
||||||
|
|
||||||
PG_MODULE_MAGIC;
|
PG_MODULE_MAGIC;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -359,6 +363,29 @@ array_to_vector(PG_FUNCTION_ARGS)
|
|||||||
PG_RETURN_POINTER(result);
|
PG_RETURN_POINTER(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert vector to float4[]
|
||||||
|
*/
|
||||||
|
PG_FUNCTION_INFO_V1(vector_to_float4);
|
||||||
|
Datum
|
||||||
|
vector_to_float4(PG_FUNCTION_ARGS)
|
||||||
|
{
|
||||||
|
Vector *vec = PG_GETARG_VECTOR_P(0);
|
||||||
|
Datum *d;
|
||||||
|
ArrayType *result;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
d = (Datum *) palloc(sizeof(Datum) * vec->dim);
|
||||||
|
|
||||||
|
for (i = 0; i < vec->dim; i++)
|
||||||
|
d[i] = Float4GetDatum(vec->x[i]);
|
||||||
|
|
||||||
|
/* Use TYPALIGN_INT for float4 */
|
||||||
|
result = construct_array(d, vec->dim, FLOAT4OID, sizeof(float4), true, TYPALIGN_INT);
|
||||||
|
|
||||||
|
PG_RETURN_POINTER(result);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the L2 distance between vectors
|
* Get the L2 distance between vectors
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -34,5 +34,11 @@ 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 '[1,2,3]'::vector::real[];
|
||||||
|
float4
|
||||||
|
---------
|
||||||
|
{1,2,3}
|
||||||
|
(1 row)
|
||||||
|
|
||||||
SELECT array_agg(n)::vector FROM generate_series(1, 1025) n;
|
SELECT array_agg(n)::vector FROM generate_series(1, 1025) n;
|
||||||
ERROR: vector cannot have more than 1024 dimensions
|
ERROR: vector cannot have more than 1024 dimensions
|
||||||
|
|||||||
@@ -10,4 +10,5 @@ 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 '[1,2,3]'::vector::real[];
|
||||||
SELECT array_agg(n)::vector FROM generate_series(1, 1025) n;
|
SELECT array_agg(n)::vector FROM generate_series(1, 1025) n;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
comment = 'vector data type and ivfflat access method'
|
comment = 'vector data type and ivfflat access method'
|
||||||
default_version = '0.1.7'
|
default_version = '0.1.8'
|
||||||
module_pathname = '$libdir/vector'
|
module_pathname = '$libdir/vector'
|
||||||
relocatable = true
|
relocatable = true
|
||||||
|
|||||||
Reference in New Issue
Block a user