feat(components): support call-time index option (#1047)

This commit is contained in:
tangchaojun-bytedance
2026-05-28 17:26:31 +08:00
committed by GitHub
parent 804b9d4779
commit 292d298c9b
3 changed files with 17 additions and 2 deletions
+3 -2
View File
@@ -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 {
+11
View File
@@ -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{
+3
View File
@@ -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,
})