# Sorting using AI / neural net

I have a search operation taking place on a server that essentially queries images using OpenCV against other images from a database. Since each image query operation is quite expensive computationally, I want to find a good way to sort the images in the database to compare them in a good order. I want the program to be more likely to find a good match early and less likely to have to try all the images in the database to get a match. I suspect there would be strong correlations between data about the user carrying out the search (such as his age, gender, location, etc...) and the likelihood of him searching for a particular image, taking into account the history of users who successfully searched for this image and their data.

I was thinking this could be achieved with a neural network, however, I haven't found anything online about doing such type of sorting with one. Maybe I could use some type of machine learning to create a score for each item in the database and then use conventional sorting. Could you kindly recommend what might be a good approach to this?

• Sorting is generally not an operation you would do with machine learning, as we have fairly efficient algorithms to do sorting, once the order between any pair is known. I suspect that you want to either use machine learning to determine an order, or to heuristically find a small subset of 'interesting' samples. – Discrete lizard Apr 23 at 11:30
• Or perhaps what you'd ideally want is some kind of "index" of your images in the database. But that will likely be very high-dimensional to be meaningful for your purposes, and might be too much to do efficiently. In any case, I do not think 'sorting' accurately describes your problem, so please clarify how what I described would fit with what you'd want. – Discrete lizard Apr 23 at 11:33
• @Discretelizard thanks for your reply! Yes I think an index would be great and then I could just use any good sorting algo to order the search. Perhaps a neural net that calculates the indexes for a given input of data? – Anters Bear Apr 23 at 11:40
• Hmm. I'm still not exactly sure what it is you want. Do you want to preprocess (a function of) your data on the server such that it will help you with any query you will make afterwards? Or do you want a less expensive function that finds likely matches based on the given query image? – Discrete lizard Apr 23 at 12:02
• the latter: a less expensive function that finds likely matches based on the given query image – Anters Bear Apr 23 at 12:47