> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreweave.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Registry

> W&B モデルレジストリを使用して、モデルのバージョンを整理・管理します。

W\&B モデルレジストリを使用して、モデルのバージョンを整理・管理します。

<h2 id="add-a-description-to-a-collection-in-a-registry">
  Registry 内のコレクションに説明を追加する
</h2>

```python theme={"system"}
"""
Add an description to a collection in a registry.
"""
import wandb

# レジストリとコレクションの詳細を定義します
collection_type = "<collection_type>"
registry_name = "<registry_name>"
collection_name = "<collection_name>"

# 完全な Registry パスを作成します
registry_path = f"wandb-registry-{registry_name}/{collection_name}"

# W&B API を初期化します
api = wandb.Api()

# アーティファクト コレクションを取得します
collection = api.artifact_collection(
  type_name = collection_type, 
  name = registry_path
  )

# コレクション オブジェクトに説明のアノテーションを追加します
collection.description = "<description>"

# 更新したコレクションを保存します
collection.save()
```

<h2 id="create-a-new-registry">
  新しい Registry を作成する
</h2>

```python theme={"system"}
"""
Create a new registry in W&B. If the registry does not exist, W&B creates it.
"""
import wandb

# W&B API を初期化します
api = wandb.Api()

# 新しいレジストリを作成します
registry = api.create_registry(
    name="<registry_name>",
    visibility="<visibility>",  # 例: "public" または "private"
)
```

<h2 id="delete-a-registry">
  Registry を削除する
</h2>

```python theme={"system"}
"""
Delete a registry from W&B.
"""
import wandb

# レジストリとコレクションの詳細を定義します
registry_name = "<registry_name>"
collection_name = "<collection_name>"

# 完全な Registry パスを構築します
registry_path = f"wandb-registry-{registry_name}/{collection_name}"

# W&B API を初期化します
api = wandb.Api()

# 削除するレジストリを取得します
fetched_registry = api.registry("<registry_name>")

# レジストリを削除します
fetched_registry.delete()
```

<h2 id="create-an-artifact-and-link-it-to-a-collection-in-a-registry">
  アーティファクトを作成してRegistry内のコレクションにリンクする
</h2>

```python theme={"system"}
"""
Create a W&B artifact and link it to a collection in a registry. If the
collection does not exist, W&B creates it.
"""
import wandb

# アーティファクト オブジェクトを作成します
artifact = wandb.Artifact(name = "<artifact_name>", type = "<artifact_type>")

# レジストリ名とコレクション名を定義します
registry_name = "<registry_name>"
collection_name = "<collection_name>"
target_path = f"wandb-registry-{registry_name}/{collection_name}"

# run を初期化します
with wandb.init(entity = "<entity>", project = "<project>") as run:
  # アーティファクトをコレクションにリンクします。コレクションが存在しない場合は、W&B が作成します。
  run.link_artifact(artifact = artifact, target_path = target_path)
```

<h2 id="retrieve-a-specific-version-of-an-artifact-from-a-registry-collection">
  Registry コレクションからアーティファクトの特定のバージョンを取得する
</h2>

```python theme={"system"}
"""
Retrieve a specific version of an artifact from a registry collection.
"""

import wandb

# レジストリ、コレクション、アーティファクトのバージョンを指定します
registry = "<registry_name>"
collection = "<collection_name>"
version = "<version>"

# バージョンを含む完全なアーティファクト名を作成します
artifact_name = f"wandb-registry-{registry}/{collection}:{version}"

# W&B API を初期化します
api = wandb.Api()

# 指定したレジストリのコレクションとバージョンからアーティファクトを取得します
artifact = api.artifact(name = artifact_name)
```

<h2 id="create-a-registry-collection-and-link-an-artifact-to-it">
  Registry のコレクションを作成してアーティファクトをリンクする
</h2>

```python theme={"system"}
"""
Ceates a registry collection and links an artifact to it.
"""
import wandb

# アーティファクトオブジェクトを作成します
artifact = wandb.Artifact(name = "<artifact_name>", type = "<artifact_type>")

registry_name = "<registry_name>"
collection_name = "<collection_name>"
registry_path = f"wandb-registry-{registry_name}/{collection_name}"

# run を初期化します
with wandb.init(entity = "<entity>", project = "<project>") as run:

  # アーティファクトをコレクションにリンクします。コレクションが存在しない場合は、W&B が自動的に作成します。
  run.link_artifact(artifact = artifact, target_path = registry_path)
```

<h2 id="add-tags-to-a-collection-in-a-registry">
  Registry 内のコレクションにタグを追加する
</h2>

```python theme={"system"}
"""
Add tags to a collection in a registry.
"""
import wandb

# Registry とコレクションの情報を定義
collection_name = "<collection_name>"
collection_type = "<collection_type>"
registry_name = "<registry_name>"

# 完全な Registry パスを組み立てる
registry_path = f"wandb-registry-{registry_name}/{collection_name}"

# アーティファクト コレクションを取得
collection = wandb.Api().artifact_collection(
  type_name = collection_type, 
  name = registry_path
  )

collection.tags = ["<tag>"]
collection.save()
```

<h2 id="remove-a-tag-from-a-collection-in-a-registry">
  Registry内のコレクションからタグを削除する
</h2>

```python theme={"system"}
"""
Remove a tag from a collection in a registry.
"""
import wandb

# レジストリとコレクションの詳細を定義します
collection_name = "<collection_name>"
collection_type = "<collection_type>"
registry_name = "<registry_name>"

# 完全な Registry パスを作成します
registry_path = f"wandb-registry-{registry_name}/{collection_name}"

# アーティファクト コレクションを取得します
collection = wandb.Api().artifact_collection(
  type_name = collection_type, 
  name = registry_path
  )

collection.tags.remove("<tag>")
collection.save()
```
