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.
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
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
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
# 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" })