1
2
3
4
5
6
7
8
9
10
11
12
13
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use crate::segment::common::memory_usage::{ComponentMemoryUsage, FileStorageIntent, MemoryReporter};
use crate::segment::index::vector_index_base::{VectorIndex as _, VectorIndexEnum, VectorIndexRead as _};
impl MemoryReporter for VectorIndexEnum {
fn memory_usage(&self) -> ComponentMemoryUsage {
match self {
// Plain index: no files, no extra memory (searches storage directly)
VectorIndexEnum::Plain(_) => ComponentMemoryUsage::empty(),
// HNSW: graph files, intent depends on how the links are actually held
VectorIndexEnum::Hnsw(index) => {
let links_heap_bytes = index.links_heap_size_bytes() as u64;
if links_heap_bytes > 0 {
// Links are materialized in heap RAM (freshly built index,
// or a non-borrowable universal-IO backend): files are
// persistence only, not expected to be in page cache.
ComponentMemoryUsage::from_files_and_ram(
index.files(),
FileStorageIntent::OnDisk,
links_heap_bytes,
)
} else {
// Links are backed by a live mmap handle: residency is
// tracked via the page cache, intent depends on on_disk config.
let intent = if index.is_on_disk() {
FileStorageIntent::OnDisk
} else {
FileStorageIntent::Cached
};
ComponentMemoryUsage::from_files(index.files(), intent)
}
}
// Sparse RAM variants: inverted index is deserialized into heap.
// Files are persistence only (OnDisk), actual RAM is extra_ram_bytes.
VectorIndexEnum::SparseRam(index) => ComponentMemoryUsage::from_files_and_ram(
index.files(),
FileStorageIntent::OnDisk,
index.size_of_searchable_vectors_in_bytes() as u64,
),
VectorIndexEnum::SparseCompressedImmutableRamF32(index) => {
ComponentMemoryUsage::from_files_and_ram(
index.files(),
FileStorageIntent::OnDisk,
index.size_of_searchable_vectors_in_bytes() as u64,
)
}
VectorIndexEnum::SparseCompressedImmutableRamF16(index) => {
ComponentMemoryUsage::from_files_and_ram(
index.files(),
FileStorageIntent::OnDisk,
index.size_of_searchable_vectors_in_bytes() as u64,
)
}
VectorIndexEnum::SparseCompressedImmutableRamU8(index) => {
ComponentMemoryUsage::from_files_and_ram(
index.files(),
FileStorageIntent::OnDisk,
index.size_of_searchable_vectors_in_bytes() as u64,
)
}
// Sparse mmap variants: inverted index is mmap'd but not populated
// (loaded with populate=false), relies on OS demand-paging
VectorIndexEnum::SparseCompressedMmapF32(index) => {
ComponentMemoryUsage::from_files(index.files(), FileStorageIntent::OnDisk)
}
VectorIndexEnum::SparseCompressedMmapF16(index) => {
ComponentMemoryUsage::from_files(index.files(), FileStorageIntent::OnDisk)
}
VectorIndexEnum::SparseCompressedMmapU8(index) => {
ComponentMemoryUsage::from_files(index.files(), FileStorageIntent::OnDisk)
}
}
}
}