vxdb-server 0.4.1__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/Cargo.lock +3 -3
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/Cargo.toml +1 -1
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/PKG-INFO +1 -1
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-core/src/collection.rs +23 -2
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-core/src/index/flat.rs +7 -1
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-core/src/index/hnsw.rs +62 -3
- vxdb_server-0.5.0/crates/vxdb-core/src/index/mod.rs +33 -0
- vxdb_server-0.4.1/crates/vxdb-core/src/index/mod.rs +0 -16
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/README.md +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-core/Cargo.toml +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-core/src/distance/cosine.rs +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-core/src/distance/dot.rs +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-core/src/distance/euclidean.rs +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-core/src/distance/mod.rs +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-core/src/error.rs +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-core/src/filter.rs +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-core/src/hybrid.rs +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-core/src/lib.rs +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-core/src/storage/metadata.rs +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-core/src/storage/mmap.rs +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-core/src/storage/mod.rs +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-core/src/storage/persistent.rs +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-core/src/storage/wal.rs +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-core/src/types.rs +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-server/Cargo.toml +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-server/README.md +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-server/src/config.rs +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-server/src/main.rs +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/crates/vxdb-server/src/routes.rs +0 -0
- {vxdb_server-0.4.1 → vxdb_server-0.5.0}/pyproject.toml +0 -0
|
@@ -1837,7 +1837,7 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
|
|
1837
1837
|
|
|
1838
1838
|
[[package]]
|
|
1839
1839
|
name = "vxdb-core"
|
|
1840
|
-
version = "0.
|
|
1840
|
+
version = "0.5.0"
|
|
1841
1841
|
dependencies = [
|
|
1842
1842
|
"memmap2",
|
|
1843
1843
|
"parking_lot",
|
|
@@ -1851,7 +1851,7 @@ dependencies = [
|
|
|
1851
1851
|
|
|
1852
1852
|
[[package]]
|
|
1853
1853
|
name = "vxdb-python"
|
|
1854
|
-
version = "0.
|
|
1854
|
+
version = "0.5.0"
|
|
1855
1855
|
dependencies = [
|
|
1856
1856
|
"pyo3",
|
|
1857
1857
|
"serde_json",
|
|
@@ -1860,7 +1860,7 @@ dependencies = [
|
|
|
1860
1860
|
|
|
1861
1861
|
[[package]]
|
|
1862
1862
|
name = "vxdb-server"
|
|
1863
|
-
version = "0.
|
|
1863
|
+
version = "0.5.0"
|
|
1864
1864
|
dependencies = [
|
|
1865
1865
|
"axum",
|
|
1866
1866
|
"clap",
|
|
@@ -177,7 +177,17 @@ impl Collection {
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
pub fn query(&self, vector: &[f32], top_k: usize) -> VexResult<Vec<SearchResult>> {
|
|
180
|
-
|
|
180
|
+
self.query_ef(vector, top_k, None)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/// Vector search with an optional per-query `ef_search` override (HNSW only).
|
|
184
|
+
pub fn query_ef(
|
|
185
|
+
&self,
|
|
186
|
+
vector: &[f32],
|
|
187
|
+
top_k: usize,
|
|
188
|
+
ef_search: Option<usize>,
|
|
189
|
+
) -> VexResult<Vec<SearchResult>> {
|
|
190
|
+
let mut results = self.index.search_ef(vector, top_k, ef_search)?;
|
|
181
191
|
self.attach_documents(&mut results)?;
|
|
182
192
|
Ok(results)
|
|
183
193
|
}
|
|
@@ -187,9 +197,20 @@ impl Collection {
|
|
|
187
197
|
vector: &[f32],
|
|
188
198
|
top_k: usize,
|
|
189
199
|
filter: &Filter,
|
|
200
|
+
) -> VexResult<Vec<SearchResult>> {
|
|
201
|
+
self.query_with_filter_ef(vector, top_k, filter, None)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/// Filtered vector search with an optional per-query `ef_search` override.
|
|
205
|
+
pub fn query_with_filter_ef(
|
|
206
|
+
&self,
|
|
207
|
+
vector: &[f32],
|
|
208
|
+
top_k: usize,
|
|
209
|
+
filter: &Filter,
|
|
210
|
+
ef_search: Option<usize>,
|
|
190
211
|
) -> VexResult<Vec<SearchResult>> {
|
|
191
212
|
let fetch_k = (top_k * 10).max(100);
|
|
192
|
-
let candidates = self.index.
|
|
213
|
+
let candidates = self.index.search_ef(vector, fetch_k, ef_search)?;
|
|
193
214
|
let mut filtered: Vec<SearchResult> = candidates
|
|
194
215
|
.into_iter()
|
|
195
216
|
.filter(|r| filter.matches(&r.metadata))
|
|
@@ -54,7 +54,13 @@ impl VectorIndex for FlatIndex {
|
|
|
54
54
|
Ok(())
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
// Exact brute-force search: the ef_search hint is irrelevant and ignored.
|
|
58
|
+
fn search_ef(
|
|
59
|
+
&self,
|
|
60
|
+
query: &[f32],
|
|
61
|
+
top_k: usize,
|
|
62
|
+
_ef_search: Option<usize>,
|
|
63
|
+
) -> VexResult<Vec<SearchResult>> {
|
|
58
64
|
if query.len() != self.dimension {
|
|
59
65
|
return Err(VexError::DimensionMismatch {
|
|
60
66
|
expected: self.dimension,
|
|
@@ -368,7 +368,12 @@ impl VectorIndex for HnswIndex {
|
|
|
368
368
|
Ok(())
|
|
369
369
|
}
|
|
370
370
|
|
|
371
|
-
fn
|
|
371
|
+
fn search_ef(
|
|
372
|
+
&self,
|
|
373
|
+
query: &[f32],
|
|
374
|
+
top_k: usize,
|
|
375
|
+
ef_search: Option<usize>,
|
|
376
|
+
) -> VexResult<Vec<SearchResult>> {
|
|
372
377
|
if query.len() != self.dimension {
|
|
373
378
|
return Err(VexError::DimensionMismatch {
|
|
374
379
|
expected: self.dimension,
|
|
@@ -395,8 +400,8 @@ impl VectorIndex for HnswIndex {
|
|
|
395
400
|
current_layer -= 1;
|
|
396
401
|
}
|
|
397
402
|
|
|
398
|
-
// Search layer 0 with ef_search
|
|
399
|
-
let ef = self.config.ef_search.max(top_k);
|
|
403
|
+
// Search layer 0 with the per-query ef_search override, or the default.
|
|
404
|
+
let ef = ef_search.unwrap_or(self.config.ef_search).max(top_k);
|
|
400
405
|
let candidates = self.search_layer(query, vec![ep], ef, 0, &mut visited);
|
|
401
406
|
|
|
402
407
|
let results: Vec<SearchResult> = candidates
|
|
@@ -607,6 +612,60 @@ mod tests {
|
|
|
607
612
|
);
|
|
608
613
|
}
|
|
609
614
|
|
|
615
|
+
#[test]
|
|
616
|
+
fn test_per_query_ef_search_override() {
|
|
617
|
+
// A per-query ef_search overrides the index's configured default without
|
|
618
|
+
// rebuilding the graph. Higher ef explores more candidates, so recall
|
|
619
|
+
// rises; passing None falls back to the configured ef_search.
|
|
620
|
+
use rand::rngs::StdRng;
|
|
621
|
+
use rand::SeedableRng;
|
|
622
|
+
|
|
623
|
+
let dim = 128;
|
|
624
|
+
let n = 3000;
|
|
625
|
+
let n_queries = 100;
|
|
626
|
+
let top_k = 10;
|
|
627
|
+
|
|
628
|
+
let mut rng = StdRng::seed_from_u64(0xBEEF);
|
|
629
|
+
// Configured default ef_search is deliberately low so the override is visible.
|
|
630
|
+
let mut hnsw = HnswIndex::new(dim, Metric::Euclidean, HnswConfig::new(16, 200, 16));
|
|
631
|
+
let mut flat = FlatIndex::new(dim, Metric::Euclidean);
|
|
632
|
+
for i in 0..n {
|
|
633
|
+
let v: Vec<f32> = (0..dim).map(|_| rng.gen::<f32>()).collect();
|
|
634
|
+
let id = format!("v{}", i);
|
|
635
|
+
hnsw.insert(id.clone(), v.clone(), HashMap::new()).unwrap();
|
|
636
|
+
flat.insert(id, v, HashMap::new()).unwrap();
|
|
637
|
+
}
|
|
638
|
+
let queries: Vec<Vec<f32>> = (0..n_queries)
|
|
639
|
+
.map(|_| (0..dim).map(|_| rng.gen::<f32>()).collect())
|
|
640
|
+
.collect();
|
|
641
|
+
|
|
642
|
+
let recall = |ef: Option<usize>| -> f64 {
|
|
643
|
+
let mut total = 0.0f64;
|
|
644
|
+
for q in &queries {
|
|
645
|
+
let h: HashSet<String> =
|
|
646
|
+
hnsw.search_ef(q, top_k, ef).unwrap().into_iter().map(|r| r.id).collect();
|
|
647
|
+
let f: HashSet<String> =
|
|
648
|
+
flat.search(q, top_k).unwrap().into_iter().map(|r| r.id).collect();
|
|
649
|
+
total += h.intersection(&f).count() as f64 / top_k as f64;
|
|
650
|
+
}
|
|
651
|
+
total / n_queries as f64
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
let recall_low = recall(Some(16));
|
|
655
|
+
let recall_high = recall(Some(400));
|
|
656
|
+
let recall_default = recall(None);
|
|
657
|
+
|
|
658
|
+
eprintln!("per-query ef: 16 -> {recall_low:.3}, 400 -> {recall_high:.3}");
|
|
659
|
+
assert!(
|
|
660
|
+
recall_high > recall_low + 0.05,
|
|
661
|
+
"raising per-query ef_search should lift recall: {recall_low:.3} -> {recall_high:.3}"
|
|
662
|
+
);
|
|
663
|
+
assert!(
|
|
664
|
+
(recall_default - recall_low).abs() < 1e-9,
|
|
665
|
+
"search_ef(None) must reuse the configured ef_search (=16)"
|
|
666
|
+
);
|
|
667
|
+
}
|
|
668
|
+
|
|
610
669
|
#[test]
|
|
611
670
|
fn test_single_element() {
|
|
612
671
|
let mut idx = make_hnsw(2);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
pub mod flat;
|
|
2
|
+
pub mod hnsw;
|
|
3
|
+
|
|
4
|
+
use crate::error::VexResult;
|
|
5
|
+
use crate::types::{Metadata, SearchResult, VectorData};
|
|
6
|
+
|
|
7
|
+
pub trait VectorIndex: Send + Sync {
|
|
8
|
+
fn insert(&mut self, id: String, vector: VectorData, metadata: Metadata) -> VexResult<()>;
|
|
9
|
+
|
|
10
|
+
/// Search with an optional per-query `ef_search` override.
|
|
11
|
+
///
|
|
12
|
+
/// Higher `ef_search` explores more of the graph, trading latency for recall.
|
|
13
|
+
/// `None` uses the index's configured default. Exact indexes (flat) ignore
|
|
14
|
+
/// the hint and always return exact results.
|
|
15
|
+
fn search_ef(
|
|
16
|
+
&self,
|
|
17
|
+
query: &[f32],
|
|
18
|
+
top_k: usize,
|
|
19
|
+
ef_search: Option<usize>,
|
|
20
|
+
) -> VexResult<Vec<SearchResult>>;
|
|
21
|
+
|
|
22
|
+
/// Search with the index's configured default `ef_search`.
|
|
23
|
+
fn search(&self, query: &[f32], top_k: usize) -> VexResult<Vec<SearchResult>> {
|
|
24
|
+
self.search_ef(query, top_k, None)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
fn delete(&mut self, id: &str) -> VexResult<bool>;
|
|
28
|
+
fn len(&self) -> usize;
|
|
29
|
+
fn is_empty(&self) -> bool {
|
|
30
|
+
self.len() == 0
|
|
31
|
+
}
|
|
32
|
+
fn contains(&self, id: &str) -> bool;
|
|
33
|
+
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
pub mod flat;
|
|
2
|
-
pub mod hnsw;
|
|
3
|
-
|
|
4
|
-
use crate::error::VexResult;
|
|
5
|
-
use crate::types::{Metadata, SearchResult, VectorData};
|
|
6
|
-
|
|
7
|
-
pub trait VectorIndex: Send + Sync {
|
|
8
|
-
fn insert(&mut self, id: String, vector: VectorData, metadata: Metadata) -> VexResult<()>;
|
|
9
|
-
fn search(&self, query: &[f32], top_k: usize) -> VexResult<Vec<SearchResult>>;
|
|
10
|
-
fn delete(&mut self, id: &str) -> VexResult<bool>;
|
|
11
|
-
fn len(&self) -> usize;
|
|
12
|
-
fn is_empty(&self) -> bool {
|
|
13
|
-
self.len() == 0
|
|
14
|
-
}
|
|
15
|
-
fn contains(&self, id: &str) -> bool;
|
|
16
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|