RoanHeNaN opened a new pull request, #71320:
URL: https://github.com/apache/doris/pull/71320
### Background
An IVF / IVF_ON_DISK ANN index takes one table-level `nlist`, but faiss
builds the index per segment, so every segment gets exactly `nlist` lists
whatever its row count. At query time `ivf_nprobe` is an absolute number of
lists to probe in every segment.
### What problem does this PR solve?
Issue Number: close #71313
Related PR: None
PR Type: Feature
Problem Summary:
Segment sizes differ by orders of magnitude (fresh loads write small
segments, compaction writes large ones), so a fixed `nlist` makes lists nearly
empty in small segments and the centroid table, which is always scanned and
kept in memory, can be larger than the data. A fixed `ivf_nprobe` probes a
different fraction of each segment. This PR adds an index property
`ivf_cluster_rows` (vectors per list, like Elasticsearch DiskBBQ's
`cluster_size`) so each segment sizes its own `nlist`, and a session variable
`ivf_nprobe_ratio` that probes a fraction of each segment's lists. Indexes that
set `nlist` behave exactly as before.
### Details
- **Scope:** FE property validation and session variable, thrift query
option, BE writer (per-segment nlist) and search (per-segment nprobe), ANN
result cache key, BE unit tests, regression tests.
- **Design:**
- `ivf_cluster_rows` (IVF / IVF_ON_DISK only, mutually exclusive with
`nlist`, range [1, 65536]). The writer already buffers all vectors of a segment
until `finish()`, so the faiss IVF index is rebuilt there with `nlist =
round(rows / ivf_cluster_rows)`, clamped to [1, 65536], before training.
- When neither `nlist` nor `ivf_cluster_rows` is given, FE writes
`ivf_cluster_rows = 384` into the index properties (the same pattern NGRAM_BF
uses for its defaults). The stored metadata and `SHOW CREATE TABLE` state the
value, and a BE upgrade cannot change how existing indexes are built. The BE
keeps the same default only for metadata that lacks the key.
- `ivf_nprobe_ratio` (double, [0, 1], default 0) is sent as
`TQueryOptions.ivf_nprobe_ratio`. When > 0, each segment probes `ceil(ratio *
nlist)` lists, using the loaded faiss index's real `nlist`, clamped to [1,
nlist]. It applies to top-n and range search, and it is part of the ANN result
cache key.
- **Usage:**
```sql
INDEX idx (emb) USING ANN PROPERTIES("index_type"="ivf_on_disk",
"metric_type"="inner_product",
"dim"="768", "quantizer"="sq8", "ivf_cluster_rows"="384")
SET ivf_nprobe_ratio = 0.05; -- probe 5% of the lists of every segment
```
- **Default behavior:** creating an IVF index without `nlist` used to fail
with "nlist of ann index must be specified"; it now succeeds and uses
`ivf_cluster_rows = 384`. `ivf_nprobe_ratio` defaults to 0, so queries keep
using `ivf_nprobe`.
- **Compatibility:** existing indexes all have `nlist` (it was required), so
they are unchanged. The new thrift field is optional; a BE that does not
receive it uses 0. Segments built with `ivf_cluster_rows` are ordinary faiss
IVF indexes, so the read path is unchanged.
### Testing
- BE unit tests (`ann_index_writer_test.cpp`): `adaptive_ivf_nlist` rounding
and clamping; the default and explicit `ivf_cluster_rows`; a fixed `nlist` and
HNSW not using it; a segment rebuilt with the derived `nlist` and the full
init/add/finish workflow; `effective_ivf_nprobe` ratio mapping, ratio 0
fallback, and clamping to [1, nlist].
- Regression test `ann_index_p0/ivf_cluster_rows_test`: property validation,
the default persisted in `SHOW CREATE TABLE`, `ivf_nprobe_ratio` validation,
ratio 1.0 equals exact search, ratio r returns the same rows as `ivf_nprobe =
ceil(r * nlist)`. Three existing suites that expected the "nlist must be
specified" error now check the persisted default.
- Manual: 5M x 2048-d table, 2 x 50k-row segments with the default: every
segment logs `nlist=130`, and `ivf_nprobe_ratio` 0.02 / 0.1 / 0.5 / 1.0
returned the same rows as `ivf_nprobe` 3 / 13 / 65 / 130 (recall@10 0.817 /
0.960 / 0.993 / 0.997).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]