Skip to content

Conversation

@rohansen856
Copy link

Summary

This PR implements pricing information fields and taxonomy relationships for AIAsset models. It adds two new string fields (pricing_info and applies_to) and two many-to-many taxonomy relationships (solution and approach) to all AIAsset subclasses (datasets, ML models, experiments, computational assets, case studies, and publications).

The implementation follows existing patterns in the codebase precisely, using the same structure as the license taxonomy relationship and the creator/contact many-to-many patterns.


Change(s)

Change Type: Added

Change Category: Interface

Changelog Entry:

Added pricing_info, applies_to, solution, and approach fields to AIAsset, enabling assets to specify pricing models, application contexts, solution types, and methodological approaches.

These fields enhance AIAsset metadata with:

  • pricing_info (string): Information about pricing models or cost structures
  • applies_to (string): Context or domain where the asset can be applied
  • solution (list): Solution categories/types that the asset implements (many-to-many taxonomy)
  • approach (list): Methodological approaches/techniques employed by the asset (many-to-many taxonomy)

All fields are available across the 6 AIAsset types: datasets, ML models, experiments, computational assets, case studies, and publications.


Technical Implementation

Files Modified/Created

  1. src/database/model/ai_asset/solution.py

    • New taxonomy model for solution types
    • Uses create_taxonomy factory pattern
    • Supports hierarchical taxonomy structure
  2. src/database/model/ai_asset/approach.py

    • New taxonomy model for methodological approaches
    • Uses create_taxonomy factory pattern
    • Supports hierarchical taxonomy structure
  3. src/database/model/ai_asset/ai_asset.py

    • Added Solution and Approach imports
    • Added pricing_info and applies_to string fields to AIAssetBase
    • Added solution and approach Relationship fields to AIAsset
    • Added RelationshipConfig entries with ManyToMany specifications
    • Updated update_relationships_asset to create link tables
  4. src/tests/routers/resource_routers/test_router_pricing_solution_approach.py

    • Test for pricing_info and applies_to fields (create/update)
    • Test for solution many-to-many relationship
    • Test for approach many-to-many relationship
    • Integration test using all four fields together
  5. alembic/alembic/versions/9k2m4n6p8q0r_add_pricing_applies_solution_approach.py

    • Creates solution and approach taxonomy tables
    • Adds pricing_info and applies_to columns to 6 AIAsset tables
    • Creates 12 link tables (6 for solution, 6 for approach)
    • Includes proper foreign key constraints with CASCADE
    • Adds indexes for query performance
    • Provides complete downgrade function for rollback

Database Changes

New Taxonomy Tables:

solution (
  identifier INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(200) NOT NULL UNIQUE,
  definition TEXT,
  official BOOLEAN,
  parent_identifier INT NULL,
  FOREIGN KEY (parent_identifier) REFERENCES solution(identifier)
)

approach (
  identifier INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(200) NOT NULL UNIQUE,
  definition TEXT,
  official BOOLEAN,
  parent_identifier INT NULL,
  FOREIGN KEY (parent_identifier) REFERENCES approach(identifier)
)

New Columns Added to AIAsset Tables:

  • pricing_info VARCHAR(200) NULL
  • applies_to VARCHAR(200) NULL

Applied to: dataset, ml_model, experiment, computational_asset, case_study, publication

Link Tables Created:

Following the naming pattern: solution_<asset_type>_link and approach_<asset_type>_link

For all 6 AIAsset types: dataset, ml_model, experiment, computational_asset, case_study, publication.

Each table structure:

- from_identifier VARCHAR(30) - FK to asset_type.identifier (CASCADE on delete/update)
- linked_identifier INT - FK to taxonomy.identifier (CASCADE on update, RESTRICT on delete)
- Composite primary key (from_identifier, linked_identifier)
- Indexes on both foreign keys

How to Test

1. Run Database Migration

docker build -f alembic/Dockerfile . -t aiod-migration
docker run -v $(pwd)/alembic:/alembic:ro -v $(pwd)/src:/app -it \
  --network aiod-rest-api_default aiod-migration

2. Verify Database Schema

./scripts/database-connect.sh
SHOW TABLES LIKE 'solution%';  # Should show solution table + 6 link tables
SHOW TABLES LIKE 'approach%';  # Should show approach table + 6 link tables
DESCRIBE dataset;              # Should show pricing_info and applies_to columns
DESCRIBE solution_dataset_link;
EXIT;

3. Run Unit Tests

pytest src/tests/routers/resource_routers/test_router_pricing_solution_approach.py -v
pytest src/tests --versions 'latest'

4. Manual API Testing

# Create solution and approach taxonomy entries
curl -X POST "http://localhost/solutions" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Machine Learning Model",
    "definition": "A trained ML model for prediction tasks",
    "official": true
  }'

curl -X POST "http://localhost/approaches" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Supervised Learning",
    "definition": "Learning with labeled training data",
    "official": true
  }'

# Create a dataset with all new fields
curl -X POST "http://localhost/datasets" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Test Dataset",
    "description": {"plain": "Dataset with pricing info"},
    "aiod_entry": {"status": "published"},
    "platform": "aiod",
    "platform_resource_identifier": "test-ds",
    "pricing_info": "Free for academic use, €50/month for commercial",
    "applies_to": "Computer vision tasks",
    "solution": ["Machine Learning Model"],
    "approach": ["Supervised Learning"]
  }'

# Verify the fields are returned
curl -X GET "http://localhost/datasets/<DATASET_IDENTIFIER>" | jq '{pricing_info, applies_to, solution, approach}'

5. Verify in Swagger UI

  • Navigate to http://localhost/docs
  • Check /datasets POST endpoint shows all 4 new fields in schema
  • Verify pricing_info and applies_to are strings
  • Verify solution and approach are arrays of strings
  • Test creating a resource with all fields populated

Checklist

  • Tests have been added - Comprehensive test coverage in test_router_pricing_solution_approach.py
  • Documentation has been added:
    • Field descriptions in model docstrings
    • Schema examples in Field definitions
    • Test file serves as usage documentation
  • Self-review conducted:
    • Implementation follows existing taxonomy patterns (License, Language, Country)
    • String fields follow existing AIAssetBase field patterns
    • Many-to-many relationships use same pattern as citation
    • Link table creation follows established factory pattern
    • Migration follows structure of existing taxonomy migrations
    • No unintended changes committed
  • Code quality checks pass:
    • ruff format: Passed
    • ruff check: Passed (test directory excluded as per config)
    • pytest collection: All 8 test variants collected successfully
  • Migration verified:
    • Migration file compiles successfully
    • Revision chain is correct (revises from 8f9ac801a283)
    • No conflicts with other migrations
    • All table names verified against actual model tablename attributes
  • PR title matches changelog - "Add pricing, applies, solution and approach to AIAsset"

Related Issues

Closes #589

cc @joaquinvanschoren @mardalla

Copy link
Collaborator

@mardalla mardalla left a comment

Choose a reason for hiding this comment

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

Tested locally, works, approving

@mardalla
Copy link
Collaborator

mardalla commented Dec 2, 2025

I approved the PR, but FYI the pre-commit pytest-check step is currently failing.

The failing tests are:

  • test_example_is_valid[latest-case_study]
  • test_example_is_valid[latest-computational_asset]
  • test_example_is_valid[latest-dataset]
  • test_example_is_valid[latest-experiment]
  • test_example_is_valid[latest-ml_model]
    - test_example_is_valid[latest-publication]

They all return:

The terms {'deep learning', 'supervised learning'} are not part of the taxonomy for approach. Please see the endpoint for the taxonomy to see a list of allowed terms.

So the new approach examples are not consistent with the current taxonomy. CI should go green once either:

  • those terms are added to the approach taxonomy/fixtures, or
  • the approach examples are changed to use existing taxonomy terms.

@rohansen856
Copy link
Author

rohansen856 commented Dec 2, 2025

@mardalla Thanks for the approve and thans for pointing out ht eexamples issue that i overlooked. I double checked and changing the approach examples to this: example=["Deep Learning Theory", "Representation Learning"], would solve the issue with CI (found those in: data/taxonomies/default.json). I will do the change and do a commit.

@rohansen856
Copy link
Author

Done the chnges... pre-commit pytest-check should be passing now...

@mardalla
Copy link
Collaborator

mardalla commented Dec 5, 2025

CI is red due to pytest-check: test_example_is_valid[...] fails because the approach examples ("deep learning theory", "representation learning") are not part of the approach taxonomy. Please align the examples with the taxonomy so the POSTs return 200 instead of 400.

@rohansen856
Copy link
Author

rohansen856 commented Dec 13, 2025

@mardalla i think the issue was with proper case (as i was in my windows it probably passed but not in the CI which is in unix env). I fixed that and pushed a commit. Kindly run the CI and see if its passing now.
I tried it in the docker environment and its passing there too.
Thanks!

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.

AIAsset

2 participants