Skip to content

Commit 5b3c65d

Browse files
authored
fix: parse Milvus snake_case config fields correctly (#616)
Signed-off-by: cryo <zdtna412@gmail.com>
1 parent bccdc30 commit 5b3c65d

File tree

2 files changed

+103
-56
lines changed

2 files changed

+103
-56
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,51 @@ connection:
227227
})
228228
})
229229

230+
Context("Milvus YAML parsing", func() {
231+
It("should parse snake_case configuration fields without default fallbacks", func() {
232+
configPath := filepath.Join(tempDir, "milvus-snake.yaml")
233+
configYAML := `
234+
connection:
235+
host: "localhost"
236+
port: 19530
237+
collection:
238+
name: "yaml_snake_case"
239+
vector_field:
240+
name: "custom_embedding"
241+
dimension: 512
242+
metric_type: "L2"
243+
index:
244+
type: "IVF_FLAT"
245+
params:
246+
M: 24
247+
efConstruction: 128
248+
search:
249+
params:
250+
ef: 42
251+
topk: 25
252+
development:
253+
auto_create_collection: true
254+
drop_collection_on_startup: true
255+
`
256+
err := os.WriteFile(configPath, []byte(configYAML), 0o644)
257+
Expect(err).NotTo(HaveOccurred())
258+
259+
config, err := loadMilvusConfig(configPath)
260+
Expect(err).NotTo(HaveOccurred())
261+
Expect(config.Collection.Name).To(Equal("yaml_snake_case"))
262+
Expect(config.Collection.VectorField.Name).To(Equal("custom_embedding"))
263+
Expect(config.Collection.VectorField.Dimension).To(Equal(512))
264+
Expect(config.Collection.VectorField.MetricType).To(Equal("L2"))
265+
Expect(config.Collection.Index.Type).To(Equal("IVF_FLAT"))
266+
Expect(config.Collection.Index.Params.M).To(Equal(24))
267+
Expect(config.Collection.Index.Params.EfConstruction).To(Equal(128))
268+
Expect(config.Search.Params.Ef).To(Equal(42))
269+
Expect(config.Search.TopK).To(Equal(25))
270+
Expect(config.Development.AutoCreateCollection).To(BeTrue())
271+
Expect(config.Development.DropCollectionOnStartup).To(BeTrue())
272+
})
273+
})
274+
230275
Context("with unsupported backend type", func() {
231276
It("should return error for unsupported backend type", func() {
232277
config := CacheConfig{

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

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -18,80 +18,82 @@ import (
1818
"github.com/vllm-project/semantic-router/src/semantic-router/pkg/observability/metrics"
1919
)
2020

21-
// MilvusConfig defines the complete configuration structure for Milvus cache backend
21+
// MilvusConfig defines the complete configuration structure for Milvus cache backend.
22+
// Fields use both json/yaml tags because sigs.k8s.io/yaml converts YAML→JSON before decoding,
23+
// so json tags ensure snake_case keys map correctly without switching parsers.
2224
type MilvusConfig struct {
2325
Connection struct {
24-
Host string `yaml:"host"`
25-
Port int `yaml:"port"`
26-
Database string `yaml:"database"`
27-
Timeout int `yaml:"timeout"`
26+
Host string `json:"host" yaml:"host"`
27+
Port int `json:"port" yaml:"port"`
28+
Database string `json:"database" yaml:"database"`
29+
Timeout int `json:"timeout" yaml:"timeout"`
2830
Auth struct {
29-
Enabled bool `yaml:"enabled"`
30-
Username string `yaml:"username"`
31-
Password string `yaml:"password"`
32-
} `yaml:"auth"`
31+
Enabled bool `json:"enabled" yaml:"enabled"`
32+
Username string `json:"username" yaml:"username"`
33+
Password string `json:"password" yaml:"password"`
34+
} `json:"auth" yaml:"auth"`
3335
TLS struct {
34-
Enabled bool `yaml:"enabled"`
35-
CertFile string `yaml:"cert_file"`
36-
KeyFile string `yaml:"key_file"`
37-
CAFile string `yaml:"ca_file"`
38-
} `yaml:"tls"`
39-
} `yaml:"connection"`
36+
Enabled bool `json:"enabled" yaml:"enabled"`
37+
CertFile string `json:"cert_file" yaml:"cert_file"`
38+
KeyFile string `json:"key_file" yaml:"key_file"`
39+
CAFile string `json:"ca_file" yaml:"ca_file"`
40+
} `json:"tls" yaml:"tls"`
41+
} `json:"connection" yaml:"connection"`
4042
Collection struct {
41-
Name string `yaml:"name"`
42-
Description string `yaml:"description"`
43+
Name string `json:"name" yaml:"name"`
44+
Description string `json:"description" yaml:"description"`
4345
VectorField struct {
44-
Name string `yaml:"name"`
45-
Dimension int `yaml:"dimension"`
46-
MetricType string `yaml:"metric_type"`
47-
} `yaml:"vector_field"`
46+
Name string `json:"name" yaml:"name"`
47+
Dimension int `json:"dimension" yaml:"dimension"`
48+
MetricType string `json:"metric_type" yaml:"metric_type"`
49+
} `json:"vector_field" yaml:"vector_field"`
4850
Index struct {
49-
Type string `yaml:"type"`
51+
Type string `json:"type" yaml:"type"`
5052
Params struct {
51-
M int `yaml:"M"`
52-
EfConstruction int `yaml:"efConstruction"`
53-
} `yaml:"params"`
54-
} `yaml:"index"`
55-
} `yaml:"collection"`
53+
M int `json:"M" yaml:"M"`
54+
EfConstruction int `json:"efConstruction" yaml:"efConstruction"`
55+
} `json:"params" yaml:"params"`
56+
} `json:"index" yaml:"index"`
57+
} `json:"collection" yaml:"collection"`
5658
Search struct {
5759
Params struct {
58-
Ef int `yaml:"ef"`
59-
} `yaml:"params"`
60-
TopK int `yaml:"topk"`
61-
ConsistencyLevel string `yaml:"consistency_level"`
62-
} `yaml:"search"`
60+
Ef int `json:"ef" yaml:"ef"`
61+
} `json:"params" yaml:"params"`
62+
TopK int `json:"topk" yaml:"topk"`
63+
ConsistencyLevel string `json:"consistency_level" yaml:"consistency_level"`
64+
} `json:"search" yaml:"search"`
6365
Performance struct {
6466
ConnectionPool struct {
65-
MaxConnections int `yaml:"max_connections"`
66-
MaxIdleConnections int `yaml:"max_idle_connections"`
67-
AcquireTimeout int `yaml:"acquire_timeout"`
68-
} `yaml:"connection_pool"`
67+
MaxConnections int `json:"max_connections" yaml:"max_connections"`
68+
MaxIdleConnections int `json:"max_idle_connections" yaml:"max_idle_connections"`
69+
AcquireTimeout int `json:"acquire_timeout" yaml:"acquire_timeout"`
70+
} `json:"connection_pool" yaml:"connection_pool"`
6971
Batch struct {
70-
InsertBatchSize int `yaml:"insert_batch_size"`
71-
Timeout int `yaml:"timeout"`
72-
} `yaml:"batch"`
73-
} `yaml:"performance"`
72+
InsertBatchSize int `json:"insert_batch_size" yaml:"insert_batch_size"`
73+
Timeout int `json:"timeout" yaml:"timeout"`
74+
} `json:"batch" yaml:"batch"`
75+
} `json:"performance" yaml:"performance"`
7476
DataManagement struct {
7577
TTL struct {
76-
Enabled bool `yaml:"enabled"`
77-
TimestampField string `yaml:"timestamp_field"`
78-
CleanupInterval int `yaml:"cleanup_interval"`
79-
} `yaml:"ttl"`
78+
Enabled bool `json:"enabled" yaml:"enabled"`
79+
TimestampField string `json:"timestamp_field" yaml:"timestamp_field"`
80+
CleanupInterval int `json:"cleanup_interval" yaml:"cleanup_interval"`
81+
} `json:"ttl" yaml:"ttl"`
8082
Compaction struct {
81-
Enabled bool `yaml:"enabled"`
82-
Interval int `yaml:"interval"`
83-
} `yaml:"compaction"`
84-
} `yaml:"data_management"`
83+
Enabled bool `json:"enabled" yaml:"enabled"`
84+
Interval int `json:"interval" yaml:"interval"`
85+
} `json:"compaction" yaml:"compaction"`
86+
} `json:"data_management" yaml:"data_management"`
8587
Logging struct {
86-
Level string `yaml:"level"`
87-
EnableQueryLog bool `yaml:"enable_query_log"`
88-
EnableMetrics bool `yaml:"enable_metrics"`
89-
} `yaml:"logging"`
88+
Level string `json:"level" yaml:"level"`
89+
EnableQueryLog bool `json:"enable_query_log" yaml:"enable_query_log"`
90+
EnableMetrics bool `json:"enable_metrics" yaml:"enable_metrics"`
91+
} `json:"logging" yaml:"logging"`
9092
Development struct {
91-
DropCollectionOnStartup bool `yaml:"drop_collection_on_startup"`
92-
AutoCreateCollection bool `yaml:"auto_create_collection"`
93-
VerboseErrors bool `yaml:"verbose_errors"`
94-
} `yaml:"development"`
93+
DropCollectionOnStartup bool `json:"drop_collection_on_startup" yaml:"drop_collection_on_startup"`
94+
AutoCreateCollection bool `json:"auto_create_collection" yaml:"auto_create_collection"`
95+
VerboseErrors bool `json:"verbose_errors" yaml:"verbose_errors"`
96+
} `json:"development" yaml:"development"`
9597
}
9698

9799
// MilvusCache provides a scalable semantic cache implementation using Milvus vector database

0 commit comments

Comments
 (0)