# CMS.INITBYPROB

> Create a Count-min sketch sized for a chosen error and probability.

URL: https://docs.hotkv.com/commands/cms-initbyprob/

```
CMS.INITBYPROB key error probability
```

- Group: Count-min sketch
- Complexity: O(1)
- HotKV Cloud: all plans
- On-Premise: no license needed

`CMS.INITBYPROB` creates an empty Count-min sketch at `key`, sized so that an
estimate overcounts by more than `error` times the total of all increments
only with a chance of `probability`.

For example, `error` 0.001 and `probability` 0.01 mean: with 99% certainty,
an item's estimate is at most its true count plus 0.1% of everything counted.

The server derives the sketch's width and depth from these values, the same
way RedisBloom does. [CMS.INFO](https://docs.hotkv.com/commands/cms-info/index.md) shows the result.

## Arguments

| Argument | Meaning |
| --- | --- |
| `error` | Allowed overcount, as a fraction of the total count. Between 0 and 1, exclusive. |
| `probability` | Chance of exceeding that overcount. Between 0 and 1, exclusive. |

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Created | Simple string `OK` | Simple string `OK` |

Error replies:

- `CMS: key already exists` if the key exists (with any type).
- `CMS: invalid overestimation value` and `CMS: invalid prob value` for values outside (0, 1).
- `CMS: Insufficient memory to create the key` when the sketch would not fit in memory.

## Examples

```
127.0.0.1:6379> CMS.INITBYPROB searches 0.001 0.01
OK
127.0.0.1:6379> CMS.INFO searches
1) width
2) (integer) 2000
3) depth
4) (integer) 7
5) count
6) (integer) 0
127.0.0.1:6379> CMS.INITBYPROB other 0 0.01
(error) CMS: invalid overestimation value
```

## Compatibility

Same as `CMS.INITBYPROB` in RedisBloom, with the same dimensions for the same
arguments.

## See also

[CMS.INITBYDIM](https://docs.hotkv.com/commands/cms-initbydim/index.md), [CMS.INCRBY](https://docs.hotkv.com/commands/cms-incrby/index.md), [CMS.INFO](https://docs.hotkv.com/commands/cms-info/index.md)