Skip to content

Commit ef77b06

Browse files
feat(components): support call-time index option
1 parent 804b9d4 commit ef77b06

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

components/indexer/interface.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ import (
3030
// the implementation generates vectors before storing — the same embedder
3131
// must be used by the paired [retriever.Retriever].
3232
//
33-
// Use [Options.SubIndexes] to write documents into logical sub-partitions
34-
// within the same store.
33+
// Use [Options.Index] to choose a backend index at call time, and
34+
// [Options.SubIndexes] to write documents into logical sub-partitions within
35+
// the same store.
3536
//
3637
//go:generate mockgen -destination ../../internal/mock/components/indexer/indexer_mock.go --package indexer -source interface.go
3738
type Indexer interface {

components/indexer/option.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,23 @@ import "github.com/cloudwego/eino/components/embedding"
2020

2121
// Options is the options for the indexer.
2222
type Options struct {
23+
// Index is the index for the indexer, index in different indexers may be different.
24+
Index *string
2325
// SubIndexes is the sub indexes to be indexed.
2426
SubIndexes []string
2527
// Embedding is the embedding component.
2628
Embedding embedding.Embedder
2729
}
2830

31+
// WithIndex wraps the index option.
32+
func WithIndex(index string) Option {
33+
return Option{
34+
apply: func(opts *Options) {
35+
opts.Index = &index
36+
},
37+
}
38+
}
39+
2940
// WithSubIndexes is the option to set the sub indexes for the indexer.
3041
func WithSubIndexes(subIndexes []string) Option {
3142
return Option{

components/indexer/option_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,20 @@ import (
2727
func TestOptions(t *testing.T) {
2828
convey.Convey("test options", t, func() {
2929
var (
30+
index = "index"
3031
subIndexes = []string{"index_1", "index_2"}
3132
e = &embedding.MockEmbedder{}
3233
)
3334

3435
opts := GetCommonOptions(
3536
&Options{},
37+
WithIndex(index),
3638
WithSubIndexes(subIndexes),
3739
WithEmbedding(e),
3840
)
3941

4042
convey.So(opts, convey.ShouldResemble, &Options{
43+
Index: &index,
4144
SubIndexes: subIndexes,
4245
Embedding: e,
4346
})

0 commit comments

Comments
 (0)