Commit 8fb4d42
Migrate disk PQ flat scan to flat API (#1341)
- [x] Does this PR have a descriptive title that could go in our release
notes? **Yes.**
- [ ] Does this PR add any new dependencies? **No.**
- [ ] Does this PR modify any existing APIs? **No.** The query-aware
flat-search API was introduced separately in #1359; this PR adopts it in
`diskann-disk`.
- [x] Is the change to the API backwards compatible? **Yes.** Existing
disk search modes and result semantics are preserved.
- [x] Should this result in any changes to our documentation, either
updating existing docs or adding new ones? **Yes.** The affected
implementation rustdoc is updated.
#### Reference Issues/PRs
Built on the query-aware flat-search API merged in #1359.
#### What does this implement/fix? Briefly explain your changes.
- Replaces the disk-specific manual PQ flat-scan pipeline with the
shared flat k-NN API.
- Implements `DistancesUnordered` on `DiskAccessor` to expose complete,
batched PQ-distance scanning.
- Initializes query-dependent PQ state after every pooled scratch
checkout.
- Preserves scan-time filtering before approximate top-k selection and
full-precision reranking afterward.
- Preserves the existing pooled scratch and indexed-vector result
behavior across graph and flat search modes.
The disk backend constructs a query-aware `DiskAccessor` and passes it
directly to `flat::knn_search`. The generic flat layer now owns top-k
selection, comparison accounting, error escalation, and post-processing.
`DiskAccessor` continues to own disk-specific PQ preprocessing,
batching, filtering, data access, and distance computation.
#### Any other comments?
This PR has been rebased onto `main` after #1359 merged. Its diff is
limited to the two `diskann-disk` implementation files.
#### Architecture simplification
Before this change, disk flat search manually coordinated filtering,
batching, PQ-distance collection, top-k selection, comparison
accounting, and post-processing inside `DiskANNIndex::flat_search`.
Graph and flat search already used the same `DiskAccessor` and scratch
pool, but the flat algorithm duplicated orchestration now provided by
the shared flat API.
```mermaid
flowchart TB
subgraph Before["Before: disk-specific flat orchestration"]
direction LR
F1["FlatScan"] --> M["DiskANNIndex::flat_search"]
M --> FI["filter IDs"]
FI --> B["manual batch loop"]
B --> PQ1["DiskAccessor::pq_distances"]
PQ1 --> K1["local NeighborPriorityQueue"]
K1 --> PP1["disk post-processor"]
end
subgraph After["After: shared flat orchestration"]
direction LR
F2["FlatScan"] --> K2["flat::knn_search"]
K2 --> DU["DiskAccessor<br/>DistancesUnordered"]
DU --> PQ2["filtered, batched PQ scan"]
K2 --> TK["shared top-k · stats · errors"]
TK --> PP2["RerankAndFilter"]
end
G["Graph search"] --> SA["DiskAccessor<br/>SearchAccessor"]
DU --> S["pooled DiskSearchScratch<br/>per-query PQ preparation"]
SA --> S
```
`DiskAccessor` now exposes the disk scan through `DistancesUnordered`,
allowing `flat::knn_search` to drive the common k-NN workflow while
graph traversal continues to use the existing `SearchAccessor`
implementation. Both paths preserve their distinct filtering stages and
share the same pooled query-state lifecycle.
---------
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>1 parent 149ce76 commit 8fb4d42
3 files changed
Lines changed: 307 additions & 148 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
50 | 22 | | |
51 | 23 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
62 | 33 | | |
63 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
64 | 56 | | |
0 commit comments