I would like to write a single SPARQL query to find the k nearest neighbors for a set of vectors. To find the average label for the 100 nearest neighbors for a single vector I can use the following query:
PREFIX : <ml://>
PREFIX vector: <ml://vector/>
PREFIX feature: <ml://feature/>
SELECT (AVG(?label) as ?prediction)
WHERE {
{
SELECT ?other_vector (COUNT(?common_feature) as ?similarity)
WHERE { vector:0 :has ?common_feature .
?other_vector :has ?common_feature .
} GROUP BY ?other_vector ORDER BY DESC(?similarity) LIMIT 100
}
?other_vector :hasLabel ?label .
}
Is there a way to do this for multiple vectors in a single query?