`cube` query performance issues with ordering
Sorting works on values the query returns.

Here you have an index on embedding column but you are sorting on the result of embedding &lt;-&gt; cube('(0.08470847,...,0.06106149)'), which is not indexed.

So first retrieve the required result with the help of sub-query, then perform sorting.

select id,EDistance
from
(
select id, embedding &lt;-&gt; cube('(0.08470847,...,0.06106149)') EDistance 
from documents 
where embedding &lt;-&gt; cube('(0.08470847,...,0.06106149)') &lt; 0.25
limit 25
) t
order by EDistance ASC


Thanks!