# Collections
URL: /docs/collections

Schemas, field types, and flags — and the endpoints that manage them.



A collection is created with a name and a list of field definitions. The
schema is fixed at creation time; there is currently no endpoint to modify a
collection's fields after it's created.

```json
{
  "name": "products",
  "fields": [
    { "name": "title", "type": "text" },
    { "name": "brand", "type": "keyword", "facet": true },
    { "name": "price", "type": "int", "filter": true, "sort": true }
  ],
  "default_sorting_field": "price"
}
```

<Tabs items="['cURL', 'TypeScript', 'Python', 'C#']">
  <Tab value="cURL">
    ```bash
    curl -X POST localhost:8108/collections \
      -H 'Content-Type: application/json' \
      -d '{
        "name": "products",
        "fields": [
          {"name": "title", "type": "text"},
          {"name": "brand", "type": "keyword", "facet": true},
          {"name": "price", "type": "int", "filter": true, "sort": true}
        ],
        "default_sorting_field": "price"
      }'
    ```
  </Tab>

  <Tab value="TypeScript">
    ```ts
    import { Tachyon } from 'tachyon-sdk';

    const client = new Tachyon({ url: 'http://localhost:8108' });

    await client.collections.create({
      name: 'products',
      fields: [
        { name: 'title', type: 'text' },
        { name: 'brand', type: 'keyword', facet: true },
        { name: 'price', type: 'int', filter: true, sort: true },
      ],
      default_sorting_field: 'price',
    });
    ```
  </Tab>

  <Tab value="Python">
    ```python
    from tachyon_sdk import Tachyon

    client = Tachyon(url="http://localhost:8108")

    client.collections.create({
        "name": "products",
        "fields": [
            {"name": "title", "type": "text"},
            {"name": "brand", "type": "keyword", "facet": True},
            {"name": "price", "type": "int", "filter": True, "sort": True},
        ],
        "default_sorting_field": "price",
    })
    ```
  </Tab>

  <Tab value="C#">
    ```csharp
    using Tachyon.Sdk;

    var client = new TachyonClient(new TachyonClientOptions { Url = "http://localhost:8108" });

    await client.Collections.CreateAsync(new CollectionSchema
    {
        Name = "products",
        Fields =
        [
            new FieldSchema { Name = "title", Type = FieldType.Text },
            new FieldSchema { Name = "brand", Type = FieldType.Keyword, Facet = true },
            new FieldSchema { Name = "price", Type = FieldType.Int, Filter = true, Sort = true },
        ],
        DefaultSortingField = "price",
    });
    ```
  </Tab>
</Tabs>

## Field types [#field-types]

| Type      | Description                                                   |
| --------- | ------------------------------------------------------------- |
| `text`    | Tokenized, full-text searchable                               |
| `keyword` | Exact-value string, not tokenized — good for `filter`/`facet` |
| `int`     | Whole number                                                  |
| `float`   | Floating-point number                                         |
| `bool`    | `true` / `false`                                              |
| `date`    | Date/time value                                               |

There is no array/multi-value type name — a field's cardinality is inferred
from the values you index into it.

## Field flags [#field-flags]

Every flag defaults to `false` except `index` and `optional`, which default
to `true`.

| Flag       | Default | Effect                                              |
| ---------- | ------- | --------------------------------------------------- |
| `facet`    | `false` | Field can be passed to the `facet` search parameter |
| `filter`   | `false` | Field can be used in a `filter` expression          |
| `sort`     | `false` | Field can be used in the `sort` parameter           |
| `index`    | `true`  | Field is indexed for full-text search               |
| `optional` | `true`  | Documents may omit this field                       |
| `boost`    | —       | Optional per-field relevance multiplier (float)     |

A field must be declared with `filter: true`, `facet: true`, or `sort: true`
to be usable that way — using an undeclared field in a filter, sort, or facet
parameter returns a `400 invalid_query` error.

## Typo tolerance and default sort [#typo-tolerance-and-default-sort]

`typo_tolerance` and `default_sorting_field` are set per collection at
creation time:

* `typo_tolerance` — see [Typo Tolerance](/docs/typo-tolerance) for the full
  config shape.
* `default_sorting_field` — used to break ties, or as the sort order when a
  search doesn't specify `sort` explicitly.

## Managing collections [#managing-collections]

| Method   | Endpoint              | Description                           |
| -------- | --------------------- | ------------------------------------- |
| `POST`   | `/collections`        | Create a collection                   |
| `GET`    | `/collections`        | List all collections                  |
| `GET`    | `/collections/{name}` | Get one collection's schema and stats |
| `DELETE` | `/collections/{name}` | Delete a collection and its data      |

`GET`/`POST` responses include `num_documents` and `num_segments` alongside
the schema. Full parameter and response details: [API Reference → Collections](/api/collections).

<Tabs items="['cURL', 'TypeScript', 'Python', 'C#']">
  <Tab value="cURL">
    ```bash
    curl localhost:8108/collections
    curl localhost:8108/collections/products
    curl -X DELETE localhost:8108/collections/products
    ```
  </Tab>

  <Tab value="TypeScript">
    ```ts
    import { Tachyon } from 'tachyon-sdk';

    const client = new Tachyon({ url: 'http://localhost:8108' });

    const all = await client.collections.list();
    const one = await client.collections.retrieve('products');
    await client.collections.delete('products');
    ```
  </Tab>

  <Tab value="Python">
    ```python
    from tachyon_sdk import Tachyon

    client = Tachyon(url="http://localhost:8108")

    all_collections = client.collections.list()
    one = client.collections.retrieve("products")
    client.collections.delete("products")
    ```
  </Tab>

  <Tab value="C#">
    ```csharp
    using Tachyon.Sdk;

    var client = new TachyonClient(new TachyonClientOptions { Url = "http://localhost:8108" });

    var all = await client.Collections.ListAsync();
    var one = await client.Collections.RetrieveAsync("products");
    await client.Collections.DeleteAsync("products");
    ```
  </Tab>
</Tabs>
