Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ jobs:
with:
go-version: ${{ matrix.go }}
cache: false # depends on go.sum
- run: go mod tidy
- run: |
go mod tidy
(cd adapters/pgx && go mod tidy)
(cd adapters/ent && go mod tidy)
(cd examples && go mod tidy)
(cd adapter_tests && go mod tidy)
- uses: ankane/setup-postgres@v1
with:
database: pgvector_go_test
Expand All @@ -24,5 +29,9 @@ jobs:
cd pgvector
make
sudo make install
- run: go generate ./test/ent && go mod tidy
- run: go test -v
- run: (cd adapters/ent && go generate ./test && go mod tidy)
- run: go test -v ./...
- run: (cd adapters/pgx && go test -v ./...)
- run: (cd adapters/ent && go test -v ./...)
- run: (cd examples && go test -v ./...)
- run: (cd adapter_tests && go test -v ./...)
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/go.sum
/test/ent/*
!/test/ent/generate.go
!/test/ent/schema
go.sum
go.work.sum
/adapters/ent/test/*
!/adapters/ent/test/generate.go
!/adapters/ent/test/schema
40 changes: 29 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ Run:
go get github.com/pgvector/pgvector-go
```

Install adapter modules only when needed:

```sh
# pgx adapter
go get github.com/pgvector/pgvector-go/adapters/pgx

# ent helpers
go get github.com/pgvector/pgvector-go/adapters/ent
```

And follow the instructions for your database library:

- [pgx](#pgx)
Expand All @@ -40,7 +50,7 @@ Import the packages
```go
import (
"github.com/pgvector/pgvector-go"
pgxvec "github.com/pgvector/pgvector-go/pgx"
pgxvec "github.com/pgvector/pgvector-go/adapters/pgx"
)
```

Expand Down Expand Up @@ -92,7 +102,7 @@ _, err := conn.Exec(ctx, "CREATE INDEX ON items USING ivfflat (embedding vector_

Use `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distance

See a [full example](pgx_test.go)
See a [full example](adapter_tests/pgx_test.go)

## pg

Expand Down Expand Up @@ -145,7 +155,7 @@ _, err := conn.Exec(ctx, "CREATE INDEX ON items USING ivfflat (embedding vector_

Use `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distance

See a [full example](pg_test.go)
See a [full example](adapter_tests/pg_test.go)

## Bun

Expand Down Expand Up @@ -207,7 +217,7 @@ func (*Item) AfterCreateTable(ctx context.Context, query *bun.CreateTableQuery)

Use `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distance

See a [full example](bun_test.go)
See a [full example](adapter_tests/bun_test.go)

## Ent

Expand All @@ -216,7 +226,7 @@ Import the package
```go
import (
"github.com/pgvector/pgvector-go"
entvec "github.com/pgvector/pgvector-go/ent"
entvec "github.com/pgvector/pgvector-go/adapters/ent"
)
```

Expand Down Expand Up @@ -278,7 +288,7 @@ func (Item) Indexes() []ent.Index {

Use `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distance

See a [full example](ent_test.go)
See a [full example](adapter_tests/ent_test.go)

## GORM

Expand Down Expand Up @@ -330,7 +340,7 @@ db.Exec("CREATE INDEX ON items USING ivfflat (embedding vector_l2_ops) WITH (lis

Use `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distance

See a [full example](gorm_test.go)
See a [full example](adapter_tests/gorm_test.go)

## sqlx

Expand Down Expand Up @@ -380,7 +390,7 @@ db.MustExec("CREATE INDEX ON items USING ivfflat (embedding vector_l2_ops) WITH

Use `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distance

See a [full example](sqlx_test.go)
See a [full example](adapter_tests/sqlx_test.go)

## Reference

Expand Down Expand Up @@ -472,14 +482,22 @@ To get started with development:
git clone https://github.com/pgvector/pgvector-go.git
cd pgvector-go
go mod tidy
(cd adapters/pgx && go mod tidy)
(cd adapters/ent && go mod tidy)
(cd examples && go mod tidy)
(cd adapter_tests && go mod tidy)
createdb pgvector_go_test
go generate ./test/ent
go test -v
(cd ./adapters/ent && go generate ./test)
go test ./...
(cd adapters/pgx && go test ./...)
(cd adapters/ent && go test ./...)
(cd adapter_tests && go test ./...)
```

To run an example:

```sh
createdb pgvector_example
go run ./examples/loading
cd examples
go run ./loading
```
14 changes: 12 additions & 2 deletions bun_test.go → adapter_tests/bun_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pgvector_test
package adapter_tests_test

import (
"context"
Expand All @@ -14,6 +14,16 @@ import (
"github.com/uptrace/bun/driver/pgdriver"
)

func pgUser() string {
if user := os.Getenv("PGUSER"); user != "" {
return user
}
if user := os.Getenv("USER"); user != "" {
return user
}
return "postgres"
}

type BunItem struct {
bun.BaseModel `bun:"table:bun_items"`

Expand Down Expand Up @@ -73,7 +83,7 @@ func TestBun(t *testing.T) {

pgconn := pgdriver.NewConnector(
pgdriver.WithDatabase("pgvector_go_test"),
pgdriver.WithUser(os.Getenv("USER")),
pgdriver.WithUser(pgUser()),
pgdriver.WithTLSConfig(nil), // sslmode=disable
)
sqldb := sql.OpenDB(pgconn)
Expand Down
6 changes: 3 additions & 3 deletions ent_test.go → adapter_tests/ent_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pgvector_test
package adapter_tests_test

import (
"context"
Expand All @@ -8,8 +8,8 @@ import (
"entgo.io/ent/dialect/sql"
_ "github.com/lib/pq"
"github.com/pgvector/pgvector-go"
entvec "github.com/pgvector/pgvector-go/ent"
"github.com/pgvector/pgvector-go/test/ent"
entvec "github.com/pgvector/pgvector-go/adapters/ent"
ent "github.com/pgvector/pgvector-go/adapters/ent/test"
)

func TestEnt(t *testing.T) {
Expand Down
56 changes: 56 additions & 0 deletions adapter_tests/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module github.com/pgvector/pgvector-go/adapter_tests

go 1.23.0

replace github.com/pgvector/pgvector-go/adapters/ent => ../adapters/ent

replace github.com/pgvector/pgvector-go/adapters/pgx => ../adapters/pgx

require (
entgo.io/ent v0.14.3
github.com/go-pg/pg/v10 v10.11.0
github.com/jackc/pgx/v5 v5.7.2
github.com/jmoiron/sqlx v1.3.5
github.com/lib/pq v1.10.9
github.com/pgvector/pgvector-go v0.3.0
github.com/pgvector/pgvector-go/adapters/ent v0.0.0
github.com/pgvector/pgvector-go/adapters/pgx v0.0.0
github.com/uptrace/bun v1.1.12
github.com/uptrace/bun/dialect/pgdialect v1.1.12
github.com/uptrace/bun/driver/pgdriver v1.1.12
gorm.io/driver/postgres v1.5.4
gorm.io/gorm v1.25.5
)

require (
ariga.io/atlas v0.32.0 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/bmatcuk/doublestar v1.3.4 // indirect
github.com/go-openapi/inflect v0.21.0 // indirect
github.com/go-pg/zerochecker v0.2.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/hcl/v2 v2.23.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
github.com/vmihailenco/bufpool v0.1.11 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser v0.1.2 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/zclconf/go-cty v1.16.2 // indirect
github.com/zclconf/go-cty-yaml v1.1.0 // indirect
golang.org/x/crypto v0.36.0 // indirect
golang.org/x/mod v0.24.0 // indirect
golang.org/x/sync v0.12.0 // indirect
golang.org/x/sys v0.31.0 // indirect
golang.org/x/text v0.23.0 // indirect
golang.org/x/tools v0.31.0 // indirect
mellium.im/sasl v0.3.1 // indirect
)
2 changes: 1 addition & 1 deletion gorm_test.go → adapter_tests/gorm_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pgvector_test
package adapter_tests_test

import (
"math"
Expand Down
2 changes: 1 addition & 1 deletion pg_test.go → adapter_tests/pg_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pgvector_test
package adapter_tests_test

import (
"math"
Expand Down
4 changes: 2 additions & 2 deletions pgx_test.go → adapter_tests/pgx_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pgvector_test
package adapter_tests_test

import (
"context"
Expand All @@ -10,7 +10,7 @@ import (
"github.com/jackc/pgx/v5/pgtype"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/pgvector/pgvector-go"
pgxvec "github.com/pgvector/pgvector-go/pgx"
pgxvec "github.com/pgvector/pgvector-go/adapters/pgx"
)

type PgxItem struct {
Expand Down
2 changes: 1 addition & 1 deletion sqlx_test.go → adapter_tests/sqlx_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pgvector_test
package adapter_tests_test

import (
"reflect"
Expand Down
5 changes: 5 additions & 0 deletions adapter_tests/stub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package adapter_tests

func stub() {
// Empty stub
}
File renamed without changes.
26 changes: 26 additions & 0 deletions adapters/ent/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module github.com/pgvector/pgvector-go/adapters/ent

go 1.23.0

require (
entgo.io/ent v0.14.3
github.com/pgvector/pgvector-go v0.3.0
)

require (
ariga.io/atlas v0.32.0 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/bmatcuk/doublestar v1.3.4 // indirect
github.com/go-openapi/inflect v0.21.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/hcl/v2 v2.23.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/zclconf/go-cty v1.16.2 // indirect
github.com/zclconf/go-cty-yaml v1.1.0 // indirect
golang.org/x/mod v0.24.0 // indirect
golang.org/x/sync v0.12.0 // indirect
golang.org/x/text v0.23.0 // indirect
golang.org/x/tools v0.31.0 // indirect
)
3 changes: 3 additions & 0 deletions adapters/ent/test/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package test

//go:generate go run entgo.io/ent/cmd/ent generate --feature sql/execquery ./schema
File renamed without changes.
17 changes: 17 additions & 0 deletions adapters/pgx/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module github.com/pgvector/pgvector-go/adapters/pgx

go 1.23.0

require (
github.com/jackc/pgx/v5 v5.7.2
github.com/pgvector/pgvector-go v0.3.0
github.com/x448/float16 v0.8.4
)

require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/stretchr/testify v1.8.2 // indirect
golang.org/x/crypto v0.36.0 // indirect
golang.org/x/text v0.23.0 // indirect
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/citus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/jackc/pgx/v5"
"github.com/pgvector/pgvector-go"
pgxvector "github.com/pgvector/pgvector-go/pgx"
pgxvector "github.com/pgvector/pgvector-go/adapters/pgx"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/disco/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/ankane/disco-go"
"github.com/jackc/pgx/v5"
"github.com/pgvector/pgvector-go"
pgxvector "github.com/pgvector/pgvector-go/pgx"
pgxvector "github.com/pgvector/pgvector-go/adapters/pgx"
)

func main() {
Expand Down
7 changes: 7 additions & 0 deletions examples/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module github.com/pgvector/pgvector-go/examples

go 1.23.0

replace github.com/pgvector/pgvector-go/adapters/ent => ../adapters/ent

replace github.com/pgvector/pgvector-go/adapters/pgx => ../adapters/pgx
2 changes: 1 addition & 1 deletion examples/hybrid/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/jackc/pgx/v5"
"github.com/pgvector/pgvector-go"
pgxvector "github.com/pgvector/pgvector-go/pgx"
pgxvector "github.com/pgvector/pgvector-go/adapters/pgx"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/loading/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/jackc/pgx/v5"
"github.com/pgvector/pgvector-go"
pgxvector "github.com/pgvector/pgvector-go/pgx"
pgxvector "github.com/pgvector/pgvector-go/adapters/pgx"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/openai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/jackc/pgx/v5"
"github.com/pgvector/pgvector-go"
pgxvector "github.com/pgvector/pgvector-go/pgx"
pgxvector "github.com/pgvector/pgvector-go/adapters/pgx"
)

func main() {
Expand Down
Loading