Skip to content

Add search to Model registry

Eduardo Bonet requested to merge model_registry/search_box into master

What does this MR do and why?

Add search to Model registry

Adds component SearchBar, that fetches search terms from the url and populates a RegistrySearch. Implements searching and ordering on ModelFinder

Changelog: added

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After
image image

How to set up and validate locally

  1. On rails console, enable the feature flag and create some data

    Feature.enable("model_registry")
    p = Project.find_by(id: 20) # or whatever project you want to use for testing
    3.times { |i|  Ml::FindOrCreateModelService.new(p, "model_#{i}").execute }
    
    Ml::FindOrCreateModelVersionService.new(p, { model_name: "model_1", version: "1.0.0" }).execute
    3.times { |i| Ml::FindOrCreateModelVersionService.new(p, { model_name: "model_2", version: "1.2.#{i}" }).execute }
  2. Navigate to /-/ml/models

Database

By name:

SELECT
    ml_models.*,
    count(ml_model_versions.id) AS version_count
FROM
    "ml_models"
    LEFT OUTER JOIN "ml_model_versions" ON "ml_model_versions"."model_id" = "ml_models"."id"
WHERE
    "ml_models"."project_id" = 20
    AND (ml_models.name LIKE '%model\_%')
GROUP BY
    "ml_models"."id"
ORDER BY
    LOWER("ml_models"."name") ASC,
    "ml_models"."id" DESC
LIMIT 21

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/23032/commands/74161

Local explain with more data:

Sort  (cost=7.09..7.10 rows=1 width=104) (actual time=0.146..0.148 rows=3 loops=1)
"  Sort Key: (lower(ml_models.name)), ml_models.id DESC"
  Sort Method: quicksort  Memory: 25kB
  ->  GroupAggregate  (cost=7.06..7.08 rows=1 width=104) (actual time=0.105..0.109 rows=3 loops=1)
        Group Key: ml_models.id
        ->  Sort  (cost=7.06..7.07 rows=1 width=72) (actual time=0.096..0.098 rows=5 loops=1)
              Sort Key: ml_models.id DESC
              Sort Method: quicksort  Memory: 25kB
              ->  Hash Right Join  (cost=5.24..7.05 rows=1 width=72) (actual time=0.079..0.086 rows=5 loops=1)
                    Hash Cond: (ml_model_versions.model_id = ml_models.id)
                    ->  Seq Scan on ml_model_versions  (cost=0.00..1.64 rows=64 width=16) (actual time=0.012..0.018 rows=68 loops=1)
                    ->  Hash  (cost=5.23..5.23 rows=1 width=64) (actual time=0.038..0.039 rows=3 loops=1)
                          Buckets: 1024  Batches: 1  Memory Usage: 9kB
                          ->  Index Scan using index_ml_models_on_project_id_and_name on ml_models  (cost=0.15..5.23 rows=1 width=64) (actual time=0.028..0.030 rows=3 loops=1)
                                Index Cond: (project_id = 20)
                                Filter: (name ~~ '%model\_%'::text)
Planning Time: 4.808 ms
Execution Time: 0.246 ms

By created_at:

SELECT
    ml_models.*,
    count(ml_model_versions.id) AS version_count
FROM
    "ml_models"
    LEFT OUTER JOIN "ml_model_versions" ON "ml_model_versions"."model_id" = "ml_models"."id"
WHERE
    "ml_models"."project_id" = 20
    AND (ml_models.name LIKE '%model\_%')
GROUP BY
    "ml_models"."id"
ORDER BY
    "ml_models"."created_at" ASC,
    "ml_models"."id" DESC
LIMIT 21

https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/23032/commands/74160

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Merge request reports