Images

Images

Images

class vectorai.api.image.ViImageClient(username, api_key, url=None)

Search and Encoding of Images

search_image(collection_name: str, image, fields: List, metric: str = 'cosine', min_score=None, page: int = 1, page_size: int = 10, include_vector: bool = False, include_count: bool = True, asc: bool = False, return_curl: bool = False, **kwargs)

Search an image field with image using Vector Search

Vector similarity search with an image directly.

_note: image has to be stored somewhere and be provided as image_url, a url that stores the image_

For example: an image_url represents an image of a celebrity:

"https://www.celebrity_images.com/brad_pitt.png"

-> <Encode the image to vector> ->

image vector: [0.794617772102356, 0.3581121861934662, 0.21113917231559753, 0.24878688156604767, 0.9741804003715515 ...]

-> <Vector Search> ->

Search Results: {...}
Parameters
  • image_url – The image url of an image to encode into a vector

  • collection_name – Name of Collection

  • search_fields – Vector fields to search through

  • approx – Used for approximate search

  • sum_fields – Whether to sum the multiple vectors similarity search score as 1 or seperate

  • page_size – Size of each page of results

  • page – Page of the results

  • metric – Similarity Metric, choose from [‘cosine’, ‘l1’, ‘l2’, ‘dp’]

  • min_score – Minimum score for similarity metric

  • include_vector – Include vectors in the search results

  • include_count – Include count in the search results

  • hundred_scale

    Whether to scale up the metric by 100

    asc:

    Whether to sort the score by ascending order (default is false, for getting most similar results)

search_image_by_upload(collection_name: str, image, fields: List, metric: str = 'cosine', min_score=None, page: int = 1, page_size: int = 10, include_vector=False, include_count=True, asc=False, return_curl: bool = False, **kwargs)

Search an image field with uploaded image using Vector Search

Vector similarity search with an uploaded image directly.

_note: image has to be sent as a base64 encoded string_

Parameters
  • collection_name – Name of Collection

  • search_fields – Vector fields to search against

  • page_size – Size of each page of results

  • page – Page of the results

  • approx – Used for approximate search

  • sum_fields – Whether to sum the multiple vectors similarity search score as 1 or seperate

  • metric – Similarity Metric, choose from [‘cosine’, ‘l1’, ‘l2’, ‘dp’]

  • min_score – Minimum score for similarity metric

  • include_vector – Include vectors in the search results

  • include_count – Include count in the search results

  • hundred_scale – Whether to scale up the metric by 100

  • image

    Image in local file path

    asc:

    Whether to sort the score by ascending order (default is false, for getting most similar results)

encode_image(collection_name: str, image, return_curl: bool = False, **kwargs)

Encode image into a vector

_note: image has to be stored somewhere and be provided as image_url, a url that stores the image_

For example: an image_url represents an image of a celebrity:

"https://www.celebrity_images.com/brad_pitt.png"

-> <Encode the image to vector> ->

image vector: [0.794617772102356, 0.3581121861934662, 0.21113917231559753, 0.24878688156604767, 0.9741804003715515 ...]
Parameters
  • image – The image url of an image to encode into a vector

  • collection_name – Name of Collection

encode_image_job(collection_name: str, image_field: str, refresh: bool = False, return_curl: bool = False, **kwargs)

Encode all images in a field into vectors

Within a collection encode the specified image field in every document into vectors.

_note: image has to be stored somewhere and be provided as image_url, a url that stores the image_

For example, an image_url field “celebrity_image” represents an image of a celebrity:

document 1 image_url field: {"celebrity_image" : "https://www.celebrity_images.com/brad_pitt".png}

document 2 image_url field: {"celebrity_image" : "https://www.celebrity_images.com/brad_pitt.png"}

-> <Encode the images to vectors> ->

document 1 image_url vector: {"celebrity_image_vector_": [0.794617772102356, 0.3581121861934662, 0.21113917231559753, 0.24878688156604767, 0.9741804003715515 ...]}

document 2 image_url vector: {"celebrity_image_vector_": [0.8364648222923279, 0.6280597448348999, 0.8112713694572449, 0.36105549335479736, 0.005313870031386614 ...]}
Parameters
  • image_field – The image field to encode into vectors

  • refresh – Whether to refresh the whole collection and re-encode all to vectors

  • collection_name – Name of Collection