# Documents
URL: /docs/documents

Indexing, fetching, and deleting individual documents.



Documents are plain, flat JSON objects — there's no envelope or wrapper
around them. `id` is implicit: every document has one, but it's never
declared as a schema field, and field names starting with `_` are reserved.

## Indexing [#indexing]

`POST /collections/{name}/documents` accepts either a single document object
or a JSON array of documents, indexed as one batch:

<Tabs items="['cURL', 'TypeScript', 'Python', 'C#']">
  <Tab value="cURL">
    ```bash
    curl -X POST localhost:8108/collections/products/documents \
      -H 'Content-Type: application/json' \
      -d '[
        {"id": "1", "title": "Wireless Mouse", "brand": "Logitech", "price": 2999},
        {"id": "2", "title": "Mechanical Keyboard", "brand": "Razer", "price": 8999}
      ]'
    ```
  </Tab>

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

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

    await client.collection('products').documents.index([
      { id: '1', title: 'Wireless Mouse', brand: 'Logitech', price: 2999 },
      { id: '2', title: 'Mechanical Keyboard', brand: 'Razer', price: 8999 },
    ]);
    ```
  </Tab>

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

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

    client.collection("products").documents.index([
        {"id": "1", "title": "Wireless Mouse", "brand": "Logitech", "price": 2999},
        {"id": "2", "title": "Mechanical Keyboard", "brand": "Razer", "price": 8999},
    ])
    ```
  </Tab>

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

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

    await client.Collection("products").Documents.IndexAsync(
        new Document { ["id"] = "1", ["title"] = "Wireless Mouse", ["brand"] = "Logitech", ["price"] = 2999 },
        new Document { ["id"] = "2", ["title"] = "Mechanical Keyboard", ["brand"] = "Razer", ["price"] = 8999 });
    ```
  </Tab>
</Tabs>

Each document in a batch is indexed independently — one invalid document
doesn't fail the rest of the batch. The response reports per-document
outcomes:

```json
{
  "num_indexed": 2,
  "num_failed": 0,
  "results": [
    { "success": true, "id": "1", "error": null, "code": null },
    { "success": true, "id": "2", "error": null, "code": null }
  ]
}
```

Indexing the same `id` again replaces the existing document.

## Fetching and deleting [#fetching-and-deleting]

| Method   | Endpoint                             | Description              |
| -------- | ------------------------------------ | ------------------------ |
| `GET`    | `/collections/{name}/documents/{id}` | Fetch a single document  |
| `DELETE` | `/collections/{name}/documents/{id}` | Delete a single document |

Deletes take effect immediately for subsequent searches, though the
underlying segment data is only physically reclaimed on the next merge — see
[Persistence](/docs/persistence).

Full request/response shapes: [API Reference → Documents](/api/documents).

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

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

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

    const doc = await client.collection('products').documents.retrieve('1');
    await client.collection('products').documents.delete('1');
    ```
  </Tab>

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

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

    doc = client.collection("products").documents.retrieve("1")
    client.collection("products").documents.delete("1")
    ```
  </Tab>

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

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

    var collection = client.Collection("products");
    var doc = await collection.Documents.RetrieveAsync("1");
    await collection.Documents.DeleteAsync("1");
    ```
  </Tab>
</Tabs>
