# Metrics

> USearch for C

### Dense Indexes

A dense index holds fixed-width vectors under one metric, with the `dimensions`, `quantization`, `connectivity` and `values_per_key` its constructor froze.

`#include <usearch/dense_index.h>`

`#include <usearch/geospatial_index.h>`

`#include <usearch/sequence_index.h>`

`#include <usearch/shapes_index.h>`

`#include <usearch/types.h>`

## usearch_dense_index_t

Vector Search Index over equidimensional dense representations.

```c
typedef struct usearch_dense_index_handle_t * usearch_dense_index_t;
```

See also: [usearch_dense_init_ram](https://www.unum.cloud/docs/usearch/c/residency.md#usearch_dense_init_ram)

See also: [usearch_dense_insert](https://www.unum.cloud/docs/usearch/c/inputs-and-outputs.md#usearch_dense_insert)

See also: [usearch_dense_search](https://www.unum.cloud/docs/usearch/c/inputs-and-outputs.md#usearch_dense_search)

## usearch_dense_metric_t

The dense metric kinds supported out of the box, with SIMD kernels dispatched by the machine's capabilities.

```c
enum usearch_dense_metric_t
```

The last two read their vectors as [`usearch_scalar_u1x8_k`](https://www.unum.cloud/docs/usearch/c/inputs-and-outputs.md#usearch_scalar_u1x8_k) bit sets and refuse any other quantization; the first four refuse that one.

- `usearch_dense_metric_unknown_k` = `0`: No kind named - an unset field, refused by every constructor.
- `usearch_dense_metric_inner_k` = `1`: Sum of elementwise products, unnormalized and scale-sensitive; the only kind the linear-algebra verbs accept, since a product and a softmax both need logits rather than distances.
- `usearch_dense_metric_angular_k` = `2`: Cosine distance in [0, 2], zero for identical directions and blind to magnitude, which is precomputed once per vector at insertion rather than per comparison.
- `usearch_dense_metric_euclidean_k` = `3`: L2 distance, non-negative and zero only for identical vectors - the scale-sensitive counterpart to angular, where a doubled vector is far from its original rather than identical to it.
- `usearch_dense_metric_hamming_k` = `4`: Count of differing bits, so its range is the dimensionality and every bit weighs the same.
- `usearch_dense_metric_jaccard_k` = `5`: Differing bits over union bits in [0, 1], ignoring the zeros both vectors share - the kind for sparse sets, where Hamming would call two nearly-empty vectors identical.

Spellings: ```
char const * usearch_dense_metric_name(usearch_dense_metric_t metric);
```

```
usearch_dense_metric_t usearch_dense_metric_from_name(
    usearch_bytes_view_t name);
```

## usearch_geospatial_index_t

Similarity Search Index over observations in space & time.

```c
typedef struct usearch_geospatial_index_handle_t * usearch_geospatial_index_t;
```

## usearch_sequence_index_t

Similarity Search Index over variable-length sequences.

```c
typedef struct usearch_sequence_index_handle_t * usearch_sequence_index_t;
```

See also: [usearch_sequence_init_ram](https://www.unum.cloud/docs/usearch/c/residency.md#usearch_sequence_init_ram)

See also: [usearch_sequence_insert](https://www.unum.cloud/docs/usearch/c/inputs-and-outputs.md#usearch_sequence_insert)

See also: [usearch_sequence_search](https://www.unum.cloud/docs/usearch/c/inputs-and-outputs.md#usearch_sequence_search)

## usearch_sequence_metric_t

The sequence scoring kinds supported out of the box.

```c
enum usearch_sequence_metric_t
```

The edit kinds fill a ____[|a|+1,|b|+1] table of cell `D`[i,j], the least cost of turning the prefix of `a` ending at `i` into the prefix of `b` ending at `j`, carrying one row, so each is quadratic in time. They write `c` for the substitution cost and `g` for the gap cost.

- `usearch_sequence_metric_unknown_k` = `0`
- `usearch_sequence_metric_levenshtein_bytes_k` = `1`: Levenshtein edit distance over raw bytes.
- `usearch_sequence_metric_levenshtein_utf8_k` = `2`: Levenshtein edit distance over UTF-8 code points.
- `usearch_sequence_metric_needleman_wunsch_k` = `3`: Global alignment with linear gap costs - Needleman-Wunsch.
- `usearch_sequence_metric_overlap_k` = `4`: Window overlap: the share of the larger window set the other side misses.

Spellings: ```
char const * usearch_sequence_metric_name(
    usearch_sequence_metric_t metric);
```

```
usearch_sequence_metric_t usearch_sequence_metric_from_name(
    usearch_bytes_view_t name);
```

## usearch_sequence_weights_t

The substitution matrix and gap costs an alignment kind scores with; the Levenshtein kinds score with unit costs and take none.

```c
struct usearch_sequence_weights_t
```

Needleman-Wunsch reads the matrix as similarities `s` between class codes, the classes ending at the last code scoring anything, at most 32 of them, and its sequences as those codes packed two bits apiece up to four classes and five past, little-endian behind one byte counting the slots the last bytes leave unused. It scores with `c(a,b)` = (s(a,a) + s(b,b)) / 2 − s(a,b), costs that must not be negative, rounded to integers of at most 15 together with the gap cost, all scaled down by one factor when either passes it.

- `substitution_matrix` `int8_t const *`: Row-major 256×256 signed scores over byte alphabets.
- `gap` `int8_t`: Cost of one unaligned symbol.

## usearch_shapes_index_t

Similarity Search Index over 3D point clouds of varying size.

```c
typedef struct usearch_shapes_index_handle_t * usearch_shapes_index_t;
```

See also: [usearch_shapes_init_ram](https://www.unum.cloud/docs/usearch/c/residency.md#usearch_shapes_init_ram)

See also: [usearch_shapes_insert](https://www.unum.cloud/docs/usearch/c/inputs-and-outputs.md#usearch_shapes_insert)

See also: [usearch_shapes_search](https://www.unum.cloud/docs/usearch/c/inputs-and-outputs.md#usearch_shapes_search)

## usearch_shapes_metric_t

How two shapes compare, with no correspondence between their points.

```c
enum usearch_shapes_metric_t
```

Writes `d` for the distance between two points, `S` for one of the eight sign flips __diag__(±1,±1,±1), and `P` for a transport plan: a non-negative ____[|A|,|B|] matrix whose rows sum to `1/|A|` and columns to `1/|B|`. Both shapes are taken as already centred and turned onto their principal axes, as the index stores them. Scoring Kinds

- `usearch_shapes_metric_unknown_k` = `0`
- `usearch_shapes_metric_chamfer_k` = `1`: Mean distance to each point's nearest partner, both directions, halved.
- `usearch_shapes_metric_hausdorff_k` = `2`: The worst of all nearest-partner distances, both directions.
- `usearch_shapes_metric_gromov_wasserstein_k` = `3`: Transport over each side's internal geometry - the best ranker, and the costliest.
- `usearch_shapes_metric_wasserstein_procrustes_k` = `4`: Residual after the best rigid motion and the best matching - Wasserstein-Procrustes.

Spellings: ```
char const * usearch_shapes_metric_name(usearch_shapes_metric_t metric);
```

```
usearch_shapes_metric_t usearch_shapes_metric_from_name(
    usearch_bytes_view_t name);
```

## usearch_distance_t

Distance or similarity score between two entries, in the metric of the index that produced it.

```c
typedef double usearch_distance_t;
```

Wide enough for every modality's scoring range.

