vxdb-server 0.4.0__tar.gz → 0.4.1__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.0 → vxdb_server-0.4.1}/Cargo.lock +3 -3
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/Cargo.toml +1 -1
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/PKG-INFO +1 -1
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-core/src/hybrid.rs +56 -9
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/README.md +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-core/Cargo.toml +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-core/src/collection.rs +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-core/src/distance/cosine.rs +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-core/src/distance/dot.rs +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-core/src/distance/euclidean.rs +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-core/src/distance/mod.rs +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-core/src/error.rs +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-core/src/filter.rs +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-core/src/index/flat.rs +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-core/src/index/hnsw.rs +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-core/src/index/mod.rs +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-core/src/lib.rs +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-core/src/storage/metadata.rs +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-core/src/storage/mmap.rs +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-core/src/storage/mod.rs +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-core/src/storage/persistent.rs +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-core/src/storage/wal.rs +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-core/src/types.rs +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-server/Cargo.toml +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-server/README.md +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-server/src/config.rs +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-server/src/main.rs +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/crates/vxdb-server/src/routes.rs +0 -0
- {vxdb_server-0.4.0 → vxdb_server-0.4.1}/pyproject.toml +0 -0
|
@@ -1837,7 +1837,7 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
|
|
1837
1837
|
|
|
1838
1838
|
[[package]]
|
|
1839
1839
|
name = "vxdb-core"
|
|
1840
|
-
version = "0.4.
|
|
1840
|
+
version = "0.4.1"
|
|
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.4.
|
|
1854
|
+
version = "0.4.1"
|
|
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.4.
|
|
1863
|
+
version = "0.4.1"
|
|
1864
1864
|
dependencies = [
|
|
1865
1865
|
"axum",
|
|
1866
1866
|
"clap",
|
|
@@ -10,8 +10,8 @@ const B: f64 = 0.75;
|
|
|
10
10
|
pub struct Bm25Index {
|
|
11
11
|
/// doc_id -> tokenized terms
|
|
12
12
|
docs: HashMap<String, Vec<String>>,
|
|
13
|
-
/// term ->
|
|
14
|
-
inverted: HashMap<String,
|
|
13
|
+
/// term -> (doc_id -> term frequency in that doc)
|
|
14
|
+
inverted: HashMap<String, HashMap<String, usize>>,
|
|
15
15
|
/// total number of documents
|
|
16
16
|
doc_count: usize,
|
|
17
17
|
/// average document length
|
|
@@ -37,10 +37,12 @@ impl Bm25Index {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
for token in &tokens {
|
|
40
|
-
self
|
|
40
|
+
*self
|
|
41
|
+
.inverted
|
|
41
42
|
.entry(token.clone())
|
|
42
43
|
.or_default()
|
|
43
|
-
.
|
|
44
|
+
.entry(id.to_string())
|
|
45
|
+
.or_insert(0) += 1;
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
self.docs.insert(id.to_string(), tokens);
|
|
@@ -52,7 +54,7 @@ impl Bm25Index {
|
|
|
52
54
|
if let Some(tokens) = self.docs.remove(id) {
|
|
53
55
|
for token in &tokens {
|
|
54
56
|
if let Some(posting) = self.inverted.get_mut(token) {
|
|
55
|
-
posting.
|
|
57
|
+
posting.remove(id);
|
|
56
58
|
if posting.is_empty() {
|
|
57
59
|
self.inverted.remove(token);
|
|
58
60
|
}
|
|
@@ -92,10 +94,9 @@ impl Bm25Index {
|
|
|
92
94
|
// IDF: log((N - df + 0.5) / (df + 0.5) + 1)
|
|
93
95
|
let idf = ((n - df + 0.5) / (df + 0.5) + 1.0).ln();
|
|
94
96
|
|
|
95
|
-
for doc_id in posting {
|
|
96
|
-
let
|
|
97
|
-
let
|
|
98
|
-
let tf = doc_tokens.iter().filter(|t| *t == token).count() as f64;
|
|
97
|
+
for (doc_id, &tf) in posting {
|
|
98
|
+
let doc_len = self.docs[doc_id.as_str()].len() as f64;
|
|
99
|
+
let tf = tf as f64;
|
|
99
100
|
|
|
100
101
|
// BM25 term score
|
|
101
102
|
let tf_norm = (tf * (K1 + 1.0)) / (tf + K1 * (1.0 - B + B * doc_len / self.avg_doc_len));
|
|
@@ -198,6 +199,52 @@ mod tests {
|
|
|
198
199
|
assert!(results.iter().all(|r| r.0 != "none"));
|
|
199
200
|
}
|
|
200
201
|
|
|
202
|
+
#[test]
|
|
203
|
+
fn test_bm25_df_counts_documents_not_occurrences() {
|
|
204
|
+
// "common" occurs 5x in 2 of 3 docs. df must be 2 (documents), not 10
|
|
205
|
+
// (occurrences) — an inflated df flips the IDF negative and penalizes
|
|
206
|
+
// exactly the docs that match the query.
|
|
207
|
+
let mut idx = Bm25Index::new();
|
|
208
|
+
idx.insert("doc1", "rare word appears here today");
|
|
209
|
+
idx.insert("doc2", "rare common common common common common filler");
|
|
210
|
+
idx.insert("doc3", "common common common common common other filler");
|
|
211
|
+
|
|
212
|
+
let results = idx.search("rare common", 10);
|
|
213
|
+
assert_eq!(
|
|
214
|
+
results[0].0, "doc2",
|
|
215
|
+
"doc matching both query terms must rank first, got {results:?}"
|
|
216
|
+
);
|
|
217
|
+
assert!(
|
|
218
|
+
results.iter().all(|(_, s)| *s >= 0.0),
|
|
219
|
+
"BM25 scores must be non-negative, got {results:?}"
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
#[test]
|
|
224
|
+
fn test_bm25_term_repetition_saturates() {
|
|
225
|
+
// A doc matching all three query terms once must beat a doc that
|
|
226
|
+
// repeats a single query term eight times (K1 saturation).
|
|
227
|
+
let mut idx = Bm25Index::new();
|
|
228
|
+
idx.insert(
|
|
229
|
+
"needle",
|
|
230
|
+
"the quick brown fox jumps over lazy dogs in autumn weather today",
|
|
231
|
+
);
|
|
232
|
+
idx.insert(
|
|
233
|
+
"spam",
|
|
234
|
+
"fox fox fox fox fox fox fox fox with some other filler words here",
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
let results = idx.search("quick brown fox", 10);
|
|
238
|
+
assert_eq!(
|
|
239
|
+
results[0].0, "needle",
|
|
240
|
+
"doc matching all query terms must outrank single-term repetition, got {results:?}"
|
|
241
|
+
);
|
|
242
|
+
assert!(
|
|
243
|
+
results.iter().all(|(_, s)| *s >= 0.0),
|
|
244
|
+
"BM25 scores must be non-negative, got {results:?}"
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
201
248
|
#[test]
|
|
202
249
|
fn test_bm25_empty_query() {
|
|
203
250
|
let mut idx = Bm25Index::new();
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|