feat(memory): add hybrid gateway configuration
This commit is contained in:
@ -15,6 +15,8 @@ from .schema import (
|
||||
BeaverConfig,
|
||||
ChannelConfig,
|
||||
EmbeddingConfig,
|
||||
MemoryConfig,
|
||||
MemoryGatewayConfig,
|
||||
MCPServerConfig,
|
||||
ProviderConfig,
|
||||
ToolsConfig,
|
||||
@ -76,6 +78,7 @@ def load_config(
|
||||
authz=_parse_authz(data.get("authz")),
|
||||
channels=_parse_channels(data.get("channels")),
|
||||
backend_identity=_parse_backend_identity(data.get("backend_identity") or data.get("backendIdentity")),
|
||||
memory=_parse_memory(data),
|
||||
config_path=path,
|
||||
)
|
||||
|
||||
@ -251,6 +254,50 @@ def _parse_backend_identity(raw: Any) -> BackendIdentityConfig:
|
||||
)
|
||||
|
||||
|
||||
def _parse_memory(data: dict[str, Any]) -> MemoryConfig:
|
||||
explicit = "memory" in data
|
||||
raw = _as_dict(data.get("memory"))
|
||||
mode = (_string(raw.get("mode")) or "hybrid").lower()
|
||||
if mode not in {"curated", "hybrid"}:
|
||||
raise ValueError("memory.mode must be 'curated' or 'hybrid'")
|
||||
|
||||
gateway_raw = _as_dict(raw.get("gateway"))
|
||||
parsed_top_k = _int(_first_config_value(gateway_raw.get("topK"), gateway_raw.get("top_k")))
|
||||
parsed_timeout = _float(
|
||||
_first_config_value(gateway_raw.get("timeoutSeconds"), gateway_raw.get("timeout_seconds"))
|
||||
)
|
||||
gateway = MemoryGatewayConfig(
|
||||
base_url=_string(gateway_raw.get("baseUrl") or gateway_raw.get("base_url")) or "",
|
||||
user_id=_string(gateway_raw.get("userId") or gateway_raw.get("user_id")) or "",
|
||||
user_key=_string(gateway_raw.get("userKey") or gateway_raw.get("user_key")) or "",
|
||||
app_id=_string(gateway_raw.get("appId") or gateway_raw.get("app_id")) or "default",
|
||||
project_id=_string(gateway_raw.get("projectId") or gateway_raw.get("project_id")) or "default",
|
||||
scope=_string_list(gateway_raw.get("scope")) or ["current_chat", "resources"],
|
||||
top_k=8 if parsed_top_k is None else parsed_top_k,
|
||||
timeout_seconds=10.0 if parsed_timeout is None else parsed_timeout,
|
||||
)
|
||||
|
||||
if mode == "hybrid" and explicit:
|
||||
missing: list[str] = []
|
||||
if not gateway.base_url:
|
||||
missing.append("baseUrl")
|
||||
if not gateway.user_id:
|
||||
missing.append("userId")
|
||||
if not gateway.user_key:
|
||||
missing.append("userKey")
|
||||
if missing:
|
||||
raise ValueError(f"Explicit hybrid memory requires gateway fields: {', '.join(missing)}")
|
||||
allowed_scopes = {"current_chat", "resources", "all_user_memory"}
|
||||
if not gateway.scope or any(scope not in allowed_scopes for scope in gateway.scope):
|
||||
raise ValueError("memory.gateway.scope contains an unsupported value")
|
||||
if gateway.top_k < 1 or gateway.top_k > 100:
|
||||
raise ValueError("memory.gateway.topK must be between 1 and 100")
|
||||
if gateway.timeout_seconds <= 0:
|
||||
raise ValueError("memory.gateway.timeoutSeconds must be positive")
|
||||
|
||||
return MemoryConfig(mode=mode, explicit=explicit, gateway=gateway)
|
||||
|
||||
|
||||
def _as_dict(value: Any) -> dict[str, Any]:
|
||||
return value if isinstance(value, dict) else {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user