mirror of
https://github.com/qdrant/qdrant.git
synced 2026-08-06 10:00:58 -05:00
* Introduce EdgeShardConfig for edge shard
- Add EdgeShardConfig and EdgeOptimizersConfig in lib/edge/src/config.rs
- Segment config (vector_data, sparse_vector_data, payload_storage_type)
- Global hnsw_config and per-vector HNSW in segment config
- Optimizer params: deleted_threshold, vacuum_min_vector_number,
default_segment_number, max_segment_size, indexing_threshold,
prevent_unoptimized (excludes memmap_threshold, flush_interval_sec,
max_optimization_threads)
- Persist/load as edge_config.json in shard path
- EdgeShard uses RwLock<EdgeShardConfig>; load() accepts Option<EdgeShardConfig>,
falls back to file or infer from segments; compatibility checked on load
- load_with_segment_config() for backward compatibility (SegmentConfig -> EdgeShardConfig)
- optimize() uses EdgeShardConfig for hnsw and optimizer thresholds
- Public methods: set_hnsw_config(), set_vector_hnsw_config(), set_optimizers_config()
(update and persist)
- Python and examples use load_with_segment_config with existing config API
Made-with: Cursor
* Refactor EdgeShardConfig: user-facing params only, config module
- Replace SegmentConfig inside EdgeShardConfig with user-facing fields:
- on_disk_payload (bool) instead of payload_storage_type
- vectors: HashMap<VectorNameBuf, EdgeVectorParams> with on_disk per vector,
no per-vector quantization; global quantization_config only
- sparse_vectors: HashMap<VectorNameBuf, EdgeSparseVectorParams> with on_disk
- EdgeVectorParams / EdgeSparseVectorParams use on_disk (bool) instead of
storage_type; conversion to VectorDataConfig/SparseVectorDataConfig in
to_segment_config()
- Add config module: mod.rs, optimizers.rs, vectors.rs, shard.rs
- from_segment_config(&SegmentConfig) fills all inferrable params
- to_segment_config() builds SegmentConfig for segments and optimize()
- load_with_segment_config takes Option<SegmentConfig>, uses from_segment_config
Made-with: Cursor
* Move optimizer threshold helpers to shard crate
- Add get_number_segments, get_indexing_threshold_kb, get_max_segment_size_kb,
get_deferred_points_threshold_bytes in shard::optimizers::config
- Collection OptimizersConfig and edge EdgeOptimizersConfig delegate to these
- Single place for threshold logic; collection and edge use shard helpers
Made-with: Cursor
* Use destructuring in config conversions to avoid missing new fields
- EdgeVectorParams: destructure VectorDataConfig in from_*, destructure self in to_vector_data_config
- EdgeSparseVectorParams: destructure SparseVectorDataConfig and SparseIndexConfig in from_*, destructure self in to_sparse_vector_data_config
- EdgeShardConfig: destructure SegmentConfig in from_segment_config, destructure self in to_segment_config
Adding new fields to source structs will now cause compile errors until conversions are updated.
Made-with: Cursor
* refactor: centralize on_disk_payload→payload_storage_type, on_disk→storage_type, and appendable quantization logic
- PayloadStorageType::from_on_disk_payload(bool) in segment (Mmap/InRamMmap)
- VectorStorageType::from_on_disk(bool) in segment (ChunkedMmap/InRamChunkedMmap)
- QuantizationConfig::for_appendable_segment(Option<&Self>) in segment (feature flag + supports_appendable)
- collection: use from_on_disk_payload in non-rocksdb branch
- edge shard/vectors: use new helpers; remove duplicated conditionals
- shard optimizers: use from_on_disk and for_appendable_segment
Made-with: Cursor
* refactor(edge): use EdgeShardConfig directly, drop segment_config
- Add plain_segment_config() for create_appendable_segment (no HNSW)
- Add segment_optimizer_config() built from EdgeShardConfig for blocking optimizers
- Add vector_data_config(name) for query/MMR
- build_blocking_optimizers: use segment_optimizer_config() instead of SegmentConfig
- create_appendable_segment: use plain_segment_config()
- search/query: use config().vectors and vector_data_config() instead of segment_config()
- Remove segment_config() from EdgeShardConfig and EdgeShard
- Add to_plain_vector_data_config on EdgeVectorParams
Made-with: Cursor
* [manual] review changes
* refactor(edge-py): wrap EdgeShardConfig, add EdgeVectorParams/EdgeSparseVectorParams
- PyEdgeConfig now wraps EdgeShardConfig (vectors, sparse_vectors, on_disk_payload, etc.)
- PyEdgeVectorParams / PyEdgeSparseVectorParams wrap edge config types
- PyEdgeOptimizersConfig for optional optimizer settings
- EdgeShard.load() uses EdgeShardConfig; edge::config made pub for Python crate
- cargo fmt + clippy (remove map_identity)
Made-with: Cursor
* refactor(edge-py): simplify config API, remove unused Py* types, add EdgeConfig
- Remove unused PyPayloadStorageType, PyVectorDataConfig, PyVectorStorageType,
PySparseVectorDataConfig, PySparseVectorStorageType from Python bindings
- Move PyEdgeOptimizersConfig to lib/edge/python/src/config/optimizers.rs
- Update qdrant_edge.pyi: EdgeConfig with vectors/sparse_vectors,
EdgeVectorParams, EdgeSparseVectorParams, EdgeOptimizersConfig
- Update examples (common.py, repr.py) to use new config API
- Run cargo fmt
Made-with: Cursor
* [manual] review changes
* [manual] review changes
* [manual] fix test
* Address CodeRabbit review comments for PR 8322 (#8324)
* Address CodeRabbit review comments for PR 8322
- Python examples: explicit imports (repr.py, common.py) and new EdgeConfig API
- HnswIndexConfig: add max_indexing_threads param and property in .pyi and Rust bindings
- EdgeConfig: make vectors optional for sparse-only configs; validate at least one of vectors/sparse_vectors
- EdgeShardConfig::load: use try_exists(), propagate I/O errors
- from_segment_config: infer hnsw_config from per-vector HNSW when all agree
- EdgeShard setters: atomic clone-mutate-save-then-replace; persist config save errors
- Segment compat: prefix vector name in error messages; resolve None datatype to Float32
- max_indexing_threads: preserve 0 (auto) sentinel in trait default; remove per-optimizer overrides
- SegmentOptimizerConfig:🆕 build plain and optimizer maps in single pass
- config_mismatch_optimizer tests: use VectorNameBuf::from() instead of .into()
- vectors.rs: doc updates for per-vector quantization
Made-with: Cursor
* Address @generall review: SaveOnDisk for config, resolve num_rayon_threads in optimizer
- Use SaveOnDisk<EdgeShardConfig> for EdgeShard config (generall: 'We have SaveOnDisk struct for this')
- Create via SaveOnDisk::new() after resolving config; setters use .write() for atomic persist
- set_vector_hnsw_config: clone then mutate then write (fallible setter)
- max_indexing_threads: resolve 0 (auto) via num_rayon_threads inside impl (generall: 'proper solution would be to resolve num_rayon_threads inside the optimizer impl')
- max_indexing_threads_sentinel_aware() now returns Some(num_rayon_threads(raw)) so callers get actual thread count
Made-with: Cursor
* [manual] reorganize num_rayon_threads -> get_num_indexing_threads to better account per-vector configuration
---------
Co-authored-by: Cursor Agent <agent@cursor.com>
Co-authored-by: generall <andrey@vasnetsov.com>
* update docstring and pyi
* fmt
* fmt
* clipy
---------
Co-authored-by: Cursor Agent <agent@cursor.com>
Co-authored-by: generall <andrey@vasnetsov.com>
150 lines
5.4 KiB
Rust
150 lines
5.4 KiB
Rust
use std::collections::HashMap;
|
|
use std::sync::Arc;
|
|
use std::sync::atomic::AtomicBool;
|
|
|
|
use common::budget::ResourcePermit;
|
|
use common::counter::hardware_counter::HardwareCounterCell;
|
|
use common::flags::FeatureFlags;
|
|
use common::progress_tracker::ProgressTracker;
|
|
use criterion::{BatchSize, Criterion, criterion_group, criterion_main};
|
|
use rand::prelude::StdRng;
|
|
use rand::{Rng, SeedableRng};
|
|
use segment::data_types::vectors::{DEFAULT_VECTOR_NAME, only_default_multi_vector};
|
|
use segment::entry::entry_point::SegmentEntry;
|
|
use segment::fixtures::payload_fixtures::random_multi_vector;
|
|
use segment::index::VectorIndex;
|
|
use segment::index::hnsw_index::get_num_indexing_threads;
|
|
use segment::index::hnsw_index::hnsw::{HNSWIndex, HnswIndexOpenArgs};
|
|
use segment::segment_constructor::{VectorIndexBuildArgs, build_segment};
|
|
use segment::types::Distance::{Dot, Euclid};
|
|
use segment::types::{
|
|
Distance, HnswConfig, HnswGlobalConfig, Indexes, MultiVectorConfig, SegmentConfig,
|
|
SeqNumberType, VectorDataConfig, VectorStorageType,
|
|
};
|
|
use tempfile::Builder;
|
|
|
|
#[cfg(not(target_os = "windows"))]
|
|
mod prof;
|
|
|
|
const NUM_POINTS: usize = 10_000;
|
|
const NUM_VECTORS_PER_POINT: usize = 16;
|
|
const VECTOR_DIM: usize = 128;
|
|
const TOP: usize = 10;
|
|
|
|
// intent: bench `search` without filter
|
|
fn multi_vector_search_benchmark(c: &mut Criterion) {
|
|
let mut group = c.benchmark_group("multi-vector-search-group");
|
|
let mut rnd = StdRng::seed_from_u64(42);
|
|
|
|
let hnsw_index = make_segment_index(&mut rnd, Dot);
|
|
group.bench_function("hnsw-multivec-search-dot", |b| {
|
|
b.iter_batched(
|
|
|| random_multi_vector(&mut rnd, VECTOR_DIM, NUM_VECTORS_PER_POINT).into(),
|
|
|query| {
|
|
let results = hnsw_index
|
|
.search(&[&query], None, TOP, None, &Default::default())
|
|
.unwrap();
|
|
assert_eq!(results[0].len(), TOP);
|
|
},
|
|
BatchSize::SmallInput,
|
|
)
|
|
});
|
|
|
|
let hnsw_index = make_segment_index(&mut rnd, Euclid);
|
|
group.bench_function("hnsw-multivec-search-euclidean", |b| {
|
|
b.iter_batched(
|
|
|| random_multi_vector(&mut rnd, VECTOR_DIM, NUM_VECTORS_PER_POINT).into(),
|
|
|query| {
|
|
let results = hnsw_index
|
|
.search(&[&query], None, TOP, None, &Default::default())
|
|
.unwrap();
|
|
assert_eq!(results[0].len(), TOP);
|
|
},
|
|
BatchSize::SmallInput,
|
|
)
|
|
});
|
|
|
|
group.finish();
|
|
}
|
|
|
|
fn make_segment_index<R: Rng + ?Sized>(rng: &mut R, distance: Distance) -> HNSWIndex {
|
|
let stopped = AtomicBool::new(false);
|
|
let segment_dir = Builder::new().prefix("data_dir").tempdir().unwrap();
|
|
let hnsw_dir = Builder::new().prefix("hnsw_dir").tempdir().unwrap();
|
|
|
|
let segment_config = SegmentConfig {
|
|
vector_data: HashMap::from([(
|
|
DEFAULT_VECTOR_NAME.to_owned(),
|
|
VectorDataConfig {
|
|
size: VECTOR_DIM,
|
|
distance,
|
|
storage_type: VectorStorageType::default(),
|
|
index: Indexes::Plain {},
|
|
quantization_config: None,
|
|
multivector_config: Some(MultiVectorConfig::default()), // uses multivec config
|
|
datatype: None,
|
|
},
|
|
)]),
|
|
sparse_vector_data: Default::default(),
|
|
payload_storage_type: Default::default(),
|
|
};
|
|
|
|
let hw_counter = HardwareCounterCell::new();
|
|
|
|
let mut segment = build_segment(segment_dir.path(), &segment_config, None, true).unwrap();
|
|
for n in 0..NUM_POINTS {
|
|
let idx = (n as u64).into();
|
|
let multi_vec = random_multi_vector(rng, VECTOR_DIM, NUM_VECTORS_PER_POINT);
|
|
let named_vectors = only_default_multi_vector(&multi_vec);
|
|
segment
|
|
.upsert_point(n as SeqNumberType, idx, named_vectors, &hw_counter)
|
|
.unwrap();
|
|
}
|
|
|
|
// build HNSW index
|
|
let hnsw_config = HnswConfig {
|
|
m: 8,
|
|
ef_construct: 16,
|
|
full_scan_threshold: 10, // low value to trigger index usage by default
|
|
max_indexing_threads: 0,
|
|
on_disk: None,
|
|
payload_m: None,
|
|
inline_storage: None,
|
|
};
|
|
let permit_cpu_count = get_num_indexing_threads(hnsw_config.max_indexing_threads);
|
|
let permit = Arc::new(ResourcePermit::dummy(permit_cpu_count as u32));
|
|
let vector_storage = &segment.vector_data[DEFAULT_VECTOR_NAME].vector_storage;
|
|
let quantized_vectors = &segment.vector_data[DEFAULT_VECTOR_NAME].quantized_vectors;
|
|
let hnsw_index = HNSWIndex::build(
|
|
HnswIndexOpenArgs {
|
|
path: hnsw_dir.path(),
|
|
id_tracker: segment.id_tracker.clone(),
|
|
vector_storage: vector_storage.clone(),
|
|
quantized_vectors: quantized_vectors.clone(),
|
|
payload_index: segment.payload_index.clone(),
|
|
hnsw_config,
|
|
},
|
|
VectorIndexBuildArgs {
|
|
permit,
|
|
old_indices: &[],
|
|
gpu_device: None,
|
|
stopped: &stopped,
|
|
rng,
|
|
hnsw_global_config: &HnswGlobalConfig::default(),
|
|
feature_flags: FeatureFlags::default(),
|
|
progress: ProgressTracker::new_for_test(),
|
|
},
|
|
)
|
|
.unwrap();
|
|
hnsw_index.populate().unwrap();
|
|
hnsw_index
|
|
}
|
|
|
|
criterion_group! {
|
|
name = benches;
|
|
config = Criterion::default().with_profiler(prof::FlamegraphProfiler::new(100));
|
|
targets = multi_vector_search_benchmark
|
|
}
|
|
|
|
criterion_main!(benches);
|