# `BB.Inference.Artefact.Placement`
[🔗](https://github.com/beam-bots/bb_inference/blob/main/lib/bb/inference/artefact/placement.ex#L5)

Fetches model artefacts and places them under a `priv` directory. Used by
`Mix.Tasks.Compile.BbInference`, which supplies the directories.

## The cache

URL sources are downloaded once into a cache outside the project, keyed by
the URL's own SHA-256, and reused by every project and every build that
declares the same URL. An archive is cached whole and the member extracted
from it each time it is placed.

## Outcomes

- **Placed** - the artefact is in `priv` and, where a `sha256` is declared,
  matches it.
- **Warning** - the download failed. Nothing is placed and nothing is
  recorded, so the next build tries again.
- **Error** - the artefact doesn't match its declared `sha256`, the local
  source doesn't exist, or the archive doesn't contain the member. A
  download that doesn't match is deleted from the cache, so the next build
  downloads it again rather than failing on the same bytes.

## Not re-hashing

The manifest records, for each placed artefact, what was declared and the
size and modification time of the file placed. An artefact whose
declaration and file are both unchanged is not hashed again.

# `artefact`

```elixir
@type artefact() :: %{
  model: atom(),
  source: String.t(),
  archive_member: String.t() | nil,
  sha256: String.t() | nil,
  path: Path.t()
}
```

# `diagnostic`

```elixir
@type diagnostic() :: {:warning | :error, String.t()}
```

# `manifest`

```elixir
@type manifest() :: %{required(Path.t()) =&gt; term()}
```

# `options`

```elixir
@type options() :: [
  priv_dir: Path.t(),
  cache_dir: Path.t(),
  manifest: manifest(),
  info: (String.t() -&gt; any())
]
```

# `place_all`

```elixir
@spec place_all([{module(), artefact()}], options()) :: {[diagnostic()], manifest()}
```

Place every artefact, returning what was said about each and the new
manifest.

Files under `priv_dir` that the old manifest placed and that no artefact
now declares are removed.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
