Skip to content

Commit 14f26ef

Browse files
committed
fix
Signed-off-by: Huamin Chen <[email protected]>
1 parent 4310d92 commit 14f26ef

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

candle-binding/src/model_architectures/traditional/deberta_v3_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn test_deberta_v3_invalid_path() {
2929
#[test]
3030
fn test_deberta_v3_debug_format() {
3131
// Test that the Debug trait exists
32-
let _type_check: Option<Box<dyn std::fmt::Debug>> = None::<Box<DebertaV3Classifier>>;
32+
let _type_check: Option<Box<dyn std::fmt::Debug>> = None;
3333
}
3434

3535
#[cfg(test)]

config/config.redis.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ semantic_cache:
99
similarity_threshold: 0.80 # Global threshold (lowered for better matching)
1010
ttl_seconds: 3600
1111
backend_config_path: "config/semantic-cache/redis.yaml"
12-
1312
# Embedding model for semantic similarity matching
1413
# Options: "bert" (fast, 384-dim), "qwen3" (high quality, 1024-dim, 32K context), "gemma" (balanced, 768-dim, 8K context)
1514
# Default: "bert" (fastest, lowest memory)

src/semantic-router/pkg/cache/cache_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ development:
275275
Context("with unsupported backend type", func() {
276276
It("should return error for unsupported backend type", func() {
277277
config := CacheConfig{
278-
BackendType: "redis", // Unsupported
278+
BackendType: "unsupported_type", // Unsupported
279279
Enabled: true,
280280
SimilarityThreshold: 0.8,
281281
TTLSeconds: 3600,
@@ -492,7 +492,7 @@ development:
492492
It("should return information about available backends", func() {
493493
backends := GetAvailableCacheBackends()
494494

495-
Expect(backends).To(HaveLen(2)) // Memory and Milvus
495+
Expect(backends).To(HaveLen(3)) // Memory, Milvus, and Redis
496496

497497
// Check memory backend info
498498
memoryBackend := backends[0]
@@ -509,6 +509,14 @@ development:
509509
Expect(milvusBackend.Description).To(ContainSubstring("Milvus vector database"))
510510
Expect(milvusBackend.Features).To(ContainElement("Highly scalable"))
511511
Expect(milvusBackend.Features).To(ContainElement("Persistent storage"))
512+
513+
// Check Redis backend info
514+
redisBackend := backends[2]
515+
Expect(redisBackend.Type).To(Equal(RedisCacheType))
516+
Expect(redisBackend.Name).To(Equal("Redis Vector Database"))
517+
Expect(redisBackend.Description).To(ContainSubstring("Redis with vector search"))
518+
Expect(redisBackend.Features).To(ContainElement("Fast in-memory performance"))
519+
Expect(redisBackend.Features).To(ContainElement("TTL support"))
512520
})
513521
})
514522
})

src/semantic-router/pkg/cache/redis_cache.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,9 @@ func (c *RedisCache) UpdateWithResponse(requestID string, responseBody []byte) e
419419
logging.Infof("UpdateWithResponse: found %d result(s) for request_id=%s", results.Total, requestID)
420420

421421
doc := results.Docs[0]
422-
model, _ := doc.Fields["model"]
423-
queryStr, _ := doc.Fields["query"]
424-
requestBodyStr, _ := doc.Fields["request_body"]
422+
model := fmt.Sprint(doc.Fields["model"])
423+
queryStr := fmt.Sprint(doc.Fields["query"])
424+
requestBodyStr := fmt.Sprint(doc.Fields["request_body"])
425425

426426
// Extract document ID from the result
427427
docID := doc.ID
@@ -639,7 +639,13 @@ func (c *RedisCache) FindSimilarWithThreshold(model string, query string, thresh
639639
}
640640

641641
var distance float64
642-
fmt.Sscanf(fmt.Sprint(distanceVal), "%f", &distance)
642+
if _, err := fmt.Sscanf(fmt.Sprint(distanceVal), "%f", &distance); err != nil {
643+
logging.Infof("RedisCache.FindSimilarWithThreshold: failed to parse distance value: %v", err)
644+
atomic.AddInt64(&c.missCount, 1)
645+
metrics.RecordCacheOperation("redis", "find_similar", "error", time.Since(start).Seconds())
646+
metrics.RecordCacheMiss()
647+
return nil, false, nil
648+
}
643649

644650
// Convert distance to similarity score based on metric type
645651
var similarity float32

0 commit comments

Comments
 (0)