Skip to content

Commit ff9276d

Browse files
authored
Merge pull request #1200 from max-svistunov/lcore-1260-fix-vector-store-dedup
LCORE-1260 Deduplicate vector_store entries when modifying BYOK RAG config
2 parents 6ad3b82 + d059014 commit ff9276d

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

src/llama_stack_configuration.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,15 @@ def construct_vector_stores_section(
179179
if "vector_stores" in ls_config["registered_resources"]:
180180
output = ls_config["registered_resources"]["vector_stores"].copy()
181181

182-
# append new vector_stores entries
182+
# append new vector_stores entries, skipping duplicates
183+
existing_store_ids = {vs.get("vector_store_id") for vs in output}
184+
added = 0
183185
for brag in byok_rag:
184186
vector_db_id = brag.get("vector_db_id", "")
187+
if vector_db_id in existing_store_ids:
188+
continue
189+
existing_store_ids.add(vector_db_id)
190+
added += 1
185191
output.append(
186192
{
187193
"vector_store_id": vector_db_id,
@@ -192,7 +198,7 @@ def construct_vector_stores_section(
192198
)
193199
logger.info(
194200
"Added %s items into registered_resources.vector_stores, total items %s",
195-
len(byok_rag),
201+
added,
196202
len(output),
197203
)
198204
return output

tests/unit/test_llama_stack_configuration.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,47 @@ def test_construct_vector_stores_section_merge() -> None:
7878
assert len(output) == 2
7979

8080

81+
def test_construct_vector_stores_section_skips_duplicate_from_existing() -> None:
82+
"""Test skips BYOK entry when vector_store_id already exists in config."""
83+
ls_config = {
84+
"registered_resources": {
85+
"vector_stores": [
86+
{"vector_store_id": "store1", "provider_id": "original_provider"},
87+
]
88+
}
89+
}
90+
byok_rag = [
91+
{
92+
"vector_db_id": "store1",
93+
"embedding_model": "test-model",
94+
"embedding_dimension": 512,
95+
},
96+
]
97+
output = construct_vector_stores_section(ls_config, byok_rag)
98+
assert len(output) == 1
99+
assert output[0]["provider_id"] == "original_provider"
100+
101+
102+
def test_construct_vector_stores_section_skips_duplicate_within_byok() -> None:
103+
"""Test skips duplicate vector_db_id entries within the BYOK RAG list."""
104+
ls_config: dict[str, Any] = {}
105+
byok_rag = [
106+
{
107+
"vector_db_id": "store1",
108+
"embedding_model": "model-a",
109+
"embedding_dimension": 512,
110+
},
111+
{
112+
"vector_db_id": "store1",
113+
"embedding_model": "model-b",
114+
"embedding_dimension": 768,
115+
},
116+
]
117+
output = construct_vector_stores_section(ls_config, byok_rag)
118+
assert len(output) == 1
119+
assert output[0]["embedding_model"] == "model-a"
120+
121+
81122
# =============================================================================
82123
# Test construct_vector_io_providers_section
83124
# =============================================================================

0 commit comments

Comments
 (0)