# Images

Methods on image datasets accept either image URLs for publically accessible images or image objects for images stored in the filesystem. The maximum image size for locally stored images is 200kB. The transformation from images to vectors is done internally and your application doesn't have to worry about it.

{% hint style="info" %}
Recommended image size is 224x224px. Larger images can cause latency issues while smaller images can hurt the search performance.
{% endhint %}

### Create a Dataset

Create a dataset with `Image` type which tells AnnDB to embed your images and queries to vector representations.

![](https://1514770980-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MBjJDID-9E2lsbXx9on%2F-MYkCJb7wNKAGTLUtvyn%2F-MYkC_PlcCBidy8TmRGq%2Fimage.png?alt=media\&token=41f086c8-5ed5-44f0-9e1e-c74498aa9da0)

In order to manage images in your dataset, create a corresponding dataset instance using the client.

{% tabs %}
{% tab title="Python" %}

```python
dataset = client.images('<DATASET_NAME>')
```

Python client accepts either image URLs or `PIL.Image.Image` objects as images.
{% endtab %}

{% tab title="Ruby" %}

```ruby
dataset = client.images("<DATASET_NAME>")
```

Ruby client accepts either image URLs or image byte arrays as images. To obtain a byte array from `MiniMagick::Image` use `.to_blob`.
{% endtab %}
{% endtabs %}

### Search using images

{% tabs %}
{% tab title="Python" %}

```python
result = dataset.search(img, 10)

for item in result:
    print(item.id, item.metadata)
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
result = dataset.search(img, 10)

result.each do |item|
    puts item.id, item.metadata
end
```

{% endtab %}
{% endtabs %}

### Search using natural language

{% tabs %}
{% tab title="Python" %}

```python
result = dataset.search('cute puppy', 10)

for item in result:
    print(item.id, item.metadata)
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
result = dataset.search("cute puppy", 10)

result.each do |item|
    puts item.id, item.metadata
end
```

{% endtab %}
{% endtabs %}

### Insert

{% tabs %}
{% tab title="Python" %}

```python
# Single image
id = dataset.insert(img, metadata={'key': 'value'})
```

```python
# Batch
result = dataset.insert_batch([
    anndb_api.ImageItem(None, img, {'key': 'value'}),
    ...
])

for r in result:
    print(r.id, r.error)
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
id = dataset.insert(img, metadata={ "key": "value" })
```

```ruby
result = dataset.insert_batch([
    {
        image: img.to_blob,
        metadata: { "key": "value" }
    },
    ...
])

result.each { |r|
    puts r[:id], r[:error]
}
```

{% endtab %}
{% endtabs %}

### Update

{% tabs %}
{% tab title="Python" %}

```python
# Single image
id = dataset.update(id, img, metadata={'key': 'value'})
```

```python
# Batch
result = dataset.update_batch([
    anndb_api.ImageItem(id, img, {'key': 'value'}),
    ...
])

for r in result:
    print(r.id, r.error)
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
id = dataset.update(id, img, metadata={ "key": "value" })
```

```ruby
result = dataset.update_batch([
    {
        id: id,
        image: "https://my.domain/img.jpg",
        metadata: { "key": "value" }
    },
    ...
])

result.each { |r|
    puts r[:id], r[:error]
}
```

{% endtab %}
{% endtabs %}

### Delete

{% tabs %}
{% tab title="Python" %}

```python
# Single image
dataset.delete(id)
```

```python
# Batch
result = dataset.delete_batch([id, ...])

for r in result:
    print(r.id, r.error)
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
dataset.delete(id)
```

```ruby
result = dataset.delete_batch([id, ...])

result.each { |r|
    puts r[:id], r[:error]
}
```

{% endtab %}
{% endtabs %}
