Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit 586f9a7

Browse files
committed
add: pgvector vectorstore implementation
1 parent c395834 commit 586f9a7

File tree

20 files changed

+686
-39
lines changed

20 files changed

+686
-39
lines changed

go.mod

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ require (
2828
github.com/google/uuid v1.6.0
2929
github.com/hupe1980/golc v0.0.112
3030
github.com/iwilltry42/bm25-go v0.0.0-20240909111832-a928590cc9da
31+
github.com/jackc/pgx/v5 v5.7.1
3132
github.com/jmcarbo/stopwords v1.1.9
3233
github.com/joho/godotenv v1.5.1
3334
github.com/knadh/koanf/parsers/json v0.1.0
@@ -38,14 +39,15 @@ require (
3839
github.com/ledongthuc/pdf v0.0.0-20240201131950-da5b75280b06
3940
github.com/lu4p/cat v0.1.5
4041
github.com/mitchellh/mapstructure v1.5.0
42+
github.com/pgvector/pgvector-go v0.2.2
4143
github.com/philippgille/chromem-go v0.6.1-0.20240811154507-a1944285b284
4244
github.com/spf13/cobra v1.8.1
4345
github.com/stretchr/testify v1.9.0
4446
github.com/swaggo/files v1.0.1
4547
github.com/swaggo/gin-swagger v1.6.0
4648
github.com/swaggo/swag v1.16.3
4749
github.com/tmc/langchaingo v0.1.12
48-
golang.org/x/sync v0.7.0
50+
golang.org/x/sync v0.8.0
4951
gorm.io/gorm v1.25.10
5052
sigs.k8s.io/yaml v1.4.0
5153
)
@@ -109,6 +111,8 @@ require (
109111
github.com/hupe1980/go-textractor v0.0.9 // indirect
110112
github.com/hupe1980/go-tiktoken v0.0.9 // indirect
111113
github.com/inconshreveable/mousetrap v1.1.0 // indirect
114+
github.com/jackc/pgpassfile v1.0.0 // indirect
115+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
112116
github.com/jaytaylor/html2text v0.0.0-20200412013138-3577fbdbcff7 // indirect
113117
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
114118
github.com/jinzhu/inflection v1.0.0 // indirect
@@ -158,11 +162,11 @@ require (
158162
gitlab.com/golang-commonmark/mdurl v0.0.0-20191124015652-932350d1cb84 // indirect
159163
gitlab.com/golang-commonmark/puny v0.0.0-20191124015043-9f83538fa04f // indirect
160164
golang.org/x/arch v0.8.0 // indirect
161-
golang.org/x/crypto v0.24.0 // indirect
165+
golang.org/x/crypto v0.27.0 // indirect
162166
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
163167
golang.org/x/net v0.26.0 // indirect
164-
golang.org/x/sys v0.21.0 // indirect
165-
golang.org/x/text v0.16.0 // indirect
168+
golang.org/x/sys v0.25.0 // indirect
169+
golang.org/x/text v0.18.0 // indirect
166170
golang.org/x/tools v0.22.0 // indirect
167171
google.golang.org/api v0.184.0 // indirect
168172
google.golang.org/genproto/googleapis/api v0.0.0-20240610135401-a8a62080eff3 // indirect

go.sum

Lines changed: 173 additions & 10 deletions
Large diffs are not rendered by default.

pkg/cmd/askdir.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (s *ClientAskDir) Customize(cmd *cobra.Command) {
3131
}
3232

3333
func (s *ClientAskDir) Run(cmd *cobra.Command, args []string) error {
34-
c, err := s.getClient()
34+
c, err := s.getClient(cmd.Context())
3535
if err != nil {
3636
return err
3737
}

pkg/cmd/client.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"archive/zip"
5+
"context"
56
"fmt"
67
"io"
78
"os"
@@ -89,13 +90,13 @@ func (s *Client) loadArchive() error {
8990
return fmt.Errorf("knowledge archive must contain exactly one .db and one .gob file")
9091
}
9192

92-
s.DSN = types.ArchivePrefix + dbFile
93-
s.VectorDBPath = types.ArchivePrefix + vectorStoreFile
93+
s.DatabaseConfig.DSN = types.ArchivePrefix + dbFile
94+
s.VectorDBConfig.DSN = types.ArchivePrefix + vectorStoreFile
9495

9596
return nil
9697
}
9798

98-
func (s *Client) getClient() (client.Client, error) {
99+
func (s *Client) getClient(ctx context.Context) (client.Client, error) {
99100
if err := s.loadArchive(); err != nil {
100101
return nil, err
101102
}
@@ -111,7 +112,7 @@ func (s *Client) getClient() (client.Client, error) {
111112
return nil, err
112113
}
113114

114-
ds, err := datastore.NewDatastore(s.DSN, s.AutoMigrate == "true", s.VectorDBConfig.VectorDBPath, provider)
115+
ds, err := datastore.NewDatastore(ctx, s.DatabaseConfig.DSN, s.AutoMigrate == "true", s.VectorDBConfig.DSN, provider)
115116
if err != nil {
116117
return nil, err
117118
}

pkg/cmd/create_dataset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (s *ClientCreateDataset) Customize(cmd *cobra.Command) {
1717
}
1818

1919
func (s *ClientCreateDataset) Run(cmd *cobra.Command, args []string) error {
20-
c, err := s.getClient()
20+
c, err := s.getClient(cmd.Context())
2121
if err != nil {
2222
return err
2323
}

pkg/cmd/delete_dataset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (s *ClientDeleteDataset) Customize(cmd *cobra.Command) {
1717
}
1818

1919
func (s *ClientDeleteDataset) Run(cmd *cobra.Command, args []string) error {
20-
c, err := s.getClient()
20+
c, err := s.getClient(cmd.Context())
2121
if err != nil {
2222
return err
2323
}

pkg/cmd/edit_dataset.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"encoding/json"
55
"fmt"
6+
67
"github.com/gptscript-ai/knowledge/pkg/datastore"
78
"github.com/gptscript-ai/knowledge/pkg/index"
89
"github.com/spf13/cobra"
@@ -23,7 +24,7 @@ func (s *ClientEditDataset) Customize(cmd *cobra.Command) {
2324
}
2425

2526
func (s *ClientEditDataset) Run(cmd *cobra.Command, args []string) error {
26-
c, err := s.getClient()
27+
c, err := s.getClient(cmd.Context())
2728
if err != nil {
2829
return err
2930
}

pkg/cmd/export.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"fmt"
5+
56
"github.com/spf13/cobra"
67
)
78

@@ -17,7 +18,7 @@ func (s *ClientExportDatasets) Customize(cmd *cobra.Command) {
1718
}
1819

1920
func (s *ClientExportDatasets) Run(cmd *cobra.Command, args []string) error {
20-
c, err := s.getClient()
21+
c, err := s.getClient(cmd.Context())
2122
if err != nil {
2223
return err
2324
}

pkg/cmd/get_dataset.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"encoding/json"
55
"fmt"
6+
67
"github.com/spf13/cobra"
78
)
89

@@ -19,7 +20,7 @@ func (s *ClientGetDataset) Customize(cmd *cobra.Command) {
1920
}
2021

2122
func (s *ClientGetDataset) Run(cmd *cobra.Command, args []string) error {
22-
c, err := s.getClient()
23+
c, err := s.getClient(cmd.Context())
2324
if err != nil {
2425
return err
2526
}

pkg/cmd/import.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (s *ClientImportDatasets) Customize(cmd *cobra.Command) {
2222
}
2323

2424
func (s *ClientImportDatasets) Run(cmd *cobra.Command, args []string) error {
25-
c, err := s.getClient()
25+
c, err := s.getClient(cmd.Context())
2626
if err != nil {
2727
return err
2828
}

0 commit comments

Comments
 (0)