IVF Index
Note:
Performance tables, charts, timings, and capacity heuristics on this page are retained from upstream Apache Doris material. They were not measured on VeloDB Cloud. Use them as starting points and validate recall, latency, throughput, and memory on your own workload.
One-sentence definition: IVF (Inverted File Index) is an approximate nearest neighbor (ANN) index that partitions the vector space through clustering to narrow the search range. Core 26.1.1 release notes include IVF and disk-backed IVF support.
This article answers the following questions:
- What is the IVF index? Why does it accelerate vector retrieval?
- How do you create, build, and drop an IVF index in VeloDB Cloud?
- How do you choose key parameters such as
nlistandnprobeto balance recall and performance? - What factors affect recall? How do you avoid performance degradation?
Quick navigation
| Your goal | Jump to |
|---|---|
| Understand the basic principles of IVF | What Is the IVF Index |
| Create and use an IVF index | Use IVF in VeloDB Cloud |
| Tune recall | Recall Optimization |
| Troubleshoot query performance | Query Performance |
| Reproduce performance benchmarks | Benchmark |
| Common questions | FAQ |
What is the IVF index
From inverted indexes to vector inverted indexes
The term IVF (Inverted File) originates from the field of information retrieval. Take text retrieval as an example:
-
Forward index: Each document maintains a list of words. The query must scan all documents.
Document Words Document 1 the, cow, says, moo Document 2 the, cat, and, the, hat Document 3 the, dish, ran, away, with, the, spoon -
Inverted index: Each word maintains a list of "documents that contain this word." The query only needs to scan the relevant lists.
Word Documents the Document 1, Document 3, Document 4, Document 5, Document 7 cow Document 2, Document 3, Document 4 says Document 5 moo Document 7
Today, text is usually represented as vector embeddings. IVF borrows the inverted-index idea: cluster centroids act as the "dictionary," and each centroid maintains a list of "vectors that belong to this cluster." A query only needs to inspect a small number of selected clusters.
Why IVF accelerates vector search
When a dataset grows to millions or billions of vectors, exact kNN search (computing the distance between the query vector and every vector in the database) is equivalent to a large-scale matrix multiplication, and the computational cost becomes unacceptable.
Approximate nearest neighbor (ANN) search trades a small amount of accuracy for an order-of-magnitude speedup. IVF is one of the most widely used and effective ANN methods in industry. Its core idea is "divide and conquer":
- Partition the entire vector dataset into multiple clusters, each represented by a centroid.
- At query time, first identify the small number of clusters whose centroids are closest to the query vector, search only within these clusters, and skip the rest of the data.

Use IVF in VeloDB Cloud
VeloDB Cloud supports IVF-based ANN indexes. The index type is fixed as ANN, and the IVF algorithm is selected by specifying index_type=ivf.
Choose an index build approach
There are two ways to create an ANN index, suitable for different scenarios:
| Approach | Build timing | Pros | Cons | Applicable scenarios |
|---|---|---|---|---|
| Define index at table creation | Built synchronously during data ingestion | Queries are accelerated as soon as data is written | Slows down writes; Compaction may trigger index rebuilds, wasting resources | Production environments where index parameters are already finalized |
CREATE INDEX + BUILD INDEX | Built asynchronously after data is loaded | Defers build work until after ingestion; the build still consumes resources | No acceleration during the build period | Parameter-tuning phase, initialization of very large tables |
Approach 1: Define the index at table creation
CREATE TABLE sift_1M (
id int NOT NULL,
embedding array<float> NOT NULL COMMENT "",
INDEX ann_index (embedding) USING ANN PROPERTIES(
"index_type"="ivf",
"metric_type"="l2_distance",
"dim"="128",
"nlist"="1024"
)
) ENGINE=OLAP
DUPLICATE KEY(id) COMMENT "OLAP"
DISTRIBUTED BY HASH(id) BUCKETS 1
PROPERTIES (
"replication_num" = "1"
);
INSERT INTO sift_1M
SELECT *
FROM S3(
"uri" = "https://selectdb-customers-tools-bj.oss-cn-beijing.aliyuncs.com/sift_database.tsv",
"format" = "csv");
Approach 2: CREATE INDEX + BUILD INDEX
Step 1: Create the table (without the index) and load the data.
CREATE TABLE sift_1M (
id int NOT NULL,
embedding array<float> NOT NULL COMMENT ""
) ENGINE=OLAP
DUPLICATE KEY(id) COMMENT "OLAP"
DISTRIBUTED BY HASH(id) BUCKETS 1
PROPERTIES (
"replication_num" = "1"
);
INSERT INTO sift_1M
SELECT *
FROM S3(
"uri" = "https://selectdb-customers-tools-bj.oss-cn-beijing.aliyuncs.com/sift_database.tsv",
"format" = "csv");
Step 2: Run CREATE INDEX to add the index definition. At this point, only the index metadata is registered; the index has not yet been built on the existing data.
CREATE INDEX idx_test_ann ON sift_1M (`embedding`) USING ANN PROPERTIES (
"index_type"="ivf",
"metric_type"="l2_distance",
"dim"="128",
"nlist"="1024"
);
SHOW DATA ALL FROM sift_1M;
Expected output (LocalIndexSize is still 0):
+-----------+-----------+--------------+----------+----------------+---------------+----------------+-----------------+----------------+-----------------+
| TableName | IndexName | ReplicaCount | RowCount | LocalTotalSize | LocalDataSize | LocalIndexSize | RemoteTotalSize | RemoteDataSize | RemoteIndexSize |
+-----------+-----------+--------------+----------+----------------+---------------+----------------+-----------------+----------------+-----------------+
| sift_1M | sift_1M | 10 | 1000000 | 170.093 MB | 170.093 MB | 0.000 | 0.000 | 0.000 | 0.000 |
| | Total | 10 | | 170.093 MB | 170.093 MB | 0.000 | 0.000 | 0.000 | 0.000 |
+-----------+-----------+--------------+----------+----------------+---------------+----------------+-----------------+----------------+-----------------+
Step 3: Run BUILD INDEX to build the index on the existing data. This task runs asynchronously.
BUILD INDEX ON sift_1M;
Step 4: Check the task status with SHOW BUILD INDEX.
SHOW BUILD INDEX WHERE TableName = "sift_1M";
After the task finishes, check the data size again. The index size (LocalIndexSize) has been generated:
+---------------+-----------+---------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------+-------------------------+---------------+----------+------+----------+
| JobId | TableName | PartitionName | AlterInvertedIndexes | CreateTime | FinishTime | TransactionId | State | Msg | Progress |
+---------------+-----------+---------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------+-------------------------+---------------+----------+------+----------+
| 1764392359610 | sift_1M | sift_1M | [ADD INDEX idx_test_ann (`embedding`) USING ANN PROPERTIES("dim" = "128", "index_type" = "ivf", "metric_type" = "l2_distance", "nlist" = "1024")], | 2025-12-01 14:18:22.360 | 2025-12-01 14:18:27.885 | 5036 | FINISHED | | NULL |
+---------------+-----------+---------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------+-------------------------+---------------+----------+------+----------+
mysql> SHOW DATA ALL FROM sift_1M;
+-----------+-----------+--------------+----------+----------------+---------------+----------------+-----------------+----------------+-----------------+
| TableName | IndexName | ReplicaCount | RowCount | LocalTotalSize | LocalDataSize | LocalIndexSize | RemoteTotalSize | RemoteDataSize | RemoteIndexSize |
+-----------+-----------+--------------+----------+----------------+---------------+----------------+-----------------+----------------+-----------------+
| sift_1M | sift_1M | 10 | 1000000 | 671.084 MB | 170.093 MB | 500.991 MB | 0.000 | 0.000 | 0.000 |
| | Total | 10 | | 671.084 MB | 170.093 MB | 500.991 MB | 0.000 | 0.000 | 0.000 |
+-----------+-----------+--------------+----------+----------------+---------------+----------------+-----------------+----------------+-----------------+
Drop the index
During parameter tuning, you often need to test different parameter combinations to ensure recall. Use DROP INDEX to manage indexes flexibly:
ALTER TABLE sift_1M DROP INDEX idx_test_ann;
Run vector queries
ANN indexes accelerate both TopN search and range search.
For high-dimensional vectors, consider prepared statements to reduce repeated SQL parsing. Measure their effect on your workload.
The following query uses the sift_1M table created above. Replace the sample vector with a 128-dimensional query vector from the same embedding scheme as the stored data:
SELECT id, l2_distance_approximate(embedding, array_repeat(0.1, 128)) AS distance
FROM sift_1M
ORDER BY distance
LIMIT 10;
Compare the result against l2_distance to measure recall. Actual results depend on the loaded vectors and index parameters.
Recall optimization
The core metric of vector search is recall. Any performance figure is meaningful only when recall is acceptable. The main factors that affect recall are:
- IVF index parameters (
nlist) and query parameters (nprobe) - Vector quantization in the index
- The size and number of Segments
This section discusses items 1 and 3. Vector quantization is covered in other documents.
Index hyperparameters: nlist and ivf_nprobe
IVF uses key parameters during index building and at query time:
Index building phase:
- Clustering: Use a clustering algorithm (such as k-means) to partition the vectors into
nlistclusters, then compute and store the centroid of each cluster. - Vector assignment: Assign each vector to the cluster whose centroid is closest to it, and add the vector to the corresponding inverted list.
Query phase:
- Cluster selection: Compute the distance from the query vector to all
nlistcentroids and pick the closestnprobeclusters. - Within-cluster exhaustive search: Compare vectors one by one inside the selected
nprobeclusters to find the nearest neighbors.
| Parameter | Purpose | Effect | Core 26.1.3 source value |
|---|---|---|---|
nlist | Number of clusters (inverted lists) | A larger value gives finer granularity and faster search, but increases clustering cost and makes neighbors more likely to be scattered across different clusters | Required explicitly; no SQL default |
nprobe | Number of clusters probed at query time | A larger value gives higher recall and higher latency; a smaller value is faster but more likely to miss results | ivf_nprobe initializes to 32 |
Measured results on the SIFT_1M dataset:
| nlist | nprobe | recall@100 |
|---|---|---|
| 1024 | 64 | 0.9542 |
| 1024 | 32 | 0.9034 |
| 1024 | 16 | 0.8299 |
| 1024 | 8 | 0.7337 |
| 512 | 32 | 0.9384 |
| 512 | 16 | 0.8763 |
| 512 | 8 | 0.7869 |
Select hyperparameters
Although the exact optimal parameters cannot be determined in advance, you can choose them systematically as follows:
- Create a temporary table
table_multi_indexwithout indexes that contains 2 to 3 vector columns. - Load data into this table through Stream Load or another method.
- Run
CREATE INDEXandBUILD INDEXwith different parameters on each vector column. - Compare the recall of each column and pick the parameter combination that fits best.
Example:
ALTER TABLE tbl DROP INDEX idx_embedding;
CREATE INDEX idx_embedding ON tbl (`embedding`) USING ANN PROPERTIES (
"index_type"="ivf",
"metric_type"="inner_product",
"dim"="768",
"nlist"="1024"
);
BUILD INDEX ON tbl;
Number of rows covered by the index
Data in a VeloDB Cloud internal table is organized in the following hierarchy:
- Table to Tablet: Distributed evenly across N Tablets by the bucket key (the basic unit of data migration and rebalancing).
- Tablet to Rowset: Each load or Compaction adds a new Rowset (the unit of version management).
- Rowset to Segment: The actual data is stored in Segment files.
ANN indexes are built per segment. Ingestion and compaction can change segment sizes. In VeloDB Cloud, the service manages write_buffer_size, vertical_compaction_max_segment_size, and compaction scheduling. Use workload measurements and contact Support if segment sizing needs investigation.
Each combination of IVF index parameters can effectively cover only a limited amount of data. When the number of rows in a Segment exceeds a threshold, recall drops.
Tip:
Use
SHOW TABLETS FROM <table>to check the Compaction status of a table. Open the corresponding URL to see the number of Segments.
Effect of compaction on recall
Compaction merges multiple small Segments into larger ones, which makes index parameters that were tuned for smaller data sizes ineffective and reduces recall.
Compaction can rebuild indexes over different segment sizes and change recall or latency. Re-test after substantial data or compaction changes.
For a one-time bulk load, evaluate the compaction schedule and index-build timing together:
- Validate recall with index parameters suited to the resulting segment sizes. Full compaction alone does not guarantee stable recall.
- Consider whether index construction would soon be repeated by compaction. Compare the total build and compaction cost before adding a full compaction; lower overall write amplification is workload dependent.
In VeloDB Cloud, compaction scheduling is managed by the service. Ask VeloDB Cloud support to assess whether compaction should precede the index build for your workload. A manual full compaction is not a general prerequisite for BUILD INDEX.
Query performance
Load index files before concurrent queries
The VeloDB Cloud ANN index is implemented on top of Meta's open-source faiss. An IVF index must be fully loaded into memory before it can accelerate queries.
Best practice: Run a cold query before high-concurrency queries to ensure that all relevant Segment index files have been loaded. Otherwise, performance on the first query degrades significantly.
Memory footprint and performance
An IVF index without quantization compression occupies about 1.02 times the memory of the vectors it indexes.
For example, the memory footprint of an IVF FLAT index for a 128-dimensional, 1M-row dataset is approximately:
128 * 4 * 1,000,000 * 1.02 ≈ 500 MB
Reference values:
| dim | rows | Estimated memory |
|---|---|---|
| 128 | 1M | 500 MB |
| 768 | 1M | 2.9 GB |
For in-memory IVF, size the cluster for the indexes queried concurrently plus query and build overhead. Otherwise, frequent IO on index files causes severe query performance degradation.
Benchmark
Benchmark scope: The commands below reproduce an upstream self-managed Apache Doris setup. The full release and hardware configuration is not provided. They use loopback endpoints and are not warehouse connection instructions. VeloDB Cloud manages frontend and compute-node deployment.
Test framework: VectorDBBench.
Performance768D1M
Benchmark commands:
# load
NUM_PER_BATCH=1000000 python3 -m vectordbbench doris --host 127.0.0.1 --port 9030 --case-type Performance768D1M --db-name Performance768D1M --stream-load-rows-per-batch 500000 --index-prop index_type=ivf,nlist=1024 --skip-search-serial --skip-search-concurrent
# search
NUM_PER_BATCH=1000000 python3 -m vectordbbench doris --host 127.0.0.1 --port 9030 --case-type Performance768D1M --db-name Performance768D1M --search-concurrent --search-serial --num-concurrency 10,40,80 --stream-load-rows-per-batch 500000 --index-prop index_type=ivf,nlist=1024 --session-var ivf_nprobe=64 --skip-load --skip-drop-old
FAQ
Q1: How should you choose between IVF and HNSW? IVF is suitable for large-scale scenarios that have sufficient memory and need to balance build cost with query latency. HNSW has an advantage in query latency but a higher memory footprint. See the HNSW documentation for details.
Q2: Why is recall still low after BUILD INDEX?
Common causes include: nprobe is set too low, Segments are too large so the index does not cover them well, or parameter tuning no longer fits the segment sizes. See Recall Optimization.
Q3: Why run a cold query before high-concurrency queries? The IVF index must be fully loaded into memory to accelerate queries. The cold query warms the cache by loading the index from disk into memory, which can reduce subsequent query latency while the index remains cached.
Q4: How should I choose nlist and inspect ivf_nprobe?
nlist must be supplied explicitly when creating an IVF index. 1024 is an example value. The Core 26.1.3 source initializes the session variable ivf_nprobe to 32; check the effective value with SHOW VARIABLES LIKE 'ivf_nprobe'. Adjust based on your actual data size and recall requirements following Hyperparameter Selection in Practice.
Q5: Does DROP INDEX release memory immediately?
DROP INDEX removes the index definition, and the index files are cleaned up afterwards. During parameter tuning, use it together with the CREATE INDEX and BUILD INDEX workflow.
Troubleshooting
| Symptom | Possible cause | Solution |
|---|---|---|
| Recall is significantly lower than expected | ivf_nprobe is too low or parameters do not fit the segment sizes | Tune ivf_nprobe and nlist; compare recall after major ingestion or compaction changes |
| First query has very high latency, subsequent queries are normal | The index has not yet been loaded into memory (cold load) | Run a cold query to warm up before high-concurrency queries |
| Cluster memory is tight and query performance degrades | The index does not fully reside in memory, causing frequent IO | Scale cluster capacity or evaluate quantization and disk-backed IVF |
BUILD INDEX does not finish for a long time | The task is asynchronous and the data volume is large | Check progress with SHOW BUILD INDEX WHERE TableName = "<tbl>" |
| Data ingestion becomes slow | The index is built synchronously at table creation | Switch to the CREATE INDEX + BUILD INDEX approach to build asynchronously |