The QUERY_RECALL function calculates the vector index recall rate for a specified SQL query, which is the ratio of the Top-K results returned by approximate search to the results obtained by brute-force search.
This function supports all types of vector indexes.
Syntax
FUNCTION QUERY_RECALL(
IN SQL_QUERY LONGTEXT)
RETURN FLOAT;
Parameters
Parameter |
Description |
|---|---|
| sql_query | SQL query statement for calculating recall. Subqueries are not supported. |
Return value
Returns the recall rate of the FLOAT type, with a value range of 0 to 1. A closer value to 1 indicates better recall performance of the index.
Examples
Create a test table and write test data into it.
CREATE TABLE vector_index_test(c1 INT, c2 VECTOR(3), PRIMARY KEY(c1), VECTOR INDEX idx1(c2) WITH (distance=l2, type=hnsw, lib=vsag));
INSERT INTO vector_index_test VALUES(1, '[0.203846,0.205289,0.880265]');
INSERT INTO vector_index_test VALUES(2, '[0.484526,0.669954,0.986755]');
INSERT INTO vector_index_test VALUES(3, '[0.327936,0.048756,0.084670]');
INSERT INTO vector_index_test VALUES(4, '[0.148869,0.878546,0.028024]');
INSERT INTO vector_index_test VALUES(5, '[0.334970,0.857377,0.886132]');
INSERT INTO vector_index_test VALUES(6, '[0.117582,0.302352,0.471198]');
INSERT INTO vector_index_test VALUES(7, '[0.551185,0.231134,0.075354]');
INSERT INTO vector_index_test VALUES(8, '[0.185221,0.315131,0.558301]');
INSERT INTO vector_index_test VALUES(9, '[0.928764,0.254038,0.272721]');
Calculate the recall rate for a specified query.
SELECT DBMS_VECTOR.QUERY_RECALL('SELECT * FROM vector_index_test ORDER BY l2_distance(c2, [0.2, 0.3, 0.8]) APPROXIMATE LIMIT 3') AS recall_rate;
The query result is as follows:
+-------------+
| recall_rate |
+-------------+
| 1 |
+-------------+