zeusdb-vector-database 0.9.0__tar.gz → 0.10.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.
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/Cargo.lock +29 -9
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/Cargo.toml +3 -1
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/PKG-INFO +356 -10
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/README.md +355 -9
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/bindings/python/src/hnsw_index/construct.rs +131 -7
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/bindings/python/src/hnsw_index/input.rs +256 -32
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/bindings/python/src/hnsw_index/mod.rs +282 -30
- zeusdb_vector_database-0.10.0/bindings/python/src/hnsw_index/query.rs +443 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/bindings/python/src/lib.rs +37 -7
- zeusdb_vector_database-0.10.0/bindings/python/src/tokenizer.rs +124 -0
- zeusdb_vector_database-0.10.0/crates/core/src/admit.rs +270 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/src/columns.rs +22 -1
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/src/distance.rs +12 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/src/error.rs +246 -4
- zeusdb_vector_database-0.10.0/crates/core/src/frame.rs +656 -0
- zeusdb_vector_database-0.10.0/crates/core/src/fusion.rs +306 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/src/graph/guard_tests.rs +2 -2
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/src/graph/mod.rs +190 -1
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/src/graph/mutable/mod.rs +1 -1
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/src/lib.rs +23 -4
- zeusdb_vector_database-0.10.0/crates/core/src/space.rs +811 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/hnsw/Cargo.toml +8 -4
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/hnsw/src/collection/construct.rs +144 -28
- zeusdb_vector_database-0.10.0/crates/hnsw/src/collection/dense.rs +851 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/hnsw/src/collection/input.rs +4 -4
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/hnsw/src/collection/insert.rs +311 -142
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/hnsw/src/collection/mod.rs +469 -76
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/hnsw/src/collection/persist.rs +174 -96
- zeusdb_vector_database-0.10.0/crates/hnsw/src/collection/persist_tests.rs +678 -0
- zeusdb_vector_database-0.10.0/crates/hnsw/src/collection/query.rs +546 -0
- zeusdb_vector_database-0.10.0/crates/hnsw/src/collection/query_tests.rs +462 -0
- zeusdb_vector_database-0.10.0/crates/hnsw/src/collection/search.rs +1173 -0
- zeusdb_vector_database-0.10.0/crates/hnsw/src/collection/spaces_tests.rs +672 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/hnsw/src/collection/stats.rs +81 -27
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/hnsw/src/collection/training.rs +31 -29
- zeusdb_vector_database-0.10.0/crates/hnsw/src/lib.rs +63 -0
- zeusdb_vector_database-0.10.0/crates/hnsw/src/locks.rs +679 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/hnsw/src/persistence.rs +386 -39
- zeusdb_vector_database-0.10.0/crates/sparse/Cargo.toml +25 -0
- zeusdb_vector_database-0.10.0/crates/sparse/src/calibrate.rs +377 -0
- zeusdb_vector_database-0.10.0/crates/sparse/src/corpus.rs +180 -0
- zeusdb_vector_database-0.10.0/crates/sparse/src/index.rs +987 -0
- zeusdb_vector_database-0.10.0/crates/sparse/src/lib.rs +91 -0
- zeusdb_vector_database-0.10.0/crates/sparse/src/persist.rs +536 -0
- zeusdb_vector_database-0.10.0/crates/sparse/src/search.rs +1157 -0
- zeusdb_vector_database-0.10.0/crates/sparse/src/verify.rs +722 -0
- zeusdb_vector_database-0.10.0/crates/text/Cargo.toml +21 -0
- zeusdb_vector_database-0.10.0/crates/text/src/dictionary.rs +305 -0
- zeusdb_vector_database-0.10.0/crates/text/src/lib.rs +46 -0
- zeusdb_vector_database-0.10.0/crates/text/src/tokenizer.rs +185 -0
- zeusdb_vector_database-0.10.0/crates/text/src/vectorize.rs +187 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/pyproject.toml +1 -1
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/src/zeusdb_vector_database/__init__.py +1 -1
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/src/zeusdb_vector_database/vector_database.py +64 -14
- zeusdb_vector_database-0.9.0/crates/hnsw/src/collection/search.rs +0 -1279
- zeusdb_vector_database-0.9.0/crates/hnsw/src/lib.rs +0 -50
- zeusdb_vector_database-0.9.0/crates/hnsw/src/locks.rs +0 -492
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/LICENSE +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/NOTICE +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/bindings/python/Cargo.toml +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/bindings/python/src/conversion.rs +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/bindings/python/src/logging.rs +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/Cargo.toml +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/src/checksum.rs +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/src/filter.rs +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/src/graph/dump.rs +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/src/graph/fuzz.rs +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/src/graph/levels.rs +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/src/graph/mutable/insert.rs +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/src/graph/store.rs +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/src/graph/structure.rs +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/src/graph/test_graph.rs +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/src/graph/traverse.rs +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/src/pq.rs +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/src/rng.rs +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/core/src/test_vectors.rs +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/crates/hnsw/src/rerank.rs +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/src/zeusdb_vector_database/logging_config.py +0 -0
- {zeusdb_vector_database-0.9.0 → zeusdb_vector_database-0.10.0}/src/zeusdb_vector_database/py.typed +0 -0
|
@@ -82,9 +82,9 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
|
|
82
82
|
|
|
83
83
|
[[package]]
|
|
84
84
|
name = "chacha20"
|
|
85
|
-
version = "0.10.
|
|
85
|
+
version = "0.10.2"
|
|
86
86
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
87
|
-
checksum = "
|
|
87
|
+
checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06"
|
|
88
88
|
dependencies = [
|
|
89
89
|
"cfg-if",
|
|
90
90
|
"cpufeatures",
|
|
@@ -613,9 +613,9 @@ checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
|
|
|
613
613
|
|
|
614
614
|
[[package]]
|
|
615
615
|
name = "safe_arch"
|
|
616
|
-
version = "1.
|
|
616
|
+
version = "1.2.0"
|
|
617
617
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
618
|
-
checksum = "
|
|
618
|
+
checksum = "42c6efa15875e6ecb39ca61fb0b0c1a40b84fac5a5ffe71eef7d1000c8eb3f5f"
|
|
619
619
|
dependencies = [
|
|
620
620
|
"bytemuck",
|
|
621
621
|
]
|
|
@@ -936,9 +936,9 @@ dependencies = [
|
|
|
936
936
|
|
|
937
937
|
[[package]]
|
|
938
938
|
name = "wide"
|
|
939
|
-
version = "1.
|
|
939
|
+
version = "1.7.0"
|
|
940
940
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
941
|
-
checksum = "
|
|
941
|
+
checksum = "8cf05ca94c9fba0c51316899caa1d1e74a064fc310a5efa7375e614343d415be"
|
|
942
942
|
dependencies = [
|
|
943
943
|
"bytemuck",
|
|
944
944
|
"safe_arch",
|
|
@@ -1034,7 +1034,7 @@ dependencies = [
|
|
|
1034
1034
|
|
|
1035
1035
|
[[package]]
|
|
1036
1036
|
name = "zeusdb-vector-core"
|
|
1037
|
-
version = "0.
|
|
1037
|
+
version = "0.10.0"
|
|
1038
1038
|
dependencies = [
|
|
1039
1039
|
"rand",
|
|
1040
1040
|
"rand_chacha",
|
|
@@ -1047,7 +1047,7 @@ dependencies = [
|
|
|
1047
1047
|
|
|
1048
1048
|
[[package]]
|
|
1049
1049
|
name = "zeusdb-vector-hnsw"
|
|
1050
|
-
version = "0.
|
|
1050
|
+
version = "0.10.0"
|
|
1051
1051
|
dependencies = [
|
|
1052
1052
|
"bincode",
|
|
1053
1053
|
"chrono",
|
|
@@ -1057,11 +1057,13 @@ dependencies = [
|
|
|
1057
1057
|
"serde_json",
|
|
1058
1058
|
"tracing",
|
|
1059
1059
|
"zeusdb-vector-core",
|
|
1060
|
+
"zeusdb-vector-sparse",
|
|
1061
|
+
"zeusdb-vector-text",
|
|
1060
1062
|
]
|
|
1061
1063
|
|
|
1062
1064
|
[[package]]
|
|
1063
1065
|
name = "zeusdb-vector-python"
|
|
1064
|
-
version = "0.
|
|
1066
|
+
version = "0.10.0"
|
|
1065
1067
|
dependencies = [
|
|
1066
1068
|
"chrono",
|
|
1067
1069
|
"numpy",
|
|
@@ -1074,6 +1076,24 @@ dependencies = [
|
|
|
1074
1076
|
"zeusdb-vector-hnsw",
|
|
1075
1077
|
]
|
|
1076
1078
|
|
|
1079
|
+
[[package]]
|
|
1080
|
+
name = "zeusdb-vector-sparse"
|
|
1081
|
+
version = "0.10.0"
|
|
1082
|
+
dependencies = [
|
|
1083
|
+
"serde",
|
|
1084
|
+
"tempfile",
|
|
1085
|
+
"tracing",
|
|
1086
|
+
"zeusdb-vector-core",
|
|
1087
|
+
]
|
|
1088
|
+
|
|
1089
|
+
[[package]]
|
|
1090
|
+
name = "zeusdb-vector-text"
|
|
1091
|
+
version = "0.10.0"
|
|
1092
|
+
dependencies = [
|
|
1093
|
+
"serde",
|
|
1094
|
+
"zeusdb-vector-core",
|
|
1095
|
+
]
|
|
1096
|
+
|
|
1077
1097
|
[[package]]
|
|
1078
1098
|
name = "zmij"
|
|
1079
1099
|
version = "1.0.23"
|
|
@@ -27,7 +27,7 @@ resolver = "2"
|
|
|
27
27
|
members = ["crates/*", "bindings/*"]
|
|
28
28
|
|
|
29
29
|
[workspace.package]
|
|
30
|
-
version = "0.
|
|
30
|
+
version = "0.10.0"
|
|
31
31
|
edition = "2021"
|
|
32
32
|
# The same licence pyproject.toml declares, LICENSE holds and NOTICE restates.
|
|
33
33
|
# cargo-deny reads this field. The wheel's metadata is unaffected, because
|
|
@@ -40,6 +40,8 @@ license = "Apache-2.0"
|
|
|
40
40
|
# cargo-deny's allow-wildcard-paths admits the versionless edge.
|
|
41
41
|
zeusdb-vector-core = { path = "crates/core" }
|
|
42
42
|
zeusdb-vector-hnsw = { path = "crates/hnsw" }
|
|
43
|
+
zeusdb-vector-sparse = { path = "crates/sparse" }
|
|
44
|
+
zeusdb-vector-text = { path = "crates/text" }
|
|
43
45
|
# abi3-py310 builds against CPython's stable ABI, so one wheel per platform
|
|
44
46
|
# loads on every CPython from 3.10 up, including versions that do not exist
|
|
45
47
|
# yet. The feature lives here rather than in pyproject's [tool.maturin]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: zeusdb-vector-database
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.10.0
|
|
4
4
|
Classifier: Programming Language :: Rust
|
|
5
5
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
6
6
|
Requires-Dist: numpy>=2.2.6,<3.0.0
|
|
@@ -71,6 +71,10 @@ ZeusDB leverages the HNSW (Hierarchical Navigable Small World) algorithm for spe
|
|
|
71
71
|
|
|
72
72
|
🗂️ Metadata-aware filtering for precise and contextual querying
|
|
73
73
|
|
|
74
|
+
🔤 Text search over a sparse space, with a built-in tokenizer or one you supply
|
|
75
|
+
|
|
76
|
+
🔀 Hybrid search that runs dense, sparse and text arms over one candidate set and fuses them by rank
|
|
77
|
+
|
|
74
78
|
💾 Save and load complete indexes to disk
|
|
75
79
|
|
|
76
80
|
<br/>
|
|
@@ -97,6 +101,8 @@ All distance metrics in ZeusDB Vector Database return distance values, not simil
|
|
|
97
101
|
|
|
98
102
|
This applies to all distance types, including cosine. `dot` is the one exception to the zero, because its score is `1 - dot` and an inner product above one takes it below zero.
|
|
99
103
|
|
|
104
|
+
**This is what `search()` returns.** A `query()` page is scored differently. A sparse or text arm's score is a similarity, so higher is more similar, and a fused score is a reciprocal rank sum, which is higher for a record that placed well on more arms. See [Hybrid Search](#-hybrid-search).
|
|
105
|
+
|
|
100
106
|
Under `cosine`, vectors are normalized to unit length when they are stored. A vector you read back with `return_vector=True` or `get_records()` is therefore the normalized form, not the values you supplied. Under `l1`, `l2` and `dot` the values are stored unchanged.
|
|
101
107
|
|
|
102
108
|
A zero vector has no direction, so under `cosine` it sits at distance 1.0 from everything, including itself.
|
|
@@ -235,6 +241,7 @@ HNSWIndex(dim=8, space=cosine, m=16, ef_construction=200, expected_size=5, vecto
|
|
|
235
241
|
| `expected_size` | `int` | `10000` | Estimated number of records to be inserted, from 1 to 100,000,000. Used for preallocating internal data structures and for choosing the default `m`. Not a hard limit, see below. |
|
|
236
242
|
| `quantization_config` | `dict` | `None` | Product Quantization configuration for memory-efficient vector compression. See [Product Quantization](#️-product-quantization). |
|
|
237
243
|
| `indexed_fields` | `list[str]` | `None` | Metadata fields to build a column for, so that a filter naming only those fields does not read every record. Up to 32 names, no duplicates, none of `$and`, `$or` or `$not`. See [Declaring the fields you filter on](#-declaring-the-fields-you-filter-on). |
|
|
244
|
+
| `sparse` | `dict` | `None` | Declares a sparse space beside the dense one. `tokenizer` makes it a text layer and defaults the weighting to `"bm25"`; without one the weighting defaults to `"dot"`. `name` is the directory the space saves under and defaults to `sparse`. Also takes `unlink` and `lazy_threshold_percent`. See [Text Search](#-text-search) and [Sparse Vectors](#-sparse-vectors). |
|
|
238
245
|
|
|
239
246
|
**`dim` is required.** There is no default, because `dim` has to equal the width your embedding model produces and an index built at any other width rejects every vector you add to it. Omitting it raises `TypeError`.
|
|
240
247
|
|
|
@@ -250,18 +257,18 @@ except TypeError as error:
|
|
|
250
257
|
create() requires 'dim', the width of the vectors this index will hold. There is no default because dim has to equal the width your embedding model produces, and an index built at any other width rejects every vector you add to it. Read it off one embedding with len(vector), or pass the width your model documents, for example dim=1536 for OpenAI text-embedding-3-small or dim=768 for most sentence-transformers models.
|
|
251
258
|
```
|
|
252
259
|
|
|
253
|
-
**The default `m` depends on `expected_size`.** It is 16 for an `expected_size` of 25,000 or less, and 32 above that. A graph too sparse for the number of records loses recall that no search width recovers, so declare `expected_size` honestly or set `m` yourself. Passing `m` explicitly always wins, and [`rebuild()`](
|
|
260
|
+
**The default `m` depends on `expected_size`.** It is 16 for an `expected_size` of 25,000 or less, and 32 above that. A graph too sparse for the number of records loses recall that no search width recovers, so declare `expected_size` honestly or set `m` yourself. Passing `m` explicitly always wins, and [`rebuild()`](#️-change-m-after-the-fact-with-rebuild) changes it afterwards.
|
|
254
261
|
|
|
255
262
|
```python
|
|
256
263
|
vdb.create("hnsw", dim=8, expected_size=25_000).get_stats()["m"] # '16'
|
|
257
264
|
vdb.create("hnsw", dim=8, expected_size=25_001).get_stats()["m"] # '32'
|
|
258
265
|
```
|
|
259
266
|
|
|
260
|
-
**`expected_size` is a hint and not a limit.** An index accepts more records than it declared and the graph grows to fit them. What it does not change is `m`, which [`rebuild()`](
|
|
267
|
+
**`expected_size` is a hint and not a limit.** An index accepts more records than it declared and the graph grows to fit them. What it does not change is `m`, which [`rebuild()`](#️-change-m-after-the-fact-with-rebuild) does. Passing twice the declared size logs a warning once, on the `add()` that crosses it.
|
|
261
268
|
|
|
262
269
|
**`ef_construction` costs build time and buys graph quality.** It changes neither search latency nor the size of the finished index. Build time is linear in it above 100, so 50,000 records of `dim=1536` build in 76.9 s at the default and 262.1 s at 800. Recall stops improving at or near the default on most data, and where it keeps climbing a larger `ef_search` buys more for less, so raise `ef_search` before raising this. The default does not move with `m`, so 200 is 6.25 times the layer zero neighbour budget of 32 at `m=16` and 3.125 times the budget of 64 at `m=32`. Measured at 50,000 records with `m=32`, raising it to 400 bought 0.0010 recall at 10 on OpenAI embeddings of `dim=1536`, 0.0002 on SIFT and 0.0078 on GloVe, for 1.9 to 2.2 times the build time, which is why the constant stays.
|
|
263
270
|
|
|
264
|
-
**Keep `ef_construction` above `2 × m`.** At or below the neighbour budget the graph keeps every candidate the insertion search returned and prunes none of them. `create()` and [`rebuild()`](
|
|
271
|
+
**Keep `ef_construction` above `2 × m`.** At or below the neighbour budget the graph keeps every candidate the insertion search returned and prunes none of them. `create()` and [`rebuild()`](#️-change-m-after-the-fact-with-rebuild) both warn when the pair reaches that point, and both take the pair, so either remedy the warning names can be taken. The defaults are clear of it.
|
|
265
272
|
|
|
266
273
|
<br/>
|
|
267
274
|
|
|
@@ -376,6 +383,46 @@ print(add_result)
|
|
|
376
383
|
AddResult(inserted=2, errors=0, shape=Some((2, 2)))
|
|
377
384
|
```
|
|
378
385
|
|
|
386
|
+
#### ✅ Format 6 – Sparse and text beside the vector
|
|
387
|
+
|
|
388
|
+
An index declaring a sparse space takes one more key per record. A record dict spells it `text` or `sparse`, a batch dict spells the same thing `texts` or `sparse`, one entry per record.
|
|
389
|
+
|
|
390
|
+
```python
|
|
391
|
+
from zeusdb_vector_database import VectorDatabase
|
|
392
|
+
|
|
393
|
+
vdb = VectorDatabase()
|
|
394
|
+
index = vdb.create("hnsw", dim=2, sparse={"tokenizer": "simple"})
|
|
395
|
+
|
|
396
|
+
# A record dict carries text, one key per record.
|
|
397
|
+
print(index.add({"id": "doc1", "values": [0.1, 0.2], "text": "the quick brown fox"}))
|
|
398
|
+
|
|
399
|
+
# A batch dict carries texts, one per record, aligned with ids.
|
|
400
|
+
print(index.add({
|
|
401
|
+
"ids": ["doc2", "doc3"],
|
|
402
|
+
"embeddings": [[0.3, 0.4], [0.5, 0.6]],
|
|
403
|
+
"texts": ["a lazy brown dog", "the rain in spain"],
|
|
404
|
+
}))
|
|
405
|
+
|
|
406
|
+
# A record the space takes nothing from leaves the key out.
|
|
407
|
+
print(index.add({"id": "doc4", "values": [0.7, 0.8]}))
|
|
408
|
+
print(index.get_stats()["sparse_records"], len(index))
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
*Output*
|
|
412
|
+
```
|
|
413
|
+
AddResult(inserted=1, errors=0, shape=Some((1, 2)))
|
|
414
|
+
AddResult(inserted=2, errors=0, shape=Some((2, 2)))
|
|
415
|
+
AddResult(inserted=1, errors=0, shape=Some((1, 2)))
|
|
416
|
+
3 4
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
| Shape | Text layer | Term ids |
|
|
420
|
+
|-------|-----------|----------|
|
|
421
|
+
| A record dict, formats 1 and 2 | `text` | `sparse` |
|
|
422
|
+
| A batch dict, formats 3 and 5 | `texts` | `sparse` |
|
|
423
|
+
|
|
424
|
+
**A space takes one spelling and refuses the other.** `sparse` on a text layer is that record's error, and `text` on a space declared without a tokenizer is the same. On an index declaring no sparse space at all, either key gives `This collection declares no sparse space`, one error per record. The parallel array rule extends to these, so a `texts` list short against `ids` raises before anything is inserted.
|
|
425
|
+
|
|
379
426
|
Each format is parsed and validated automatically. Invalid records are skipped rather than aborting the call, and the reason for each is returned in `errors`. A record whose vector contains `NaN` or an infinity is rejected this way.
|
|
380
427
|
|
|
381
428
|
<br/>
|
|
@@ -417,7 +464,7 @@ The `add()` method inserts or replaces one or more vectors in the index.
|
|
|
417
464
|
|
|
418
465
|
| Parameter | Type | Default | Description |
|
|
419
466
|
|-----------|-------------------------------------|---------|-------------|
|
|
420
|
-
| `data` | `dict`, `list[dict]`, `dict` of arrays, or `np.ndarray` | *required* | Input records to upsert into the index. Supports the
|
|
467
|
+
| `data` | `dict`, `list[dict]`, `dict` of arrays, or `np.ndarray` | *required* | Input records to upsert into the index. Supports the six formats above. |
|
|
421
468
|
| `overwrite` | `bool` | `True` | Whether an ID already in the index is replaced. With `False`, a colliding record is skipped and counted as an error. |
|
|
422
469
|
|
|
423
470
|
**The parallel arrays must be the same length.** Formats 3 and 5 pair `ids[i]` with `vectors[i]` and `metadatas[i]` by position, so a disagreement in length is a caller error and raises `ValueError` naming both lengths and which field is short. Nothing is inserted before the raise, so the call is safe to retry.
|
|
@@ -612,6 +659,8 @@ The `search()` method retrieves the top-k most similar vectors from the index gi
|
|
|
612
659
|
|
|
613
660
|
A query vector containing `NaN` or an infinity raises `ValueError` rather than returning meaningless distances.
|
|
614
661
|
|
|
662
|
+
`search()` asks one space. To ask several in one call, and to see what a query would cost before it runs, see [Hybrid Search](#-hybrid-search) and [Query Plans](#️-query-plans).
|
|
663
|
+
|
|
615
664
|
<br/>
|
|
616
665
|
|
|
617
666
|
### 🧰 Additional functionality
|
|
@@ -767,7 +816,7 @@ storage_mode_description: raw_only
|
|
|
767
816
|
| `quantized_codes_memory_mb` | The codes, which grow with the record count |
|
|
768
817
|
| `codebook_memory_mb`, `sdc_table_memory_mb`, `centroid_norm_memory_mb` | The trained tables, fixed by `dim`, `subvectors` and `bits` |
|
|
769
818
|
| `index_bookkeeping_memory_mb` | The hash tables that find a record |
|
|
770
|
-
| `total_memory_mb` | The sum of the seven figures above |
|
|
819
|
+
| `total_memory_mb` | The sum of the seven figures above, and of `sparse_memory_mb` and `dictionary_memory_mb` where the index declares a sparse space |
|
|
771
820
|
| `quantization_type` | `pq`, or `none` on an unquantized index |
|
|
772
821
|
| `raw_vectors_retained` | The storage mode's policy, `none_once_trained` or `all_records`. Quantized indexes only |
|
|
773
822
|
|
|
@@ -1426,6 +1475,7 @@ The persistence system supports:
|
|
|
1426
1475
|
✅ **Hybrid storage format**, binary encoding for vectors with human-readable JSON for metadata
|
|
1427
1476
|
✅ **Quantization support**, both raw and quantized storage modes, including the trained codebook
|
|
1428
1477
|
✅ **Training state recovery**, so an index saved mid-collection resumes collecting
|
|
1478
|
+
✅ **Sparse spaces**, the postings and the term dictionary, under `spaces/<name>/`
|
|
1429
1479
|
✅ **Format versioning**, so a directory this build cannot interpret is refused rather than misread
|
|
1430
1480
|
✅ **Atomic saves**, so a reader sees the whole previous index or the whole new one
|
|
1431
1481
|
✅ **A digest per artefact**, checked on load, so a file that has changed since it was written is refused
|
|
@@ -1489,6 +1539,8 @@ top hit: doc_0
|
|
|
1489
1539
|
|
|
1490
1540
|
The graph is rebuilt by re-inserting every record only when the saved graph cannot be used, which covers a directory whose graph files were lost or damaged and one written by a release too old for this build to interpret. Set `ZEUSDB_LOAD_REBUILD_GRAPH=1` to ask for that rebuild on a directory whose graph is perfectly readable, which is how an index built by an earlier release picks up graph improvements made since.
|
|
1491
1541
|
|
|
1542
|
+
**A directory whose sparse space was declared with your own tokenizer needs it handed back**, as `vdb.load(path, tokenizer=tokenize)`. See [Text Search](#-text-search).
|
|
1543
|
+
|
|
1492
1544
|
<br />
|
|
1493
1545
|
|
|
1494
1546
|
### 🗜️ Persistence with Product Quantization
|
|
@@ -1546,9 +1598,15 @@ my_index.zdb/
|
|
|
1546
1598
|
├── quantization.json # PQ configuration (if enabled)
|
|
1547
1599
|
├── pq_centroids.bin # Trained centroids (if PQ trained)
|
|
1548
1600
|
├── pq_codes.bin # Quantized codes (if PQ active)
|
|
1549
|
-
|
|
1601
|
+
├── hnsw_index.zdbgraph # HNSW graph structure and payload
|
|
1602
|
+
└── spaces/ # One directory per sparse space (if declared)
|
|
1603
|
+
└── <name>/
|
|
1604
|
+
├── postings.zdbsparse # Every live record's term ids and weights
|
|
1605
|
+
└── terms.zdbdict # The term dictionary (text layers only)
|
|
1550
1606
|
```
|
|
1551
1607
|
|
|
1608
|
+
`<name>` is the space's `name`, which defaults to `sparse`. `terms.zdbdict` is written only where the space was declared with a tokenizer.
|
|
1609
|
+
|
|
1552
1610
|
`manifest.json` lists every file the save wrote under `files_included` and is the last file written, so it is the inventory of what the directory does hold. Beside the list, `file_digests` records each artefact's length and a digest of its contents.
|
|
1553
1611
|
|
|
1554
1612
|
A directory saved by 0.6.0 or earlier holds `hnsw_index.hnsw.graph` and `hnsw_index.hnsw.data` in place of `hnsw_index.zdbgraph`. Opening it still works: the graph is rebuilt once from the stored records, and the next `.save()` writes the single file.
|
|
@@ -1644,9 +1702,9 @@ all checks passed
|
|
|
1644
1702
|
|
|
1645
1703
|
- **Same volume.** The staging directory is a sibling of the target, so both are on the target's volume and the move is a rename rather than a copy.
|
|
1646
1704
|
|
|
1647
|
-
- **Version compatibility.** The manifest records a format version. This build writes 1.1.0 and reads any 1.x. A different major version is refused.
|
|
1705
|
+
- **Version compatibility.** The manifest records a format version. This build writes 1.1.0 for a directory holding a dense space alone, which opens on every release that reads 1.x, and 2.0.0 for a directory holding a sparse space, which needs this release or later. It reads any 1.x or 2.x. A different major version is refused.
|
|
1648
1706
|
|
|
1649
|
-
- **Integrity checks on load.** Four run, in this order: the format version, then `files_included` against the directory, then each artefact against its recorded length and digest, then the restored record count against the count in `config.json`.
|
|
1707
|
+
- **Integrity checks on load.** Four run, in this order: the format version, then `files_included` against the directory, then each artefact against its recorded length and digest, then the restored record count against the count in `config.json`. A directory holding a sparse space adds two, being every record the space holds against the id mappings, and every term id the postings carry against the length of the dictionary.
|
|
1650
1708
|
|
|
1651
1709
|
- **`save()` and `load()` are silent.** Every step they used to print to stdout is a `debug` log line instead, so a library caller sees nothing on stdout. Set `ZEUSDB_LOG_LEVEL=debug` to see the steps.
|
|
1652
1710
|
|
|
@@ -1791,7 +1849,7 @@ print(matched({"$not": {"tier": "free"}}))
|
|
|
1791
1849
|
# Records with no lang field at all, which no operator can select.
|
|
1792
1850
|
print(matched({"$not": {"lang": {"all": []}}}))
|
|
1793
1851
|
|
|
1794
|
-
# None of these, which is
|
|
1852
|
+
# None of these, which is a negated disjunction over a group.
|
|
1795
1853
|
print(matched({"$not": {"$or": [{"lang": "es"}, {"tier": "gold"}]}}))
|
|
1796
1854
|
```
|
|
1797
1855
|
|
|
@@ -1975,6 +2033,294 @@ print(matched({"$not": {"author": "Bob"}}))
|
|
|
1975
2033
|
['doc_1', 'doc_3']
|
|
1976
2034
|
```
|
|
1977
2035
|
|
|
2036
|
+
---
|
|
2037
|
+
|
|
2038
|
+
<br/>
|
|
2039
|
+
|
|
2040
|
+
## 🔎 Sparse and Hybrid Search
|
|
2041
|
+
|
|
2042
|
+
### 🔤 Text Search
|
|
2043
|
+
|
|
2044
|
+
A sparse space indexes term counts beside the dense vectors. Declare it with a tokenizer and records carry a `text` field, which the tokenizer splits and the space counts.
|
|
2045
|
+
|
|
2046
|
+
```python
|
|
2047
|
+
from zeusdb_vector_database import VectorDatabase
|
|
2048
|
+
|
|
2049
|
+
vdb = VectorDatabase()
|
|
2050
|
+
index = vdb.create("hnsw", dim=4, sparse={"tokenizer": "simple"})
|
|
2051
|
+
|
|
2052
|
+
index.add([
|
|
2053
|
+
{"id": "d1", "values": [0.1, 0.1, 0.1, 0.1],
|
|
2054
|
+
"text": "the quick brown fox jumps over the lazy dog"},
|
|
2055
|
+
{"id": "d2", "values": [0.2, 0.2, 0.2, 0.2],
|
|
2056
|
+
"text": "a quick brown dog outpaces a lazy fox"},
|
|
2057
|
+
{"id": "d3", "values": [0.3, 0.3, 0.3, 0.3],
|
|
2058
|
+
"text": "the rain in spain falls mainly on the plain"},
|
|
2059
|
+
])
|
|
2060
|
+
|
|
2061
|
+
for hit in index.query(arms=[{"text": "quick fox"}], top_k=2):
|
|
2062
|
+
print(hit["id"], round(hit["score"], 4))
|
|
2063
|
+
```
|
|
2064
|
+
|
|
2065
|
+
*Output*
|
|
2066
|
+
```
|
|
2067
|
+
d2 0.9705
|
|
2068
|
+
d1 0.9254
|
|
2069
|
+
```
|
|
2070
|
+
|
|
2071
|
+
| Key | Takes | Means |
|
|
2072
|
+
|-----|-------|-------|
|
|
2073
|
+
| `tokenizer` | `"simple"` or a callable | How a text becomes terms. Declaring it makes the space a text layer |
|
|
2074
|
+
| `weighting` | `"dot"`, `"bm25"`, or a mapping | How a term count scores. Defaults to `bm25` where a tokenizer is declared. `{"type": "bm25", "k1": 1.5, "b": 0.6}` sets the parameters, which otherwise take 1.2 and 0.75 |
|
|
2075
|
+
| `name` | a string | The directory the space saves under. Defaults to `sparse` |
|
|
2076
|
+
|
|
2077
|
+
**Scores are similarities.** Higher is better, unlike the dense `search()`, whose scores are distances. A space with a text layer takes `text` and refuses `sparse`.
|
|
2078
|
+
|
|
2079
|
+
<br/>
|
|
2080
|
+
|
|
2081
|
+
**The built-in tokenizer** splits on anything that is not a letter or a digit and lowercases. It does no stemming, no stopword removal and no segmentation of a script written without spaces, so `state-of-the-art` is four terms and `don't` is two. A caller who needs more supplies their own.
|
|
2082
|
+
|
|
2083
|
+
```python
|
|
2084
|
+
def tokenize(text):
|
|
2085
|
+
return [w.strip(".,!?").lower() for w in text.split() if len(w) > 2]
|
|
2086
|
+
|
|
2087
|
+
index = vdb.create("hnsw", dim=4, sparse={"tokenizer": tokenize})
|
|
2088
|
+
index.add({"id": "d1", "values": [0.1, 0.1, 0.1, 0.1],
|
|
2089
|
+
"text": "The quick brown fox."})
|
|
2090
|
+
|
|
2091
|
+
print(index.get_stats()["term_count"])
|
|
2092
|
+
```
|
|
2093
|
+
|
|
2094
|
+
*Output*
|
|
2095
|
+
```
|
|
2096
|
+
4
|
|
2097
|
+
```
|
|
2098
|
+
|
|
2099
|
+
A tokenizer takes a `str` and returns an iterable of `str`, one per term, in order and with every repeat, since the count is what the space stores. An exception it raises comes back as itself from `query()`, and from `add()` as that record's error naming the class.
|
|
2100
|
+
|
|
2101
|
+
<br/>
|
|
2102
|
+
|
|
2103
|
+
**Reopening an index built with your own tokenizer** needs the same tokenizer handed back, because the directory records that one was used and cannot reproduce it.
|
|
2104
|
+
|
|
2105
|
+
```python
|
|
2106
|
+
index.save("my_index.zdb")
|
|
2107
|
+
|
|
2108
|
+
reopened = vdb.load("my_index.zdb", tokenizer=tokenize)
|
|
2109
|
+
```
|
|
2110
|
+
|
|
2111
|
+
`vdb.load("my_index.zdb")` on such a directory raises, since the directory records that a tokenizer of your own was used and cannot reproduce it. It records nothing that identifies which one, so a different callable opens it without complaint and tokenizes queries its own way. An index built with `"simple"` reopens with nothing handed.
|
|
2112
|
+
|
|
2113
|
+
---
|
|
2114
|
+
|
|
2115
|
+
<br/>
|
|
2116
|
+
|
|
2117
|
+
### 🧮 Sparse Vectors
|
|
2118
|
+
|
|
2119
|
+
A caller running their own sparse encoder declares the space without a tokenizer and supplies the pairs directly. The dimensions are the caller's own term ids and the values are the caller's own weights.
|
|
2120
|
+
|
|
2121
|
+
```python
|
|
2122
|
+
from zeusdb_vector_database import VectorDatabase
|
|
2123
|
+
|
|
2124
|
+
vdb = VectorDatabase()
|
|
2125
|
+
index = vdb.create("hnsw", dim=4, sparse={"name": "encoder"})
|
|
2126
|
+
|
|
2127
|
+
index.add([
|
|
2128
|
+
{"id": "d1", "values": [0.1, 0.1, 0.1, 0.1],
|
|
2129
|
+
"sparse": {"dims": [12, 977, 4021], "values": [0.41, 1.20, 0.08]}},
|
|
2130
|
+
{"id": "d2", "values": [0.2, 0.2, 0.2, 0.2],
|
|
2131
|
+
"sparse": {"dims": [12, 350], "values": [0.90, 0.15]}},
|
|
2132
|
+
])
|
|
2133
|
+
|
|
2134
|
+
hits = index.query(
|
|
2135
|
+
arms=[{"sparse": {"dims": [12, 977], "values": [0.9, 0.3]}}],
|
|
2136
|
+
top_k=2,
|
|
2137
|
+
)
|
|
2138
|
+
for hit in hits:
|
|
2139
|
+
print(hit["id"], round(hit["score"], 4))
|
|
2140
|
+
```
|
|
2141
|
+
|
|
2142
|
+
*Output*
|
|
2143
|
+
```
|
|
2144
|
+
d2 0.81
|
|
2145
|
+
d1 0.729
|
|
2146
|
+
```
|
|
2147
|
+
|
|
2148
|
+
| Key | Takes | Means |
|
|
2149
|
+
|-----|-------|-------|
|
|
2150
|
+
| `dims` | a list of integers | Term ids, strictly increasing |
|
|
2151
|
+
| `values` | a list of numbers | The weight of each term |
|
|
2152
|
+
|
|
2153
|
+
**The default weighting is `dot`**, which is the sum of products, and it leaves a trained encoder's weights alone. A space declared this way takes `sparse` and refuses `text`.
|
|
2154
|
+
|
|
2155
|
+
<br/>
|
|
2156
|
+
|
|
2157
|
+
**A caller counting terms themselves** declares `"weighting": "bm25"` and supplies raw counts. The engine then applies the saturation, the length normalisation and the rarity over the records the query admits.
|
|
2158
|
+
|
|
2159
|
+
```python
|
|
2160
|
+
index = vdb.create("hnsw", dim=4, sparse={"name": "counts", "weighting": "bm25"})
|
|
2161
|
+
|
|
2162
|
+
index.add({"id": "d1", "values": [0.1, 0.1, 0.1, 0.1],
|
|
2163
|
+
"sparse": {"dims": [3, 9, 41], "values": [2.0, 1.0, 1.0]}})
|
|
2164
|
+
```
|
|
2165
|
+
|
|
2166
|
+
Under `bm25` a value must be a whole number above zero, since a term frequency is a count. A trained encoder's weight is refused with the value named, which is what tells you the space wants `dot` instead.
|
|
2167
|
+
|
|
2168
|
+
---
|
|
2169
|
+
|
|
2170
|
+
<br/>
|
|
2171
|
+
|
|
2172
|
+
### 🔀 Hybrid Search
|
|
2173
|
+
|
|
2174
|
+
`query()` runs several arms over one set of candidates and fuses their pages by rank. An arm is a dense vector, a sparse vector or a text, and every arm shares the filter.
|
|
2175
|
+
|
|
2176
|
+
```python
|
|
2177
|
+
from zeusdb_vector_database import VectorDatabase
|
|
2178
|
+
|
|
2179
|
+
vdb = VectorDatabase()
|
|
2180
|
+
index = vdb.create("hnsw", dim=4, space="l2", sparse={"tokenizer": "simple"})
|
|
2181
|
+
|
|
2182
|
+
index.add([
|
|
2183
|
+
{"id": "d1", "values": [0.1, 0.1, 0.1, 0.1],
|
|
2184
|
+
"text": "the quick brown fox", "metadata": {"lang": "en"}},
|
|
2185
|
+
{"id": "d2", "values": [0.9, 0.9, 0.9, 0.9],
|
|
2186
|
+
"text": "a lazy brown dog", "metadata": {"lang": "en"}},
|
|
2187
|
+
{"id": "d3", "values": [0.2, 0.2, 0.2, 0.2],
|
|
2188
|
+
"text": "un renard brun rapide", "metadata": {"lang": "fr"}},
|
|
2189
|
+
])
|
|
2190
|
+
|
|
2191
|
+
hits = index.query(
|
|
2192
|
+
arms=[{"vector": [0.1, 0.1, 0.1, 0.1]}, {"text": "quick fox"}],
|
|
2193
|
+
filter={"lang": "en"},
|
|
2194
|
+
top_k=2,
|
|
2195
|
+
)
|
|
2196
|
+
for hit in hits:
|
|
2197
|
+
print(hit["id"], round(hit["score"], 4),
|
|
2198
|
+
[(c["arm"], c["rank"]) for c in hit["contributions"]])
|
|
2199
|
+
```
|
|
2200
|
+
|
|
2201
|
+
*Output*
|
|
2202
|
+
```
|
|
2203
|
+
d1 0.0328 [(0, 1), (1, 1)]
|
|
2204
|
+
d2 0.0161 [(0, 2)]
|
|
2205
|
+
```
|
|
2206
|
+
|
|
2207
|
+
| Argument | Takes | Means |
|
|
2208
|
+
|----------|-------|-------|
|
|
2209
|
+
| `arms` | a list of mappings | One to eight arms. Each names `vector`, `sparse` or `text` |
|
|
2210
|
+
| `filter` | a filter | Applied once, to every arm |
|
|
2211
|
+
| `top_k` | an integer | The page size |
|
|
2212
|
+
| `fetch` | an integer | What each arm contributes. Defaults to `top_k` for one arm and five times it for several |
|
|
2213
|
+
| `fusion` | `"rrf"` or a mapping | How the pages combine. `{"type": "rrf", "k": 60.0}` sets the constant |
|
|
2214
|
+
|
|
2215
|
+
**A hit carries its rank and score on every arm's page it appeared on**, under `contributions`, indexed by the arm's position in `arms`. A fused score is a rank sum and means nothing on its own, which is what the contributions are for.
|
|
2216
|
+
|
|
2217
|
+
<br/>
|
|
2218
|
+
|
|
2219
|
+
**An arm takes the options its own kind takes.** A dense arm takes `ef_search` and `rerank` as `search()` does, and a sparse or text arm takes `idf`.
|
|
2220
|
+
|
|
2221
|
+
```python
|
|
2222
|
+
hits = index.query(
|
|
2223
|
+
arms=[
|
|
2224
|
+
{"vector": [0.1, 0.1, 0.1, 0.1], "ef_search": 200},
|
|
2225
|
+
{"text": "quick fox", "idf": "global"},
|
|
2226
|
+
],
|
|
2227
|
+
top_k=2,
|
|
2228
|
+
fusion={"type": "rrf", "k": 30.0},
|
|
2229
|
+
)
|
|
2230
|
+
```
|
|
2231
|
+
|
|
2232
|
+
| Key | On | Means |
|
|
2233
|
+
|-----|----|-------|
|
|
2234
|
+
| `ef_search` | a dense arm | The search width, as `search()` takes it |
|
|
2235
|
+
| `rerank` | a dense arm | How many candidates to rescore against true vectors |
|
|
2236
|
+
| `idf` | a sparse or text arm | `"corpus"` counts term rarity over the records the filter admits, `"global"` over every record. Defaults to `"corpus"` |
|
|
2237
|
+
|
|
2238
|
+
**A one arm query is that arm's search.** A single dense arm returns the page `search()` returns, id for id and score for score, with each hit carrying its `contributions` as well. `query()` is the shape to reach for whenever more than one arm is in play.
|
|
2239
|
+
|
|
2240
|
+
---
|
|
2241
|
+
|
|
2242
|
+
<br/>
|
|
2243
|
+
|
|
2244
|
+
### 🗺️ Query Plans
|
|
2245
|
+
|
|
2246
|
+
`explain()` takes the same arguments as `query()` and returns what the query would do, without running it.
|
|
2247
|
+
|
|
2248
|
+
```python
|
|
2249
|
+
plan = index.explain(
|
|
2250
|
+
arms=[{"vector": [0.1, 0.1, 0.1, 0.1]}, {"text": "quick fox"}],
|
|
2251
|
+
filter={"lang": "en"},
|
|
2252
|
+
top_k=10,
|
|
2253
|
+
)
|
|
2254
|
+
print(plan["admit"])
|
|
2255
|
+
for arm in plan["arms"]:
|
|
2256
|
+
print(arm["kind"], arm["fetch"], round(arm["cost_ns"]))
|
|
2257
|
+
```
|
|
2258
|
+
|
|
2259
|
+
*Output*
|
|
2260
|
+
```
|
|
2261
|
+
{'shape': 'sorted', 'admitted': 2}
|
|
2262
|
+
dense 50 235
|
|
2263
|
+
sparse 50 22
|
|
2264
|
+
```
|
|
2265
|
+
|
|
2266
|
+
| Key | Means |
|
|
2267
|
+
|-----|-------|
|
|
2268
|
+
| `admit` | The shape the filter compiled to, and how many records it admits |
|
|
2269
|
+
| `arms` | One entry per arm, carrying its space, kind, fetch, estimated cost and whether its page is exact |
|
|
2270
|
+
| `fusion` | The rule the pages combine under, or `None` for one arm |
|
|
2271
|
+
|
|
2272
|
+
**`cost_ns` is an arm's own estimate of its own work**, in nanoseconds, and it is a figure to compare arms of one query by. It leaves out the filter's evaluation and the page's assembly, so a wall time you measure will exceed it.
|
|
2273
|
+
|
|
2274
|
+
<br/>
|
|
2275
|
+
|
|
2276
|
+
**The admit shape says how the filter was answered.**
|
|
2277
|
+
|
|
2278
|
+
| Shape | Means |
|
|
2279
|
+
|-------|-------|
|
|
2280
|
+
| `all` | Every live record, either no filter or one that admits all of them |
|
|
2281
|
+
| `bitmap` | A filter every field of which is declared, answered from the columns |
|
|
2282
|
+
| `sorted` | A short list of matching records, walked exactly |
|
|
2283
|
+
| `bounded` | A walk that stopped at a bound, so the count is an upper limit |
|
|
2284
|
+
| `predicate` | A walk that gave up, so each candidate is tested as it is visited |
|
|
2285
|
+
|
|
2286
|
+
---
|
|
2287
|
+
|
|
2288
|
+
<br/>
|
|
2289
|
+
|
|
2290
|
+
### 📊 Statistics
|
|
2291
|
+
|
|
2292
|
+
An index holding a sparse space reports it in `get_stats()` beside the dense figures.
|
|
2293
|
+
|
|
2294
|
+
```python
|
|
2295
|
+
stats = index.get_stats()
|
|
2296
|
+
for key in ("sparse_space", "sparse_weighting", "sparse_records",
|
|
2297
|
+
"sparse_postings", "sparse_memory_mb"):
|
|
2298
|
+
print(key, stats[key])
|
|
2299
|
+
```
|
|
2300
|
+
|
|
2301
|
+
*Output*
|
|
2302
|
+
```
|
|
2303
|
+
sparse_space sparse
|
|
2304
|
+
sparse_weighting bm25
|
|
2305
|
+
sparse_records 3
|
|
2306
|
+
sparse_postings 12
|
|
2307
|
+
sparse_memory_mb 0.00
|
|
2308
|
+
```
|
|
2309
|
+
|
|
2310
|
+
| Key | Means |
|
|
2311
|
+
|-----|-------|
|
|
2312
|
+
| `sparse_space` | The space's name |
|
|
2313
|
+
| `sparse_weighting` | `dot` or `bm25` |
|
|
2314
|
+
| `sparse_records` | Records the space holds, which may be fewer than the index holds |
|
|
2315
|
+
| `sparse_postings` | Live entries across every record, one per distinct term per record |
|
|
2316
|
+
| `sparse_dead_postings` | Occurrences left by removed records, reclaimed at `compact()` |
|
|
2317
|
+
| `sparse_memory_mb` | What the postings and their index hold |
|
|
2318
|
+
| `sparse_tokenizer` | `simple` or `external`, on a text layer alone |
|
|
2319
|
+
| `term_count` | Distinct terms the dictionary holds, on a text layer alone |
|
|
2320
|
+
| `dictionary_memory_mb` | What the dictionary holds, on a text layer alone |
|
|
2321
|
+
|
|
2322
|
+
**These keys are present on a sparse index and absent otherwise**, and `total_memory_mb` sums them in.
|
|
2323
|
+
|
|
1978
2324
|
<br />
|
|
1979
2325
|
|
|
1980
2326
|
## 📝 Logging
|