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

# Get

Retrieves items from the index by ID, with the fields you choose.

```typescript theme={null}
async get({
    ids: string[],
    include?: string[],   // default: ['vector', 'contents', 'metadata']
}): Promise<GetResultItem[]>
```

### Parameters

| Parameter | Type | Default | Description |
| - | - | - | - |
| `ids` | `string[]` | - | IDs of the items to retrieve. |
| `include` | `string[]` | `['vector', 'contents', 'metadata']` | *(Optional)* Fields to return besides `id`. Other values are ignored. |

### Returns

`Promise<GetResultItem[]>`, one object per ID found. IDs that don't exist are left out of the result without an error, and an empty `ids` array returns `[]`. When `include` doesn't contain `'vector'`, an existing item that has none of the requested fields is also left out.

```typescript theme={null}
{
    id: string,         // Always returned
    vector?: number[],  // When 'vector' is in include
    contents?: string,  // When 'contents' is in include; '' if the item has no contents
    metadata?: object,  // When 'metadata' is in include
}
```

`contents` is always a `string`. Contents upserted as bytes come back as their base64 text; decode them with `Buffer.from(contents, 'base64')` on Node, or `atob()` elsewhere.

### Exceptions

<AccordionGroup>
  <Accordion title="CyborgDBAuthenticationError">
    The `indexKey` or `apiKey` is invalid (HTTP `401`).
  </Accordion>

  <Accordion title="CyborgDBServiceError">
    The service returns `5xx`.
  </Accordion>
</AccordionGroup>

See [Errors](../errors) for the full hierarchy.

### Example Usage

```typescript theme={null}
const results = await index.get({ ids: ['doc1', 'doc2', 'missing-id'], include: ['contents', 'metadata'] });

for (const item of results) {
    console.log(item.id, JSON.stringify(item.contents), item.metadata);
}
// Output:
// doc1 "First document" {}
// doc2 "" { category: 'news' }
```

#### Decode bytes contents

```typescript theme={null}
await index.upsert({
    items: [{ id: 'img1', vector: [0.1, 0.2, 0.3, 0.4], contents: new Uint8Array([0x89, 0x50, 0x4e, 0x47]) }],
});

const [item] = await index.get({ ids: ['img1'], include: ['contents'] });
const raw = Buffer.from(item.contents ?? '', 'base64');
console.log(raw);
// Output: <Buffer 89 50 4e 47>
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.