Read-only mirror of https://github.com/StatistikStadtZuerich/MeLODy-2 — Stadt Zürich. Issues & pull requests at the source.
  • Kotlin 51%
  • Vue 30.3%
  • JavaScript 13.5%
  • HTML 4.1%
  • CSS 0.8%
  • Other 0.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Thomas Kurz (thomas.kurz@redlink.at) d1b59593c9 Merge branch 'feature/admin-full-refresh' into 'main'
fix smaller issues with search index builder and set mcp to stateless protocol

See merge request OE-7035/ssz-lod/melody-2.0!22
2026-07-31 08:02:35 +00:00
.devcontainer Move hardcoded agent constants to configuration 2026-02-10 19:26:01 +01:00
backend fix smaller issues with search index builder and set mcp to stateless protocol 2026-07-30 13:56:47 +02:00
demo add demo usecase (+ data) 2025-11-24 10:33:23 +01:00
gradle/wrapper Remove python-docker-runner module and all associated files, configurations, dependencies, and IntelliJ settings. 2025-07-03 07:31:17 +02:00
minimal-chat fix(logs): show first-request info logs reliably after page reload 2026-07-24 16:06:15 +02:00
testing Add test protocol for meLODy 2.0.0-rc.13 2026-07-07 16:13:31 +02:00
.dockerignore Clean up Dockerfile and update .dockerignore 2025-07-14 14:36:51 +02:00
.gitattributes - Refactor API methods to improve error handling and streamline response processing 2025-11-07 08:48:46 +01:00
.gitignore improve routing and model selection, set beta label 2025-11-06 15:07:54 +01:00
.gitlab-ci.yml ci(lfs): skip LFS smudge in CI and move all-MiniLM fixture out of prod jar 2026-07-23 15:37:39 +02:00
ARCHITECTURE.md Add comprehensive backend architecture documentation 2026-01-28 16:34:35 +01:00
CLAUDE.md Document admin dashboard in README and CLAUDE.md 2026-02-10 19:48:53 +01:00
docker-compose.yaml feat(docker): add MCP inspector service 2026-07-17 09:10:06 +02:00
Dockerfile fix(ci): add conditional dry-run and update proxy vars for image build 2026-02-25 12:51:30 +01:00
LICENSE add(licensing): include Apache License 2.0 and update README with license information 2026-06-24 16:53:44 +02:00
README.md add(licensing): include Apache License 2.0 and update README with license information 2026-06-24 16:53:44 +02:00
TODO.md Implement token usage quota system with session, daily, and monthly limits 2026-02-10 19:04:52 +01:00

MeLODy 2.0

Project Summary

MeLODy is an AI-powered chatbot for Linked Data Cubes that allows users to ask natural-language questions about statistical data and receive data-driven answers (text, tables, charts). A core principle of MeLODy is transparency: every answer references its underlying data sources, and data can be combined across multiple providers (e.g. City of Zurich, Canton of St. Gallen).

Background & Project Status

  • MeLODy 1.x started as a prototype based on a Custom GPT to evaluate whether a chatbot built on Linked Data statistics is feasible. The initial focus was on data from the City of Zurich.
  • MeLODy 2.0 has been under development since September 2025. It runs independently of ChatGPT, is deployed on its own infrastructure, and is no longer limited to a single data provider. The current status is beta.
  • The application is accessible via a web interface and can be used without registration.

Key Characteristics

  • MeLODy consistently leverages the semantics of Linked Data: datasets are uniquely identified via URIs and modeled as triples.
  • This enables the system to determine which indicators are truly comparable (same definition, same semantics) and to explicitly flag cases where comparisons are not valid.
  • Answers are transparent and reproducible, as they are derived directly from structured data.

Technical Concept (High Level)

MeLODy 2.0 is designed as an agentic system:

  • An LLM acts as an orchestrator/router that analyzes user queries, invokes tools, and aggregates results.
  • A Cube Index supports discovery of relevant Linked Data Cubes based on the cube.link schema.
  • A SPARQL Requester generates and executes SPARQL queries against external endpoints and returns structured results (e.g. tables).
  • An Interpreter/Renderer processes query results, performs calculations or aggregations, and produces textual or visual output.

In contrast, MeLODy 1.x was tightly coupled to the constraints of Custom GPTs, with limited control over routing, data access, and scalability.

Data Requirements & Onboarding for New Providers

To integrate new data sources into MeLODy, the following conditions must be met:

  • Data is published as Linked Data and follows the cube.link schema.
  • Cubes are described using SHACL shapes and include an explicit time dimension.
  • Data is provided via a performant SPARQL endpoint that supports real-time queries.
  • For onboarding, the SPARQL endpoint and relevant Cube IDs are supplied; after a quality check, the data can be integrated.

Lessons Learned

  • Agentic AI systems require iterative development and involve significant trial and error.
  • Large data volumes must be offloaded; a single LLM context is insufficient.
  • Too many tools increase system complexity—complex workflows should be encapsulated in clearly defined agents or modules.
  • The focus shifts from pure intent recognition toward data flows and clean process design.

Admin Dashboard

MeLODy 2.0 includes a comprehensive admin dashboard for monitoring token usage, costs, and quota consumption in real-time.

Access

Dashboard URL: http://localhost:8080/admin/dashboard

Authentication: HTTP Basic Auth (credentials from environment variables)

# Set credentials in environment
export USER_NAME=admin
export USER_PASSWORD=your-secure-password

# Or use existing credentials from your .env file

Features

The dashboard provides:

📊 Current Usage Statistics

  • Daily, monthly, and overall token usage
  • Cost tracking in CHF
  • Request counts
  • Quota usage with visual progress bars (green/yellow/red)

📈 Usage History

  • 30-day usage trend chart
  • Cost breakdown by period (today, yesterday, week, month)
  • Historical data for capacity planning

🔄 Session Monitoring

  • Active sessions list
  • Per-session token usage and costs
  • Session activity status

💰 Cost Analysis

  • Breakdown by token type (input/output/cached)
  • Average cost per request
  • Comparison across time periods

REST API

Programmatic access to usage statistics:

# Current usage (daily, monthly, overall)
curl -u admin:password http://localhost:8080/api/admin/quotas/usage/current

# Historical usage (last 30 days)
curl -u admin:password http://localhost:8080/api/admin/quotas/usage/history?days=30

# Active sessions
curl -u admin:password http://localhost:8080/api/admin/quotas/sessions?limit=20

# Cost breakdown
curl -u admin:password http://localhost:8080/api/admin/quotas/costs

Quota Configuration

Token quotas are configured in application.yml:

agent:
  quotas:
    session:
      max-tokens: 100000      # 100k tokens per hour
      max-price-chf: 5.0
    daily:
      max-tokens: 500000      # 500k tokens per day
      max-price-chf: 25.0
    monthly:
      max-tokens: 5000000     # 5M tokens per month
      max-price-chf: 500.0

When quotas are exceeded, requests are rejected with German error messages explaining when to retry.


Architecture

See ARCHITECTURE.md for details.

Development

License

This project is licensed under the Apache License 2.0 (Apache-2.0). See the LICENSE file for details.