The INDEX_RECALL function calculates the recall rate for a specified vector index, which is the ratio of the Top-K results returned by approximate search to the results of a brute-force search. If vectors is not provided, the function samples NUM_VECTORS vectors from existing data in the table for the calculation.
This function supports all types of vector indexes.
Syntax
FUNCTION INDEX_RECALL(
IN TABLE_NAME VARCHAR(65535),
IN INDEX_NAME VARCHAR(65535),
IN VECTORS LONGTEXT DEFAULT NULL,
IN NUM_VECTORS INT DEFAULT 25,
IN TOP_K INT DEFAULT 10,
IN FILTER LONGTEXT DEFAULT NULL,
IN PARALLEL INT DEFAULT 1,
IN PARAMETERS VARCHAR(65535) DEFAULT NULL)
RETURN FLOAT;
Parameters
Parameter |
Description |
|---|---|
| table_name | Table name, which is required. |
| index_name | Index name, which is required. |
| vectors | The vector used to calculate recall. Default value:NULL. If not specified, data will be sampled from the existing data in the table.NUM_VECTORSPerform calculations on vector columns. |
| num_vectors | The number of sampled vectors. The default value is 25, and the valid range is 1 to 50. |
| top_k | The number of top K results returned in the search. The default value is 10. |
| filter | Scalar filter conditions, that is, in SQL statements.WHEREThe content of the clause (excludingWHERE(Keywords), which is by default.NULL. |
| parallel | Parallelism, which defaults to 1. |
| parameters | Search parameters, that is, in the SQL statement.PARAMETERS(...), for example,IVF_NPROBES=20The default value isNULL. |
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 of index idx1. Sample 15 vectors and set the search Top-K to 10.
SELECT DBMS_VECTOR.INDEX_RECALL('vector_index_test', 'idx1', NULL, 15, 10, NULL, 4, NULL) AS recall_rate;
The query result is as follows:
+-------------+
| recall_rate |
+-------------+
| 1 |
+-------------+