From: PatwalVineet (@PatwalVineet) <noreply+PatwalVineet@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #837: hnsw indexing Search Results Become Inconsistent Under High Query Rate
Date: Thu, 15 May 2025 04:16:47 +0000
Message-ID: <gh-pgvector-pgvector-837-c2882189766@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-837@github.com>
References: <gh-pgvector-pgvector-837@github.com>
@ankane
i have provided my table backup link schema is events
https://drive.google.com/file/d/12uKbhhTicaEB7sPvkEdk9b-l2sGMt8eL/view?usp=sharing
```DO $$
DECLARE
rec RECORD;
closest_match UUID;
BEGIN
-- Start a single transaction for the entire process
FOR rec IN
SELECT "Id", "embedding" FROM events."Face_Recognition" ORDER BY "Id" ASC
LOOP
-- Find the closest match where id is less than current id
SELECT "GroupId"
INTO closest_match
FROM (
SELECT "Id","GroupId", "embedding" <=> rec.embedding AS "CosineDistance"
FROM events."Face_Recognition" where "Id"<rec."Id"
) AS Subquery
WHERE "CosineDistance" < 0.5 AND "GroupId" IS NOT NULL
ORDER BY "CosineDistance"
LIMIT 1;
-- If no match found, generate a new UUID
IF closest_match IS NULL THEN
closest_match := uuid_generate_v4();
END IF;
-- Update the current row
UPDATE events."Face_Recognition"
SET "GroupId" = closest_match
WHERE "Id" = rec."Id";
closest_match:=null;
END LOOP;
EXCEPTION WHEN OTHERS THEN
-- Handle errors for the entire process
RAISE NOTICE 'Error processing records: %', SQLERRM;
ROLLBACK;
commit;
END $$;
```
this is the query which i am using to assign groupIds based on vector similarity
in my Face_Recognition table there are 9705 rows having repeated 51 unique vectors so according to this query the output of distinct groupIds should be 51