@@ -34,6 +34,8 @@ import (
34
34
const (
35
35
kvCacheAwareScorerName = "KVCacheAwareScorer"
36
36
cacheStalenessThreshold = 5 * time .Second
37
+ kvCacheRedisEnvVar = "KVCACHE_INDEXER_REDIS_ADDR"
38
+ huggingFaceTokenEnvVar = "HF_TOKEN"
37
39
)
38
40
39
41
// KVCacheAwareScorer is a concrete implementation of the Scorer interface.
@@ -45,29 +47,29 @@ type KVCacheAwareScorer struct {
45
47
scoresCacheLastUpdate time.Time
46
48
}
47
49
48
- func kvCacheIndexerConfigFromEnv () * kvcache.Config {
50
+ // NewKVCacheAwareScorer creates a new KVCacheAwareScorer instance.
51
+ // It initializes the KVCacheIndexer with the provided configuration,
52
+ // and runs it with the given context.
53
+ //
54
+ // If the configuration is nil, it uses the default configuration.
55
+ func NewKVCacheAwareScorer (ctx context.Context ) (types.Scorer , error ) {
49
56
config := kvcache .NewDefaultConfig ()
50
57
51
- redisAddr := os .Getenv ("KVCACHE_INDEXER_REDIS_ADDR" )
58
+ redisAddr := os .Getenv (kvCacheRedisEnvVar )
52
59
if redisAddr != "" {
53
60
config .KVBlockIndexerConfig .RedisKVBlockIndexerConfig .RedisAddr = redisAddr
61
+ } else {
62
+ return nil , fmt .Errorf ("environment variable %s is not set" , kvCacheRedisEnvVar )
54
63
}
55
64
56
- hfToken := os .Getenv ("HF_TOKEN" )
65
+ hfToken := os .Getenv (huggingFaceTokenEnvVar )
57
66
if hfToken != "" {
58
67
config .TokenizersPoolConfig .HFTokenizerConfig .HuggingFaceToken = hfToken
68
+ } else {
69
+ return nil , fmt .Errorf ("environment variable %s is not set" , huggingFaceTokenEnvVar )
59
70
}
60
71
61
- return config
62
- }
63
-
64
- // NewKVCacheAwareScorer creates a new KVCacheAwareScorer instance.
65
- // It initializes the KVCacheIndexer with the provided configuration,
66
- // and runs it with the given context.
67
- //
68
- // If the configuration is nil, it uses the default configuration.
69
- func NewKVCacheAwareScorer (ctx context.Context ) (types.Scorer , error ) {
70
- kvCacheIndexer , err := kvcache .NewKVCacheIndexer (kvCacheIndexerConfigFromEnv ())
72
+ kvCacheIndexer , err := kvcache .NewKVCacheIndexer (config )
71
73
if err != nil {
72
74
return nil , fmt .Errorf ("failed to create KVCacheIndexer: %w" , err )
73
75
}
0 commit comments