Skip to content

Commit

Permalink
[Go] rename localvec.DefineStore
Browse files Browse the repository at this point in the history
I tried to separate DefineStore into DefineIndexer and DefineRetriever,
but I didn't see a good way to share the in-memory state of the store.
Although DefineIndexerAndRetriever is cumbersome, it at least
removes the otherwise unused term "Store".
  • Loading branch information
jba committed Jun 24, 2024
1 parent 0d65c37 commit 442ca56
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions go/plugins/localvec/localvec.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ type Config struct {
// Init initializes the plugin.
func Init() error { return nil }

// DefineStore defines an indexer and retriever that share the same underlying storage.
// The name uniquely identifies the the indexer and retriever in the registry.
func DefineStore(name string, cfg Config) (*ai.Indexer, *ai.Retriever, error) {
// DefineIndexerAndRetriever defines an Indexer and Retriever that share the same underlying storage.
// The name uniquely identifies the the Indexer and Retriever in the registry.
func DefineIndexerAndRetriever(name string, cfg Config) (*ai.Indexer, *ai.Retriever, error) {
ds, err := newDocStore(cfg.Dir, name, cfg.Embedder, cfg.EmbedderOptions)
if err != nil {
return nil, nil, err
Expand Down
2 changes: 1 addition & 1 deletion go/plugins/localvec/localvec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func TestInit(t *testing.T) {
t.Fatal(err)
}
const name = "mystore"
ind, ret, err := DefineStore(name, Config{Embedder: embedder})
ind, ret, err := DefineIndexerAndRetriever(name, Config{Embedder: embedder})
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 2 additions & 0 deletions go/plugins/pinecone/genkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type Config struct {
TextKey string
}

// DefineIndexer defines an Indexer with the given configuration.
func DefineIndexer(ctx context.Context, cfg Config) (*ai.Indexer, error) {
ds, err := newDocStore(ctx, cfg)
if err != nil {
Expand All @@ -90,6 +91,7 @@ func DefineIndexer(ctx context.Context, cfg Config) (*ai.Indexer, error) {
return ai.DefineIndexer(provider, cfg.IndexID, ds.Index), nil
}

// DefineRetriever defines a Retriever with the given configuration.
func DefineRetriever(ctx context.Context, cfg Config) (*ai.Retriever, error) {
ds, err := newDocStore(ctx, cfg)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go/samples/menu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
indexer, retriever, err := localvec.DefineStore("go-menu_items", localvec.Config{
indexer, retriever, err := localvec.DefineIndexerAndRetriever("go-menu_items", localvec.Config{
Embedder: embedder,
})
if err := setup04(ctx, indexer, retriever, model); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go/samples/rag/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func main() {
if err := localvec.Init(); err != nil {
log.Fatal(err)
}
indexer, retriever, err := localvec.DefineStore("simpleQa", localvec.Config{Embedder: embedder})
indexer, retriever, err := localvec.DefineIndexerAndRetriever("simpleQa", localvec.Config{Embedder: embedder})
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 442ca56

Please sign in to comment.