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