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

# Create a variant flag

> Add an experiment with named variants and read it with getVariant.

## Overview

Fieldkit is A/B testing search: `control`, `semantic`, `hybrid`. A variant flag (experiment / multivariate flag) makes those names type-safe.

## Steps

<Steps>
  <Step title="Define it">
    ```ts theme={null}
    "search-variant": {
      type: "variant",
      variants: ["control", "semantic", "hybrid"] as const,
      default: "control",
      description: "Search ranking experiment",
      tags: ["search", "experiment"],
    },
    ```

    `default` must be one of `variants`. Drop `as const` and the union widens to `string`.
  </Step>

  <Step title="Push">
    ```bash theme={null}
    shipd push --project web-app --env production --yes
    ```
  </Step>

  <Step title="Evaluate">
    ```ts theme={null}
    const variant = shipd.getVariant("search-variant", { userId: "usr_8f2k19" });

    switch (variant) {
      case "semantic":
        return semanticSearch(query);
      case "hybrid":
        return hybridSearch(query);
      default:
        return controlSearch(query);
    }
    ```

    ```tsx theme={null}
    const variant = useVariant("search-variant");
    ```
  </Step>
</Steps>

CLI:

```bash theme={null}
shipd flags create --key search-variant --type variant --variants control,semantic,hybrid
```

`--variants` is required for `--type variant`. Repeat the flag or pass a comma list.

Split traffic in the dashboard with a weighted serve — not in `shipd.config.ts`.
