File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
3738type Indexer interface {
Original file line number Diff line number Diff line change @@ -20,12 +20,23 @@ import "github.com/cloudwego/eino/components/embedding"
2020
2121// Options is the options for the indexer.
2222type 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.
3041func WithSubIndexes (subIndexes []string ) Option {
3142 return Option {
Original file line number Diff line number Diff line change @@ -27,17 +27,20 @@ import (
2727func 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 })
You can’t perform that action at this time.
0 commit comments