Skip to content

Warn on high-cost LightRAG and LivingMemory config#199

Merged
EterUltimate merged 1 commit into
NickCharlie:mainfrom
EterUltimate:codex/issue-198-cost-warning
Jun 11, 2026
Merged

Warn on high-cost LightRAG and LivingMemory config#199
EterUltimate merged 1 commit into
NickCharlie:mainfrom
EterUltimate:codex/issue-198-cost-warning

Conversation

@EterUltimate

@EterUltimate EterUltimate commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Closes #198.

Summary

  • Add a shared high-cost configuration detector for knowledge_engine=lightrag + lightrag_query_mode=hybrid/mix + LivingMemory memory delegation.
  • Surface non-blocking cost warnings in config validation, /api/config/schema, and /api/integrations/status.
  • Show the warning in the settings UI and integration settings area, and expand AstrBot schema/doc hints for the same combination.
  • Keep behavior advisory-only: users can still choose the high-quality hybrid/mix mode deliberately.

Validation

  • python -m json.tool _conf_schema.json > $null
  • python -m py_compile config.py webui\services\config_service.py webui\services\integration_service.py tests\unit\test_config.py tests\unit\test_config_service.py tests\unit\test_integration_service.py tests\integration\test_config_blueprint.py tests\integration\test_webui_static_assets.py
  • python -m ruff check config.py webui\services\config_service.py webui\services\integration_service.py tests\unit\test_config.py tests\unit\test_config_service.py tests\unit\test_integration_service.py tests\integration\test_config_blueprint.py tests\integration\test_webui_static_assets.py
  • python -m pytest --basetemp .tmp\pytest-temp tests\unit\test_config.py tests\unit\test_config_service.py tests\unit\test_integration_service.py tests\integration\test_config_blueprint.py tests\integration\test_webui_static_assets.py (93 passed)

Summary by Sourcery

Add advisory cost warnings for high-cost LightRAG + LivingMemory configurations and surface them across backend APIs, dashboard UI, and documentation.

New Features:

  • Introduce detection of high-cost LightRAG hybrid/mix query mode combined with LivingMemory memory delegation and generate non-blocking cost warnings.
  • Expose configuration cost warnings via the config schema API and integration status API for consumption by the web UI.
  • Display configuration and integration cost warnings in the dashboard settings and integration panels with dedicated warning UI components.

Enhancements:

  • Expand configuration and integration documentation to describe high-cost LightRAG + LivingMemory combinations and recommended lower-cost alternatives.

Tests:

  • Add unit and integration tests covering high-cost configuration detection, API exposure of warnings, and presence of related static assets and UI wiring.

@sourcery-ai

sourcery-ai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds a shared detector for a high-cost LightRAG + LivingMemory configuration and surfaces non-blocking cost warnings through backend validation, config schema/API responses, and the dashboard UI, including expanded docs and tests to cover the new behavior.

Sequence diagram for propagating high-cost config warnings to dashboard UI

sequenceDiagram
    actor User
    participant DashboardUI
    participant ConfigService
    participant IntegrationService
    participant PluginConfig
    participant get_config_cost_warnings

    User->>DashboardUI: open settings page
    DashboardUI->>ConfigService: GET /api/config/schema
    ConfigService->>PluginConfig: to_dict
    ConfigService->>get_config_cost_warnings: get_config_cost_warnings(plugin_config)
    get_config_cost_warnings-->>ConfigService: [LIGHTRAG_LIVINGMEMORY_COST_WARNING]
    ConfigService-->>DashboardUI: schema (groups, config) + warnings
    DashboardUI->>DashboardUI: renderSettings
    DashboardUI->>DashboardUI: renderConfigWarnings

    User->>DashboardUI: open integrations page
    DashboardUI->>IntegrationService: GET /api/integrations/status
    IntegrationService->>get_config_cost_warnings: get_config_cost_warnings(config)
    get_config_cost_warnings-->>IntegrationService: [LIGHTRAG_LIVINGMEMORY_COST_WARNING]
    IntegrationService-->>DashboardUI: settings + dashboards + warnings
    DashboardUI->>DashboardUI: renderIntegrations
    DashboardUI->>DashboardUI: warningListHtml
Loading

File-Level Changes

Change Details Files
Introduce reusable detection and warning helpers for the high-cost LightRAG + LivingMemory configuration and integrate them into config validation and services.
  • Define HIGH_COST_LIGHTRAG_QUERY_MODES, a localized LIGHTRAG_LIVINGMEMORY_COST_WARNING message, and helpers (_read_config_value, _read_config_bool, is_lightrag_livingmemory_high_cost_config, get_config_cost_warnings) to inspect both dict-like and object configs.
  • Hook get_config_cost_warnings into PluginConfig.validate_config so that high-cost combinations add leading-space, non-blocking warning strings to the existing error/warning list.
  • Expose config cost warnings from ConfigService.get_config_schema and IntegrationService.get_status so that API consumers receive a warnings list alongside groups and integration status.
config.py
webui/services/config_service.py
webui/services/integration_service.py
Render backend cost warnings in the dashboard settings and integrations UI with shared warning styling.
  • Add .settings-warning-list and .settings-warning styles for both the legacy dashboard HTML/CSS and the Next-style pages CSS, including light/dark theming.
  • Inject a new configWarnings container in dashboard.html and corresponding settings-warnings and integration-warnings containers in pages/dashboard/index.html.
  • Implement warningListHtml in pages/dashboard/app.js plus renderConfigWarnings / getConfigWarnings JS glue so settings and integration panels render schema.warnings / data.warnings as a warning list labeled '成本提醒'.
  • Wire renderIntegrations and renderSettings to populate the new warning containers from the backend warnings arrays.
web_res/static/html/dashboard.html
pages/dashboard/styles.css
pages/dashboard/app.js
pages/dashboard/index.html
Extend tests and documentation to cover the new high-cost warning behavior end-to-end.
  • Add unit tests for is_lightrag_livingmemory_high_cost_config and get_config_cost_warnings, including hybrid/mix vs local query modes and stringified booleans, and ensure PluginConfig.validate_config surfaces warnings without blocking.
  • Extend ConfigService tests to assert that get_config_schema exposes warnings and enriches LightRAG/LivingMemory field hints, and that update_config returns a warning message when the high-cost combo is set.
  • Extend IntegrationService tests so get_status returns warnings for a high-cost V2 combo, and tweak existing tests to set explicit low-cost defaults.
  • Add integration tests to ensure dashboard assets reference the new warning hooks and schema.warnings plumbing, and update configuration/integration docs to describe the cost implications and advisory nature of the hybrid/mix + LivingMemory setup.
  • Leave _conf_schema.json updated (content not shown) to support the new schema/hints wiring.
tests/unit/test_config.py
tests/unit/test_config_service.py
tests/unit/test_integration_service.py
tests/integration/test_webui_static_assets.py
tests/integration/test_config_blueprint.py
docs/configuration.md
docs/integrations.md
_conf_schema.json

Assessment against linked issues

Issue Objective Addressed Explanation
#198 Add a warning/reminder in the settings when the V2 configuration uses LightRAG with high-cost query modes (hybrid/mix) combined with LivingMemory delegation, to inform users about potentially increased LLM call and token consumption.
#198 Propagate and surface this warning consistently across relevant interfaces and documentation (config validation responses, config schema/API, integration status/settings UI, and configuration/integration docs) so users are clearly informed about the cost impact of this configuration.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="pages/dashboard/app.js" line_range="319-327" />
<code_context>
     }, 3200);
   }

+  function warningListHtml(warnings) {
+    const items = Array.isArray(warnings) ? warnings.filter(Boolean) : [];
+    return items.map((message) => `
+      <div class="settings-warning">
+        <strong>成本提醒</strong>
</code_context>
<issue_to_address>
**suggestion:** Normalize/trim warning messages before rendering for more consistent output and to match other paths.

`warningListHtml` currently only uses `filter(Boolean)` before escaping. In `dashboard.html`'s `getConfigWarnings`, you also coerce to `String` and `trim()` before filtering, which avoids whitespace-only warnings and normalizes spacing. Apply the same `String(message).trim()` step here so SPA and static dashboard warnings are handled consistently and blank/poorly formatted items aren’t rendered.

```suggestion
  function warningListHtml(warnings) {
    const items = Array.isArray(warnings)
      ? warnings
          .map((message) => String(message).trim())
          .filter(Boolean)
      : [];
    return items.map((message) => `
      <div class="settings-warning">
        <strong>成本提醒</strong>
        <span>${escapeHtml(message)}</span>
      </div>
    `).join("");
  }
```
</issue_to_address>

### Comment 2
<location path="tests/integration/test_webui_static_assets.py" line_range="276-285" />
<code_context>
     assert "GET /api/data/overview" in service


+def test_dashboard_exposes_config_cost_warnings():
+    text = (PLUGIN_ROOT / "web_res" / "static" / "html" / "dashboard.html").read_text(encoding="utf-8")
+    app = (PLUGIN_ROOT / "pages" / "dashboard" / "app.js").read_text(encoding="utf-8")
+    service = (PLUGIN_ROOT / "webui" / "services" / "config_service.py").read_text(encoding="utf-8")
+
+    assert "configWarnings" in text
+    assert "settings-warning-list" in text
+    assert "成本提醒" in text
+    assert "warningListHtml" in app
+    assert "schema.warnings" in app
+    assert "get_config_cost_warnings" in service
+
+
</code_context>
<issue_to_address>
**suggestion (testing):** Consider asserting the presence of the new warning containers (`settings-warnings` / `integration-warnings`) to make the dashboard wiring more robust.

Adding assertions for these DOM containers in `dashboard.html` would ensure the warning slots themselves remain intact, not just the JS symbols. This helps detect template changes that remove or rename the containers while leaving the JS references in place.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread pages/dashboard/app.js
Comment on lines +276 to +285
def test_dashboard_exposes_config_cost_warnings():
text = (PLUGIN_ROOT / "web_res" / "static" / "html" / "dashboard.html").read_text(encoding="utf-8")
app = (PLUGIN_ROOT / "pages" / "dashboard" / "app.js").read_text(encoding="utf-8")
service = (PLUGIN_ROOT / "webui" / "services" / "config_service.py").read_text(encoding="utf-8")

assert "configWarnings" in text
assert "settings-warning-list" in text
assert "成本提醒" in text
assert "warningListHtml" in app
assert "schema.warnings" in app

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Consider asserting the presence of the new warning containers (settings-warnings / integration-warnings) to make the dashboard wiring more robust.

Adding assertions for these DOM containers in dashboard.html would ensure the warning slots themselves remain intact, not just the JS symbols. This helps detect template changes that remove or rename the containers while leaving the JS references in place.

@EterUltimate EterUltimate force-pushed the codex/issue-198-cost-warning branch from c068a66 to bd3b286 Compare June 11, 2026 10:16
@EterUltimate EterUltimate merged commit 9d9fe65 into NickCharlie:main Jun 11, 2026
4 checks passed
@EterUltimate EterUltimate deleted the codex/issue-198-cost-warning branch June 18, 2026 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 在v2架构升级配置设置成lightrag+hybrid的话会导致筛选模型调用量和token消耗量剧增.(开启livingmemory了)

1 participant