mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-10-23 16:37:28 +00:00
Refactor persistence config to use stores key with unified backends
- Add StoresConfig to group all store references under persistence.stores
- Use single 'default' backend instead of separate metadata_backend/inference_backend
- Update resolver to access persistence.stores.{metadata,inference,conversations}
- All SQLite distributions now use single store.db file with shared backend
This commit is contained in:
parent
099750dd00
commit
b1659369e8
21 changed files with 1723 additions and 90 deletions
|
|
@ -447,12 +447,9 @@ class InferenceStoreReference(StoreReference):
|
|||
)
|
||||
|
||||
|
||||
class PersistenceConfig(BaseModel):
|
||||
"""Unified persistence configuration."""
|
||||
class StoresConfig(BaseModel):
|
||||
"""Store references configuration."""
|
||||
|
||||
backends: dict[str, Annotated[KVStoreConfig | SqlStoreConfig, Field(discriminator="type")]] = Field(
|
||||
description="Named backend configurations (e.g., 'default', 'cache')",
|
||||
)
|
||||
metadata: StoreReference | None = Field(
|
||||
default=None,
|
||||
description="Metadata store configuration (uses KVStore backend)",
|
||||
|
|
@ -466,13 +463,28 @@ class PersistenceConfig(BaseModel):
|
|||
description="Conversations store configuration (uses SqlStore backend)",
|
||||
)
|
||||
|
||||
|
||||
class PersistenceConfig(BaseModel):
|
||||
"""Unified persistence configuration."""
|
||||
|
||||
backends: dict[str, Annotated[KVStoreConfig | SqlStoreConfig, Field(discriminator="type")]] = Field(
|
||||
description="Named backend configurations (e.g., 'default', 'cache')",
|
||||
)
|
||||
stores: StoresConfig | None = Field(
|
||||
default=None,
|
||||
description="Store references to backends",
|
||||
)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_backend_references(self) -> Self:
|
||||
"""Check all store refs point to defined backends."""
|
||||
if not self.stores:
|
||||
return self
|
||||
|
||||
stores = [
|
||||
("metadata", self.metadata),
|
||||
("inference", self.inference),
|
||||
("conversations", self.conversations),
|
||||
("metadata", self.stores.metadata),
|
||||
("inference", self.stores.inference),
|
||||
("conversations", self.stores.conversations),
|
||||
]
|
||||
for store_name, store_ref in stores:
|
||||
if store_ref and store_ref.backend not in self.backends:
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ def resolve_backend(
|
|||
Returns:
|
||||
Resolved backend config with store-specific overlays applied
|
||||
"""
|
||||
if not persistence or not store_ref:
|
||||
if not persistence or not persistence.stores or not store_ref:
|
||||
return default_factory()
|
||||
|
||||
backend_config = persistence.backends.get(store_ref.backend)
|
||||
|
|
@ -68,7 +68,7 @@ def resolve_inference_store_config(
|
|||
Returns:
|
||||
(sql_config, max_queue_size, num_writers)
|
||||
"""
|
||||
if not persistence or not persistence.inference:
|
||||
if not persistence or not persistence.stores or not persistence.stores.inference:
|
||||
# Default SQLite
|
||||
return (
|
||||
SqliteSqlStoreConfig(
|
||||
|
|
@ -78,7 +78,7 @@ def resolve_inference_store_config(
|
|||
4,
|
||||
)
|
||||
|
||||
inference_ref = persistence.inference
|
||||
inference_ref = persistence.stores.inference
|
||||
backend_config = persistence.backends.get(inference_ref.backend)
|
||||
if not backend_config:
|
||||
raise ValueError(
|
||||
|
|
@ -116,9 +116,13 @@ def resolve_metadata_store_config(
|
|||
db_path=(DISTRIBS_BASE_DIR / image_name / "kvstore.db").as_posix()
|
||||
)
|
||||
|
||||
store_ref = None
|
||||
if persistence and persistence.stores:
|
||||
store_ref = persistence.stores.metadata
|
||||
|
||||
return resolve_backend(
|
||||
persistence=persistence,
|
||||
store_ref=persistence.metadata if persistence else None,
|
||||
store_ref=store_ref,
|
||||
default_factory=lambda: default_config,
|
||||
store_name="metadata",
|
||||
)
|
||||
|
|
@ -137,9 +141,13 @@ def resolve_conversations_store_config(
|
|||
db_path=(RUNTIME_BASE_DIR / "conversations.db").as_posix()
|
||||
)
|
||||
|
||||
store_ref = None
|
||||
if persistence and persistence.stores:
|
||||
store_ref = persistence.stores.conversations
|
||||
|
||||
return resolve_backend(
|
||||
persistence=persistence,
|
||||
store_ref=persistence.conversations if persistence else None,
|
||||
store_ref=store_ref,
|
||||
default_factory=lambda: default_config,
|
||||
store_name="conversations",
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue