diff --git a/components/indexer/interface.go b/components/indexer/interface.go index 139e914b..59154fd1 100644 --- a/components/indexer/interface.go +++ b/components/indexer/interface.go @@ -30,8 +30,9 @@ import ( // the implementation generates vectors before storing — the same embedder // must be used by the paired [retriever.Retriever]. // -// Use [Options.SubIndexes] to write documents into logical sub-partitions -// within the same store. +// Use [Options.Index] to choose a backend index at call time, and +// [Options.SubIndexes] to write documents into logical sub-partitions within +// the same store. // //go:generate mockgen -destination ../../internal/mock/components/indexer/indexer_mock.go --package indexer -source interface.go type Indexer interface { diff --git a/components/indexer/option.go b/components/indexer/option.go index e799fe12..9d095add 100644 --- a/components/indexer/option.go +++ b/components/indexer/option.go @@ -20,12 +20,23 @@ import "github.com/cloudwego/eino/components/embedding" // Options is the options for the indexer. type Options struct { + // Index is the index for the indexer, index in different indexers may be different. + Index *string // SubIndexes is the sub indexes to be indexed. SubIndexes []string // Embedding is the embedding component. Embedding embedding.Embedder } +// WithIndex wraps the index option. +func WithIndex(index string) Option { + return Option{ + apply: func(opts *Options) { + opts.Index = &index + }, + } +} + // WithSubIndexes is the option to set the sub indexes for the indexer. func WithSubIndexes(subIndexes []string) Option { return Option{ diff --git a/components/indexer/option_test.go b/components/indexer/option_test.go index 92929c20..1ef37b5a 100644 --- a/components/indexer/option_test.go +++ b/components/indexer/option_test.go @@ -27,17 +27,20 @@ import ( func TestOptions(t *testing.T) { convey.Convey("test options", t, func() { var ( + index = "index" subIndexes = []string{"index_1", "index_2"} e = &embedding.MockEmbedder{} ) opts := GetCommonOptions( &Options{}, + WithIndex(index), WithSubIndexes(subIndexes), WithEmbedding(e), ) convey.So(opts, convey.ShouldResemble, &Options{ + Index: &index, SubIndexes: subIndexes, Embedding: e, })