Perhaps the best choice would be to expand the cube , since your area of ββinterest is not an individual integer, but a complete vector.
Cube supports GiST indexing, and Postgres 9.6 will also index KNN into cubes, supporting Euclidean, taxi (aka Manhattan) and Chebyshev distances .
Itβs a little annoying that 9.6 is still under development, but there is no problem with a patch for backporting to expand the cube to 9.5, and I say this from experience.
We hope that 128 measurements will continue to be sufficient to produce meaningful results .
How to do it?
First enter an example table:
create extension cube; create table vectors (id serial, vector cube);
Fill the table with sample data:
insert into vectors select id, cube(ARRAY[round(random()*1000), round(random()*1000), round(random()*1000), round(random()*1000), round(random()*1000), round(random()*1000), round(random()*1000), round(random()*1000)]) from generate_series(1, 2000000) id;
Then try to choose:
explain analyze SELECT * from vectors order by cube(ARRAY[966,82,765,343,600,718,338,505]) <
We must create an index:
create index vectors_vector_idx on vectors (vector);
Does it help:
explain analyze SELECT * from vectors order by cube(ARRAY[966,82,765,343,600,718,338,505]) <
In 8 dimensions, this helps.