Skip to content

[DISCUSSION] New AI/ML functionalities #255

Closed

Description

@monatis

Hi,
I want to contribute to Appwrite with a separate container for AI/ML functionalities. It will be served as a web API just like other services, and it might be tightly integrated with them, e.g. storage API to process images.

Possible functionalities might include:

  • Nudity detection in images,
  • General purpose object detection,
  • Face detection,
  • Sentiment classification in texts,
    and other suggestions are welcome.

In image understanding APIs, I'm thinking of accepting images as base64-encoded strings in the JSON payloads of POST requests. So, a sample request might be as in the following:

{
  "image":
  {
    "type": "base64",
    "data": "base64 encoded string goes here"
  },
  "feature": "nudity-detection"
}

One advantage of this approach over multipart/form-data, we can also accept image URLs instead of base64-encoded image data with the same schema as in the following:

{
  "image":
  {
    "type": "url",
    "data": "https://example.com/image.jpg"
  },
  "feature": "nudity-detection"
}

For Appwrite, we can also accept a file id uploaded through storage API.

Please leave your comments to help respond to more needs and use cases with a short learning curve. What might be other use cases that we could provide an AI/ML API for? How should we implement them to minimize overhead on the client side yet remain flexible to different senarios?

Activity

  1. eldadfux commented on Nov 15, 2019

    @eldadfux
    Member

    Thank you for the great ideas and the interesting discussion @monatis!

    Any ML services that we use internally and are not exposed via Appwrite REST API can even share direct access to the storage for better performance the same way we work with the ClamAV container to scan uploaded files. Not too sure about using JSON instead of multipart/form-data in file uploads because this can be very limiting when trying to upload big files (75MB+).

    A few points that are really important for me to take into account:

    • Choosing 3rd party dependencies very carefully, some of the things we take under consideration when introducing new dependencies are listed in this medium post.

    • Try and do our best at hiding any ML/AI complexity from Appwrite end developers. Adding ML should be a mean to introduce new capabilities in the API and not our final goal.

    • We should make sure our minimum requirements stay in the region of 1-2 CPU cores and 1-2 GB memory. Appwrite should be portable and cheap to set up.

    Another thing to think about is how are we going to make ML training? Should training run in the background? Should they run offline and get updated only on version release? How can we scale this and still be able to run on cheap hardware?

    I would love to hear more ideas about adding ML power to our existing API functionality.

  2. monatis commented on Nov 16, 2019

    @monatis
    Author

    Hi @eldadfux, thank you for bringing your considerations about dependencies into attension. Mostly agree on them.
    I think that we shouldn't expose a training API in the initial plan. This would be too complex and require a large memory and possibly even a GPU, which would change the target audience of Appwrite.
    Instead, I suggest that we should deploy several pretrained AI/ML models for image and text understanding that could be applied to most common senarios. For instance, we might have an endpoint /v1/image-understanding that might return a score for the possibility that the image might contain explicit content. Or, it might return a list of objects found in the image and their bounding boxes when the value of the key "feature" set to "object-detection". Similarly, it can return a list of faces and its bounding boxes if any in the image when "feature" set to "face-detection".

    The AI/ML models for any endpoint or "feature" will be pretrained and optimized for inference on cheap hardware. Excluding training tasks out of the scope of this feature will also eliminate the necessity to use multipart for the sake of supporting large files. Any file that will be sent through image understanding API should not exceed 75 mb in size. However, if you think that we need to support multipart/form-data anyway, it's no problem. I might
    provide a sample API that would work based on the considerations above shortly within a few days.

  3. eldadfux commented on Nov 16, 2019

    @eldadfux
    Member

    @monatis A demo API will be great.

    I am also considering the option to hide this functionality as background tasks that are triggered by our queue engine (redis/resque) and then this task can apply the results as new metadata to existing file information. This way we will get this abilities by default to all relevant files and the API will have zero performance penalty.

    I am also thinking about the possibility to allow this kind of functions to be added using a plugin mechanism to allow more custom and feature specific abilities.

  4. monatis commented on Nov 16, 2019

    @monatis
    Author

    @eldadfux setting the functionality as a background task would be great in terms of reducing performance penalty, but it might be limiting for use cases where we want to use the API for the core app logic. We might need to come up with an idea to support both.

    Another senario might be conditional upload. For example post an image to the API and specify conditions, e.g., if it contains at least one face with a confidence score of >0.5. Now the API could look for faces, talks to the storage API internally to save it if it meets the condition and return metadata from the storage API, but it can simply generate an error message if it does not meet the condition.

  5. eldadfux commented on Nov 16, 2019

    @eldadfux
    Member

    @monatis I totally get what your'e saying. We need to figure out what is the perfect balance. On of Appwrite major selling points is hiding complexity for developers but at the end of the day we don't want to limit more advanced scenarios there for finding the right balance is crucial.

  6. eldadfux commented on Nov 16, 2019

    @eldadfux
    Member

    Anyway I think a demo API on an independent container could be great and will also help us figure out more things we need to decide about the scope of this features.

  7. monatis commented on Nov 16, 2019

    @monatis
    Author

    Agreed.
    Great, I'll be sharing a demo API at the beginning of next week then.

  8. eldadfux commented on Nov 23, 2019

    @eldadfux
    Member

    @monatis let me know if you need any help. I am available on our Discord server:
    https://discord.gg/GSeTUeA

  9. added
    discussion
    enhancement
    on Nov 23, 2019
  10. monatis commented on Nov 23, 2019

    @monatis
    Author

    @eldadfux I've already made some progress in this, coding a Docker-containerized object detection API. I'm travelling this weekend to talk at some developer events, but I'll share my code as soon as possible for further discussion and to get some clues around integration with the storage API.

  11. eldadfux commented on Nov 23, 2019

    @eldadfux
    Member

    @monatis sounds cool! Have a great trip and keep us posted! 👍🏻

  12. monatis commented on Nov 26, 2019

    @monatis
    Author

    I pushed the first draft of image understanding APIs for Appwrite to a private repository on Gitub and invited @eldadfux as a collaborator for further discussion. I might invite others as collaborators to this repo as well, but I find it more appropriate to keep it private at this very early stage where we need to figure out many things before going public.
    I designed basic schemas for requests to and responses from AI/ML APIs. Currently, it can

    • Accept an image URL or base64 encoding of an image in a given JSON schema,
    • parse the image appropriately based on the format it is passed in,
    • detects objects in it,
    • returns a response in a certain JSON schema including basic metadata and a list of detected objects and its bounding boxes.

    Now I'm planning to

    • make metadata in response more verbose,
    • accept imageId in requests and that image from the storage service,
    • publish detected objects to the storage service,
    • make minimum confidence score configurable in requests,
    • Test extreme cases.

    We can choose one of the possible ways for integration with the storage service.

    • a) The storage service should accept requests from clients and forward image understanding endpoints to the appropriate container (that I'm developing) after authentication/authorization.
    • b) Mount endpoints exposed by the image understanding container to some path, say, /image-understanding, and the container should verify request, validate authorization tokens, talk to the storage service internally etc.

    Which one would you prefer, or any other idea on this?

  13. eldadfux commented on Nov 26, 2019

    @eldadfux
    Member

    Hey @monatis!

    Thank you for keeping us up-to-date with your progress. I did see you invited me as a collaborator to the image-understanding repo, and I will make some time during this week or the upcoming weekend to give it a proper review.

    I think that at this stage, it will be best if we’ll develop all AI/ML capabilities as standalone containers that are 100% independent and can be considered as their own project.

    Appwrite should be the only gateway to developers and clients, so I think it will be best that Appwrite and the ML/AI containers will communicate internally and over HTTP protocol, as with do all other containers Appwrite communicates with.

    I was also thinking a bit more about the way we shall pass the files between the two containers, and I don’t think we could use a fileId or a file path. This is because Appwrite encrypts all files before saving them on the storage device, and I think its best for both security and separation of concerns that the ML/AI container won’t deal with decrypting files or understanding Appwrite complexities. I guess this only leaves us with passing the entire file using a multipart post request.

  14. locked and limited conversation to collaborators on May 13, 2022
  15. converted this issue into a discussion #3215 on May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

discussionenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions