Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
MBkkt committed Jun 27, 2024
1 parent 4483086 commit 1bcde3d
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions ydb/public/sdk/cpp/examples/vector_index/search.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@
-- ORDER BY cosine
-- LIMIT $LimitVectors;

$LimitCentroid0 = 35;
$LimitCentroid1 = 6;
$LimitCentroid2 = 4;
-- $LimitVectors = 322;
$Target = Knn::ToBinaryStringFloat(Cast([-1.7363281,-1.7363281,0.4609375,-1.7363281,-0.41796875,0.021484375,0.4609375,-0.41796875,-1.296875,0.021484375,1.7792969,-0.41796875,-0.8574219,-0.41796875,-1.296875,0.4609375,0.9003906,-1.296875,0.021484375,0.021484375,0.9003906,0.4609375,1.3398438,0.4609375,0.4609375,-0.41796875,-0.8574219,1.3398438,-0.41796875,-0.41796875,-0.41796875,-0.8574219,-2.1757812,-2.1757812,0.4609375,0.4609375,2.21875,-1.7363281,-1.296875,0.9003906,-2.1757812,-1.7363281,-1.296875,-0.41796875,-0.8574219,2.21875,-0.8574219,0.021484375,0.021484375,0.4609375,0.021484375,0.9003906,-0.41796875,-0.41796875,1.3398438,-0.41796875,0.021484375,0.021484375,0.9003906,-0.41796875,-1.296875,0.021484375,0.4609375,-0.8574219,-2.1757812,0.021484375,0.4609375,0.021484375,-0.8574219,0.021484375,-1.296875,-0.8574219,-0.8574219,0.4609375,-0.8574219,-0.41796875,-0.8574219,0.021484375,-1.296875,0.4609375,1.3398438,0.021484375,0.4609375,0.021484375,0.4609375,-1.7363281,1.3398438,0.9003906,1.3398438,-0.8574219,0.021484375,0.9003906,-0.8574219,-0.41796875,-1.296875,-0.8574219,-0.8574219,-1.296875,0.4609375,0.4609375,2.6582031,0.4609375,0.9003906,0.9003906,-3.4941406,-0.8574219,-1.296875,-0.8574219,-0.8574219,-0.8574219,-2.1757812,-0.41796875,0.4609375,0.021484375,0.021484375,0.4609375,-0.41796875,-0.8574219,0.9003906,0.021484375,0.4609375,-0.8574219,0.021484375,0.9003906,-0.8574219,-0.41796875,0.4609375,-0.41796875,-2.1757812,0.4609375,0.021484375,0.4609375,0.021484375,-0.41796875,-1.7363281,-0.8574219,-1.7363281,0.4609375,-0.8574219,-0.41796875,-0.41796875,0.9003906,-1.7363281,0.021484375,0.4609375,1.3398438,0.9003906,0.9003906,0.4609375,-1.296875,0.021484375,-0.41796875,2.21875,-0.8574219,-1.296875,1.3398438,-0.8574219,0.4609375,0.021484375,-0.8574219,0.4609375,-1.296875,-0.41796875,0.021484375,1.3398438,0.4609375,0.9003906,0.9003906,-2.6152344,-1.7363281,-1.296875,-0.41796875,0.021484375,-0.41796875,-0.8574219,-0.41796875,0.9003906,-1.296875,0.021484375,0.9003906,-0.8574219,-0.41796875,1.7792969,-1.296875,0.021484375,-0.8574219,-0.8574219,1.3398438,-0.8574219,-0.8574219,0.021484375,-1.296875,-2.1757812,-0.41796875,0.4609375,-0.41796875,-0.41796875,0.021484375,-0.8574219,-1.7363281,-0.41796875,0.9003906,-0.8574219,-1.296875,-1.296875,0.021484375,-1.296875,0.4609375,1.7792969,0.021484375,-0.41796875,0.4609375,0.4609375,0.021484375,0.9003906,1.3398438,0.021484375,-0.41796875,0.4609375,1.3398438,0.021484375,0.4609375,-1.7363281,-0.8574219,-1.7363281,-1.7363281,0.4609375,0.9003906,3.0976562,-0.8574219,0.4609375,0.9003906,-3.4941406,-0.41796875,-1.296875,-0.8574219,-0.8574219,-0.41796875,-2.1757812,-0.41796875,0.9003906,0.021484375,-0.41796875,0.021484375,0.4609375,-0.41796875,0.9003906,0.4609375,0.4609375,-1.7363281,0.021484375,-0.41796875,-0.41796875,0.4609375,0.021484375,-0.41796875,-2.1757812,0.9003906,-0.8574219,0.9003906,-0.41796875,-0.41796875,-1.7363281,-0.8574219,0.021484375,0.4609375,-0.41796875,-0.8574219,-0.41796875,-1.296875,-0.8574219,-0.8574219,0.9003906,0.9003906,-0.41796875,0.9003906,0.021484375,-0.41796875,0.4609375,2.21875,0.4609375,-0.8574219,-1.296875,0.021484375,-1.296875,1.7792969,-0.41796875,-0.8574219,-0.41796875,-1.296875,0.4609375,1.3398438,2.21875,-0.41796875,1.3398438,0.4609375,-2.6152344,-0.8574219,-1.296875,-1.296875,-1.296875,0.021484375,-0.8574219,-0.8574219,0.4609375,0.021484375,-0.41796875,1.3398438,0.021484375,0.021484375,1.3398438,-0.41796875,0.4609375,-1.7363281,0.021484375,-0.41796875,-0.8574219,0.4609375,-0.8574219,-0.8574219,-1.296875,-0.41796875,0.021484375,0.021484375,-0.8574219,-1.296875,-0.8574219,-1.296875,0.021484375,1.3398438,-1.296875,-2.6152344,-0.8574219,-1.296875,-1.296875,0.021484375,0.9003906,-0.41796875,-0.41796875,0.9003906,0.4609375,0.021484375,1.3398438,1.3398438,0.4609375,0.021484375,0.4609375,1.3398438,-0.41796875,0.4609375,-1.296875,-0.8574219,-1.7363281,-1.7363281,0.9003906,0.9003906,1.3398438,-0.41796875,0.9003906,0.021484375,-3.0546875,0.021484375,-1.296875,-0.8574219,0.021484375,0.9003906,-1.7363281,-0.41796875,0.4609375,-0.41796875,-0.41796875,0.9003906,0.021484375,0.021484375,1.7792969,-0.41796875,0.9003906,-1.296875,1.3398438,-1.7363281,-0.8574219,0.9003906,0.4609375,-0.41796875,-0.41796875,-0.8574219,-0.41796875,0.4609375,-1.7363281,-1.7363281,-0.8574219,-1.296875,0.4609375,1.3398438,-1.7363281,-2.6152344,0.021484375,-2.1757812,-1.296875,0.021484375,0.4609375,-0.41796875,0.021484375,0.9003906,0.021484375,0.4609375,0.9003906,1.3398438,0.9003906,-0.41796875,0.021484375,1.3398438,-0.41796875,0.9003906,-0.8574219,-0.8574219,-0.8574219,-1.296875,0.4609375,0.9003906,0.4609375,-0.41796875,0.4609375,-0.8574219,-2.6152344,0.021484375,-0.8574219,-1.296875,0.021484375,1.3398438,-1.296875,-1.296875,0.4609375,0.021484375,-0.41796875,1.7792969,0.021484375,0.4609375,1.3398438,-0.8574219,0.4609375,-0.8574219,0.4609375,-1.296875,-0.8574219,0.9003906,0.021484375,0.021484375,1.3398438,-0.41796875,-1.296875,-0.8574219,1.3398438,0.021484375,0.4609375,0.9003906,-1.296875,0.4609375,-1.296875,-1.296875,0.021484375,-0.8574219,-0.8574219,-0.41796875,0.021484375,0.4609375,0.021484375,0.9003906,-0.41796875,0.021484375,0.021484375,0.9003906,0.9003906,-2.1757812,-1.7363281,0.021484375,-3.0546875,0.021484375,0.021484375,-1.7363281,1.3398438,-0.41796875,0.9003906,-0.8574219,-0.41796875,-2.6152344,0.4609375,-0.41796875,0.021484375,0.021484375,-2.1757812,0.021484375,0.9003906,0.021484375,1.3398438,-1.296875,0.9003906,-0.8574219,0.4609375,0.9003906,-0.41796875,0.9003906,0.4609375,0.021484375,0.4609375,-1.7363281,-1.296875,-0.8574219,0.9003906,-0.8574219,-1.7363281,-0.41796875,0.9003906,0.021484375,0.4609375,0.021484375,0.021484375,-1.7363281,-0.8574219,-0.8574219,0.021484375,0.9003906,-1.296875,-2.1757812,-0.41796875,-0.8574219,-3.4941406,0.021484375,-0.41796875,0.4609375,0.4609375,0.4609375,0.4609375,0.4609375,0.021484375,-0.8574219,1.7792969,0.021484375,-1.7363281,1.7792969,-0.8574219,0.021484375,0.4609375,0.4609375,0.021484375,-1.7363281,0.021484375,-0.41796875,0.4609375,-0.41796875,0.9003906,0.021484375,-1.296875,-0.8574219,-1.296875,-0.8574219,0.4609375,0.021484375,-0.41796875,-1.296875,1.3398438,-1.7363281,0.021484375,0.4609375,-0.41796875,0.4609375,2.6582031,-1.7363281,0.021484375,-1.7363281,-0.41796875,0.4609375,0.021484375,-0.8574219,0.021484375,-0.8574219,0.4609375,-0.8574219,0.4609375,0.4609375,2.21875,-1.7363281,-0.8574219,-0.8574219,-1.296875,0.021484375,-0.41796875,-0.8574219,-1.296875,0.021484375,-2.6152344,-0.41796875,-0.41796875,0.9003906,0.021484375,0.9003906,0.021484375,-0.8574219,-0.8574219,-0.41796875,1.7792969,-0.41796875,-0.41796875,0.9003906,-0.8574219,-0.41796875,0.021484375,0.9003906,-0.41796875,-1.7363281,0.4609375,0.021484375,0.4609375,-2.1757812,-0.8574219,0.021484375,-0.8574219,0.4609375,-2.1757812,-1.296875,0.9003906,0.9003906,-1.296875,-0.41796875,0.021484375,-0.8574219,0.4609375,0.4609375,0.021484375,0.021484375,2.6582031,-0.41796875,-0.41796875,-1.7363281,0.4609375,-0.41796875,1.3398438,-0.41796875,0.4609375,-0.41796875,0.4609375,-0.8574219,0.4609375,0.4609375,2.21875,-1.7363281,-0.8574219,-0.8574219,-1.296875,0.021484375,-0.41796875,-0.8574219,-1.296875,0.021484375,-2.6152344,-0.41796875,-0.41796875,0.9003906,0.021484375,0.9003906,0.021484375,-0.8574219,-0.8574219,-0.41796875,1.7792969,-0.41796875,-0.41796875,0.9003906,-0.8574219,-0.41796875,0.021484375,0.9003906,-0.41796875,-1.7363281,0.4609375,0.021484375,0.4609375,-2.1757812,-0.8574219,0.021484375,-0.8574219,0.4609375,-2.1757812,-1.296875,0.9003906,0.9003906,-1.296875,-0.41796875,0.021484375,-0.8574219,0.4609375,0.4609375,0.021484375,0.021484375,2.6582031,-0.41796875,-0.41796875,-1.7363281,0.4609375,-0.41796875,1.3398438,-0.41796875,0.4609375,-0.41796875,0.4609375,-0.8574219,0.4609375,0.4609375,2.21875,-1.7363281,-0.8574219,-0.8574219,-1.296875,0.021484375,-0.41796875,-0.8574219,-1.296875,0.021484375,-2.6152344,-0.41796875,-0.41796875,0.9003906,0.021484375,0.9003906,0.021484375,-0.8574219,-0.8574219,-0.41796875,1.7792969,-0.41796875,-0.41796875,0.9003906,-0.8574219,-0.41796875,0.021484375,0.9003906,-0.41796875,-1.7363281,0.4609375,0.021484375,0.4609375,-2.1757812,-0.8574219,0.021484375,-0.8574219,0.4609375,-2.1757812,-1.296875,0.9003906,0.9003906,-1.296875,-0.41796875,0.021484375,-0.8574219,0.4609375,0.4609375,0.021484375,0.021484375,2.6582031,-0.41796875,-0.41796875,-1.7363281,0.4609375,-0.41796875,1.3398438,-0.41796875,0.4609375,-0.41796875,0.4609375,-0.8574219,0.4609375,0.4609375,2.21875,-2.1757812,-0.8574219,-0.8574219,-0.8574219,0.021484375,-0.41796875,-0.8574219,-1.296875,0.021484375,-2.6152344,-0.41796875,-0.41796875,0.9003906,0.021484375,0.9003906,0.021484375,-0.8574219,-0.8574219,-0.41796875,1.7792969,0.021484375,-0.41796875,0.9003906,-0.8574219,-0.41796875,0.021484375,0.9003906,-0.41796875,-1.7363281,0.4609375,0.021484375,0.4609375,-2.1757812,-0.8574219,0.021484375,-0.8574219,0.4609375,-2.1757812,-1.296875,0.9003906,0.9003906,-1.296875,-0.41796875,0.021484375,-0.8574219,0.4609375,0.4609375,0.021484375,0.021484375,2.6582031,-0.41796875,-0.41796875,-1.7363281,0.4609375,-0.41796875,1.3398438,-0.41796875,0.4609375,-0.41796875,0.9003906,0.021484375,0.021484375,0.9003906,-0.41796875,0.021484375,0.021484375,1.3398438,0.9003906,0.021484375,0.4609375,0.021484375,-0.41796875,-0.41796875,-0.8574219,1.3398438,0.4609375,-0.41796875,-0.41796875,0.021484375,0.4609375,0.9003906,0.9003906,-0.41796875,0.9003906,-2.1757812,0.021484375,-1.296875,-1.296875,-0.8574219,-0.41796875,0.021484375,0.021484375,-0.8574219,0.4609375,0.4609375,-0.8574219,-3.4941406,0.021484375,0.9003906,-1.296875,1.3398438,0.021484375,0.9003906,-0.8574219,0.021484375,-0.8574219,-0.8574219,-1.296875,-1.296875,0.4609375,1.3398438,-1.7363281,0.021484375,-0.41796875,0.4609375,-0.8574219,-3.0546875,0.021484375,0.021484375,0.4609375,-2.1757812,-1.7363281,0.4609375,0.9003906,0.021484375,0.021484375,0.9003906,-0.41796875,0.021484375,0.021484375,1.3398438,0.9003906,0.021484375,0.4609375,0.021484375,-0.41796875,-0.41796875,-1.296875,1.3398438,0.4609375,-0.41796875,-0.8574219,0.4609375,0.9003906,0.9003906,0.9003906,-0.41796875,0.9003906,-2.1757812,0.021484375,-1.296875,-1.296875,-1.296875,-0.41796875,0.021484375,0.021484375,-0.8574219,0.4609375,0.4609375,-0.41796875,-3.4941406,-0.41796875,0.9003906,-1.296875,1.3398438,0.021484375,0.9003906,-0.8574219,-0.41796875,-0.8574219,-0.8574219,-1.296875,-1.7363281,0.4609375,1.3398438,-1.7363281,0.021484375,0.021484375,0.4609375,-0.8574219,-3.0546875,0.021484375,0.4609375,0.4609375,-2.1757812,-1.7363281,0.4609375,0.9003906,-0.41796875,0.021484375,0.9003906,-0.41796875,-0.41796875,0.021484375,1.3398438,0.9003906,0.021484375,0.4609375,0.4609375,-0.41796875,-0.41796875,-1.296875,1.3398438,0.4609375,-0.41796875,-0.8574219,0.021484375,0.4609375,0.9003906,0.9003906,-0.8574219,0.9003906,-2.1757812,0.021484375,-1.296875,-1.296875,-1.296875,-0.8574219,0.021484375,0.021484375,-0.8574219,0.021484375,0.021484375,-0.41796875,-3.4941406,-0.41796875,0.9003906,-1.296875,1.7792969,0.021484375,1.3398438,-0.41796875,-0.41796875,-0.8574219,-0.8574219,-1.296875,-1.7363281,0.4609375,1.3398438,-1.7363281,0.021484375,0.021484375,0.4609375,-0.41796875,-2.6152344,0.021484375,0.021484375,0.4609375,-2.1757812,-1.7363281,0.4609375] as List<Float>));

$LimitCentroid0 = 1;
$LimitCentroid1 = 1;
$LimitCentroid2 = 1;
$LimitVectors = 10;

$Centroid0Ids = SELECT Knn::CosineDistance($Target, embedding) AS cosine, id
FROM alice_float_kmeans_none
WHERE parent_id = 0
Expand Down Expand Up @@ -74,12 +75,18 @@ $VectorIds = SELECT id
-- select * FROM $Centroid2Ids;
-- select * FROM $VectorIds;

$Result = SELECT *
FROM (
SELECT Knn::CosineDistance($Target, embedding) AS cosine, text
FROM alice_float WHERE id IN (SELECT id FROM $VectorIds)
)
WHERE cosine < 0.05;

select * FROM $Result ORDER BY cosine;
select COUNT(*) FROM $Result;
SELECT Knn::CosineDistance($Target, embedding) AS cosine, text
FROM alice_float
WHERE id IN (SELECT id FROM $VectorIds)
ORDER BY cosine
LIMIT $LimitVectors;

-- $Result = SELECT *
-- FROM (
-- SELECT Knn::CosineDistance($Target, embedding) AS cosine, text
-- FROM alice_float WHERE id IN (SELECT id FROM $VectorIds)
-- )
-- WHERE cosine < 0.05;

-- select * FROM $Result ORDER BY cosine;
-- select COUNT(*) FROM $Result;

0 comments on commit 1bcde3d

Please sign in to comment.