AnnDB
Search
K

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.
Recommended image size is 224x224px. Larger images can cause latency issues while smaller images can hurt the search performance.

Create a Dataset

Create a dataset with Image type which tells AnnDB to embed your images and queries to vector representations.
In order to manage images in your dataset, create a corresponding dataset instance using the client.
Python
Ruby
dataset = client.images('<DATASET_NAME>')
Python client accepts either image URLs or PIL.Image.Image objects as images.
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.

Search using images

Python
Ruby
result = dataset.search(img, 10)
for item in result:
print(item.id, item.metadata)
result = dataset.search(img, 10)
result.each do |item|
puts item.id, item.metadata
end

Search using natural language

Python
Ruby
result = dataset.search('cute puppy', 10)
for item in result:
print(item.id, item.metadata)
result = dataset.search("cute puppy", 10)
result.each do |item|
puts item.id, item.metadata
end

Insert

Python
Ruby
# Single image
id = dataset.insert(img, metadata={'key': 'value'})
# Batch
result = dataset.insert_batch([
anndb_api.ImageItem(None, img, {'key': 'value'}),
...
])
for r in result:
print(r.id, r.error)
id = dataset.insert(img, metadata={ "key": "value" })
result = dataset.insert_batch([
{
image: img.to_blob,
metadata: { "key": "value" }
},
...
])
result.each { |r|
puts r[:id], r[:error]
}

Update

Python
Ruby
# Single image
id = dataset.update(id, img, metadata={'key': 'value'})
# Batch
result = dataset.update_batch([
anndb_api.ImageItem(id, img, {'key': 'value'}),
...
])
for r in result:
print(r.id, r.error)
id = dataset.update(id, img, metadata={ "key": "value" })
result = dataset.update_batch([
{
id: id,
image: "https://my.domain/img.jpg",
metadata: { "key": "value" }
},
...
])
result.each { |r|
puts r[:id], r[:error]
}

Delete

Python
Ruby
# Single image
dataset.delete(id)
# Batch
result = dataset.delete_batch([id, ...])
for r in result:
print(r.id, r.error)
dataset.delete(id)
result = dataset.delete_batch([id, ...])
result.each { |r|
puts r[:id], r[:error]
}