Skip to main content

hermes_core/segment/builder/
config.rs

1//! Configuration and statistics types for segment builder
2
3use std::path::PathBuf;
4
5use crate::compression::CompressionLevel;
6
7/// Statistics about segment builder state
8#[derive(Debug, Clone, Default)]
9pub struct SegmentBuilderStats {
10    /// Number of documents indexed
11    pub num_docs: u32,
12    /// Number of unique terms in the inverted index
13    pub unique_terms: usize,
14    /// Total postings in memory (across all terms)
15    pub postings_in_memory: usize,
16    /// Number of interned strings
17    pub interned_strings: usize,
18    /// Size of doc_field_lengths vector
19    pub doc_field_lengths_size: usize,
20    /// Estimated total memory usage in bytes
21    pub estimated_memory_bytes: usize,
22    /// Memory breakdown by component
23    pub memory_breakdown: MemoryBreakdown,
24    /// Documents indexed into a dynamically tokenized field
25    /// (`text<lex(by: ...)>`) without any value in the hint field, so the
26    /// tokenizer's default applied.
27    pub unhinted_dynamic_docs: u64,
28}
29
30/// Detailed memory breakdown by component
31#[derive(Debug, Clone, Default)]
32pub struct MemoryBreakdown {
33    /// Postings memory (CompactPosting structs)
34    pub postings_bytes: usize,
35    /// Inverted index HashMap overhead
36    pub index_overhead_bytes: usize,
37    /// Term interner memory
38    pub interner_bytes: usize,
39    /// Document field lengths
40    pub field_lengths_bytes: usize,
41    /// Dense vector storage
42    pub dense_vectors_bytes: usize,
43    /// Number of dense vectors
44    pub dense_vector_count: usize,
45    /// Sparse vector storage
46    pub sparse_vectors_bytes: usize,
47    /// Position index storage
48    pub position_index_bytes: usize,
49}
50
51/// Configuration for segment builder
52#[derive(Clone)]
53pub struct SegmentBuilderConfig {
54    /// Directory for temporary spill files
55    pub temp_dir: PathBuf,
56    /// Compression level for document store
57    pub compression_level: CompressionLevel,
58    /// Width of the document-store compression pool. Concurrent builders with
59    /// the same width share one process-wide executor.
60    pub num_compression_threads: usize,
61    /// Initial capacity for term interner
62    pub interner_capacity: usize,
63    /// Initial capacity for posting lists hashmap
64    pub posting_map_capacity: usize,
65    /// Term-dictionary compression / bloom configuration (from the index
66    /// optimization mode).
67    pub optimization: crate::structures::IndexOptimization,
68    /// Posting block codec (`docs/posting-codecs.md`).
69    pub posting_codec: crate::structures::PostingCodec,
70}
71
72impl Default for SegmentBuilderConfig {
73    fn default() -> Self {
74        Self {
75            #[cfg(feature = "native")]
76            temp_dir: std::env::temp_dir(),
77            #[cfg(not(feature = "native"))]
78            temp_dir: PathBuf::from("/tmp"),
79            compression_level: CompressionLevel(3),
80            #[cfg(feature = "native")]
81            num_compression_threads: crate::default_compression_threads(),
82            #[cfg(not(feature = "native"))]
83            num_compression_threads: 1,
84            interner_capacity: 1_000_000,
85            posting_map_capacity: 500_000,
86            optimization: crate::structures::IndexOptimization::default(),
87            posting_codec: crate::structures::PostingCodec::default(),
88        }
89    }
90}