Skip to content

Commit 91f1b35

Browse files
authored
chore: add storage sane defaults (#4182)
# What does this PR do? since `StackRunConfig` requires certain parts of `StorageConfig`, it'd probably make sense to template in some defaults that will "just work" for most usecases specifically introduce`ServerStoresConfig` defaults for inference, metadata, conversations and prompts. We already actually funnel in defaults for these sections ad-hoc throughout the codebase additionally set some `backends` defaults for the `StorageConfig`. This will alleviate some weirdness for `--providers` for run/list-deps and also some work I have to better align our list-deps/run datatypes --------- Signed-off-by: Charlie Doern <cdoern@redhat.com>
1 parent bd5ad29 commit 91f1b35

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

src/llama_stack/core/storage/datatypes.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
from pydantic import BaseModel, Field, field_validator
1414

15+
from llama_stack.core.utils.config_dirs import DISTRIBS_BASE_DIR
16+
1517

1618
class StorageBackendType(StrEnum):
1719
KV_REDIS = "kv_redis"
@@ -256,29 +258,46 @@ class ResponsesStoreReference(InferenceStoreReference):
256258

257259
class ServerStoresConfig(BaseModel):
258260
metadata: KVStoreReference | None = Field(
259-
default=None,
261+
default=KVStoreReference(
262+
backend="kv_default",
263+
namespace="registry",
264+
),
260265
description="Metadata store configuration (uses KV backend)",
261266
)
262267
inference: InferenceStoreReference | None = Field(
263-
default=None,
268+
default=InferenceStoreReference(
269+
backend="sql_default",
270+
table_name="inference_store",
271+
),
264272
description="Inference store configuration (uses SQL backend)",
265273
)
266274
conversations: SqlStoreReference | None = Field(
267-
default=None,
275+
default=SqlStoreReference(
276+
backend="sql_default",
277+
table_name="openai_conversations",
278+
),
268279
description="Conversations store configuration (uses SQL backend)",
269280
)
270281
responses: ResponsesStoreReference | None = Field(
271282
default=None,
272283
description="Responses store configuration (uses SQL backend)",
273284
)
274285
prompts: KVStoreReference | None = Field(
275-
default=None,
286+
default=KVStoreReference(backend="kv_default", namespace="prompts"),
276287
description="Prompts store configuration (uses KV backend)",
277288
)
278289

279290

280291
class StorageConfig(BaseModel):
281292
backends: dict[str, StorageBackendConfig] = Field(
293+
default={
294+
"kv_default": SqliteKVStoreConfig(
295+
db_path=f"${{env.SQLITE_STORE_DIR:={DISTRIBS_BASE_DIR}}}/kvstore.db",
296+
),
297+
"sql_default": SqliteSqlStoreConfig(
298+
db_path=f"${{env.SQLITE_STORE_DIR:={DISTRIBS_BASE_DIR}}}/sql_store.db",
299+
),
300+
},
282301
description="Named backend configurations (e.g., 'default', 'cache')",
283302
)
284303
stores: ServerStoresConfig = Field(

tests/unit/conversations/test_conversations.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ async def service():
3838
},
3939
stores=ServerStoresConfig(
4040
conversations=SqlStoreReference(backend="sql_test", table_name="openai_conversations"),
41+
metadata=None,
42+
inference=None,
43+
prompts=None,
4144
),
4245
)
4346
register_sqlstore_backends({"sql_test": storage.backends["sql_test"]})
@@ -142,6 +145,9 @@ async def test_policy_configuration():
142145
},
143146
stores=ServerStoresConfig(
144147
conversations=SqlStoreReference(backend="sql_test", table_name="openai_conversations"),
148+
metadata=None,
149+
inference=None,
150+
prompts=None,
145151
),
146152
)
147153
register_sqlstore_backends({"sql_test": storage.backends["sql_test"]})

tests/unit/core/test_stack_validation.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
import pytest
1212

13-
from llama_stack.core.datatypes import QualifiedModel, SafetyConfig, StackRunConfig, StorageConfig, VectorStoresConfig
13+
from llama_stack.core.datatypes import QualifiedModel, SafetyConfig, StackRunConfig, VectorStoresConfig
1414
from llama_stack.core.stack import validate_safety_config, validate_vector_stores_config
15+
from llama_stack.core.storage.datatypes import ServerStoresConfig, StorageConfig
1516
from llama_stack_api import Api, ListModelsResponse, ListShieldsResponse, Model, ModelType, Shield
1617

1718

@@ -21,7 +22,15 @@ async def test_validate_missing_model(self):
2122
run_config = StackRunConfig(
2223
image_name="test",
2324
providers={},
24-
storage=StorageConfig(backends={}, stores={}),
25+
storage=StorageConfig(
26+
backends={},
27+
stores=ServerStoresConfig(
28+
metadata=None,
29+
inference=None,
30+
conversations=None,
31+
prompts=None,
32+
),
33+
),
2534
vector_stores=VectorStoresConfig(
2635
default_provider_id="faiss",
2736
default_embedding_model=QualifiedModel(
@@ -41,7 +50,15 @@ async def test_validate_success(self):
4150
run_config = StackRunConfig(
4251
image_name="test",
4352
providers={},
44-
storage=StorageConfig(backends={}, stores={}),
53+
storage=StorageConfig(
54+
backends={},
55+
stores=ServerStoresConfig(
56+
metadata=None,
57+
inference=None,
58+
conversations=None,
59+
prompts=None,
60+
),
61+
),
4562
vector_stores=VectorStoresConfig(
4663
default_provider_id="faiss",
4764
default_embedding_model=QualifiedModel(

0 commit comments

Comments
 (0)