epzero 0.4.0__tar.gz → 0.6.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.
- epzero-0.6.0/CHANGELOG.md +213 -0
- {epzero-0.4.0 → epzero-0.6.0}/CMakeLists.txt +51 -23
- {epzero-0.4.0 → epzero-0.6.0}/PKG-INFO +115 -7
- {epzero-0.4.0 → epzero-0.6.0}/bench/bench_recall.cpp +3 -1
- epzero-0.6.0/bench/regression.json +58 -0
- epzero-0.6.0/fuzz/fuzz_metadata.cpp +23 -0
- {epzero-0.4.0 → epzero-0.6.0}/fuzz/make_seeds.cpp +12 -2
- epzero-0.6.0/include/epzero/auto.h +130 -0
- {epzero-0.4.0 → epzero-0.6.0}/include/epzero/database.h +4 -1
- {epzero-0.4.0 → epzero-0.6.0}/include/epzero/distance.h +17 -0
- {epzero-0.4.0 → epzero-0.6.0}/include/epzero/hnsw.h +86 -6
- epzero-0.6.0/include/epzero/metadata.h +92 -0
- {epzero-0.4.0 → epzero-0.6.0}/include/epzero/text.h +13 -3
- {epzero-0.4.0 → epzero-0.6.0}/pyproject.toml +6 -3
- {epzero-0.4.0 → epzero-0.6.0}/python/README.md +107 -6
- {epzero-0.4.0 → epzero-0.6.0}/python/epzero/__init__.py +2 -1
- {epzero-0.4.0 → epzero-0.6.0}/python/epzero/auto.py +15 -3
- epzero-0.6.0/python/epzero/haystack.py +283 -0
- epzero-0.6.0/python/epzero/ir.py +279 -0
- {epzero-0.4.0 → epzero-0.6.0}/python/epzero/langchain.py +50 -7
- epzero-0.6.0/python/epzero/llamaindex.py +243 -0
- {epzero-0.4.0 → epzero-0.6.0}/python/epzero_py.cpp +466 -46
- {epzero-0.4.0 → epzero-0.6.0}/python/tests/test_auto.py +85 -0
- {epzero-0.4.0 → epzero-0.6.0}/python/tests/test_epzero.py +134 -2
- epzero-0.6.0/python/tests/test_haystack.py +74 -0
- epzero-0.6.0/python/tests/test_ir.py +160 -0
- {epzero-0.4.0 → epzero-0.6.0}/python/tests/test_langchain.py +17 -0
- epzero-0.6.0/python/tests/test_llamaindex.py +91 -0
- epzero-0.6.0/python/tests/test_metadata.py +67 -0
- epzero-0.6.0/src/auto.cpp +674 -0
- {epzero-0.4.0 → epzero-0.6.0}/src/brute_force.cpp +6 -1
- {epzero-0.4.0 → epzero-0.6.0}/src/database.cpp +87 -27
- {epzero-0.4.0 → epzero-0.6.0}/src/distance.cpp +84 -21
- {epzero-0.4.0 → epzero-0.6.0}/src/distance_avx2.cpp +34 -0
- epzero-0.6.0/src/distance_avx512vnni.cpp +72 -0
- {epzero-0.4.0 → epzero-0.6.0}/src/distance_avxvnni.cpp +27 -0
- epzero-0.6.0/src/distance_f16c.cpp +79 -0
- {epzero-0.4.0 → epzero-0.6.0}/src/distance_neon.cpp +73 -0
- {epzero-0.4.0 → epzero-0.6.0}/src/distance_scalar.cpp +37 -0
- epzero-0.6.0/src/half.h +60 -0
- {epzero-0.4.0 → epzero-0.6.0}/src/hnsw.cpp +389 -59
- {epzero-0.4.0 → epzero-0.6.0}/src/kernels.h +17 -0
- epzero-0.6.0/src/metadata.cpp +295 -0
- epzero-0.6.0/src/platform.h +154 -0
- epzero-0.6.0/src/porter.h +233 -0
- epzero-0.6.0/src/sq4.h +49 -0
- {epzero-0.4.0 → epzero-0.6.0}/src/text.cpp +36 -8
- epzero-0.6.0/tests/auto_test.cpp +453 -0
- epzero-0.6.0/tests/data/v4-from-0.4.0.epzero +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/tests/database_test.cpp +34 -2
- {epzero-0.4.0 → epzero-0.6.0}/tests/distance_test.cpp +32 -0
- epzero-0.6.0/tests/half_test.cpp +182 -0
- {epzero-0.4.0 → epzero-0.6.0}/tests/hnsw_test.cpp +262 -0
- epzero-0.6.0/tests/metadata_test.cpp +116 -0
- {epzero-0.4.0 → epzero-0.6.0}/tests/text_test.cpp +32 -0
- {epzero-0.4.0 → epzero-0.6.0}/wasm/epzero_wasm.cpp +52 -2
- epzero-0.4.0/CHANGELOG.md +0 -54
- epzero-0.4.0/include/epzero/auto.h +0 -70
- epzero-0.4.0/src/auto.cpp +0 -269
- epzero-0.4.0/src/distance_avx512vnni.cpp +0 -34
- epzero-0.4.0/tests/auto_test.cpp +0 -216
- {epzero-0.4.0 → epzero-0.6.0}/bench/bench_adaptive.cpp +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/bench/bench_churn.cpp +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/bench/bench_distance.cpp +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/bench/bench_filter.cpp +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/bench/bench_guard.cpp +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/fuzz/common.h +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/fuzz/fuzz_graph.cpp +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/fuzz/fuzz_snapshot.cpp +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/fuzz/fuzz_text.cpp +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/fuzz/fuzz_wal.cpp +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/fuzz/regressions/graph-empty-with-entry-point +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/fuzz/regressions/graph-entry-level-overflow +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/fuzz/regressions/graph-upper-link-to-base-node +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/fuzz/regressions/snapshot-empty-with-entry-point +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/fuzz/regressions/snapshot-huge-capacity +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/include/epzero/brute_force.h +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/include/epzero/dataset.h +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/include/epzero/parallel.h +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/include/epzero/recall.h +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/server/node_main.cpp +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/src/dataset.cpp +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/src/distance_avx512.cpp +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/src/distance_wasm.cpp +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/src/pca.h +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/src/rabitq.h +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/src/recall.cpp +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/src/visited_pool.h +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/tests/dataset_test.cpp +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/tests/recall_test.cpp +0 -0
- {epzero-0.4.0 → epzero-0.6.0}/tools/export_graph.cpp +0 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
Indexes that keep growing without leaving their newest vectors behind; 4-bit codes; walks on principal
|
|
6
|
+
directions chosen by measurement (opt-in); faster builds; a deeper re-rank at k = 100; and a library that
|
|
7
|
+
refuses the usual first-time mistakes with a clear message. Files written by 0.5 load unchanged.
|
|
8
|
+
|
|
9
|
+
**Indexes that keep growing.** A vector inserted late has had no time to gain incoming links from
|
|
10
|
+
later arrivals, so the newest vectors of a grown index are found less often than in a rebuild.
|
|
11
|
+
|
|
12
|
+
- `extra_backlinks` (Python: `Index(..., extra_backlinks=8)`, `epzero.build(..., extra_backlinks=8)`;
|
|
13
|
+
C++: `HnswParams::extra_backlinks`): each insertion also asks that many of its closest construction
|
|
14
|
+
candidates that it did not choose to link to it. Off by default; not saved with the index, so
|
|
15
|
+
`index.set_extra_backlinks(n)` sets it again after `load()`.
|
|
16
|
+
- `index.refine_links(ef=..., first=n)`: reconnects only the vectors inserted from position `n` on, for
|
|
17
|
+
a checkpoint after a batch of additions. It returns the number of vectors refined. `around=True` also
|
|
18
|
+
refines the older vectors those link to, so that they can choose the new ones beside them.
|
|
19
|
+
- Both are opt-in. A one-off build doesn't change. Together (8 extra links, each batch refined at a beam
|
|
20
|
+
of 100) they removed the newest vectors' extra misses on a growing collection for about 9% more
|
|
21
|
+
insertion work.
|
|
22
|
+
|
|
23
|
+
**4-bit codes.** The graph walk can score 4-bit codes instead of 8-bit ones: half the bytes per scored
|
|
24
|
+
node, on the same per-dimension ranges at 16 levels, with the full vectors re-ranking more of the beam.
|
|
25
|
+
|
|
26
|
+
- `epzero.build(..., code_bits=4)` builds the graph on 8-bit codes as before and walks it on 4-bit ones.
|
|
27
|
+
They were 25-43% faster on GooAQ and Yahoo (walks over every dimension) and slower on most walks on
|
|
28
|
+
principal directions and on CLIP and ALIGN image vectors (Xeon Gold 6226), so the default stays 8 bits.
|
|
29
|
+
- `measure_code_bits=True` calibrates and times the walk at both widths on the same graph and keeps 4 bits
|
|
30
|
+
only where they reach the recall target at least 3% faster (`index.plan.reasons["code_bits"]` gives both
|
|
31
|
+
timings). Opt-in: its choice was within 3% of the better one on 9 of 12 datasets, but 24% slower on GooAQ
|
|
32
|
+
at k = 10, where the two tied at calibration. Below 128 codes per vector it keeps 8 bits without trying.
|
|
33
|
+
- `index.set_code_bits(4)` (C++: `HnswIndex::set_code_bits`) converts a built index in place, keeping
|
|
34
|
+
the graph, and back with `set_code_bits(8)`. 4-bit codes need the full vectors (the default).
|
|
35
|
+
- Integer kernels for AVX2, AVX-VNNI, AVX-512 VNNI and NEON (base ARMv8, no dot-product extension needed);
|
|
36
|
+
WebAssembly uses a scalar kernel for 4-bit codes, so there the planner's timing keeps 8 bits.
|
|
37
|
+
- Saved with the index as a storage flag; builds before this one refuse such a file instead of misreading it.
|
|
38
|
+
|
|
39
|
+
**Walking on the right directions, chosen by measurement (opt-in).**
|
|
40
|
+
|
|
41
|
+
- `check_walk=True`: with your own `queries=`, if they look unlike the data (as `check_queries` judges, on a
|
|
42
|
+
sample before the build), the build times the variance rule's walk on principal directions against no walk,
|
|
43
|
+
on 50,000 rows, and keeps the faster. On COCO (text queries against image vectors) the rule's 128-direction
|
|
44
|
+
walk never reached recall 0.95 (beam width 4096); with the check, no walk reached it at 128, for 26% more build
|
|
45
|
+
time on a laptop. On the full set on a Xeon Gold 6226 the highest recall rose from 0.76-0.82 to 0.996, for 1.5x
|
|
46
|
+
the build time (25 to 38 s). Queries like the data skip the trial (AG News: build time unchanged).
|
|
47
|
+
- `measure_nav=True`: the number of directions itself by trial indexes on 100,000 rows (none, 128-512 and the
|
|
48
|
+
rule's), timed on your queries or on held-out rows. On eight datasets it chose the count that was fastest on
|
|
49
|
+
the full data, or within 5% of it, 15 times out of 16 (Xeon Gold 6226, round 14), but it costs 2-3.5x the build
|
|
50
|
+
time, so it stays opt-in.
|
|
51
|
+
|
|
52
|
+
**Searching deeper at k = 100.** With the walk on principal directions, the early-stopping re-rank with
|
|
53
|
+
full vectors now scores up to max(`rerank`, `ef`) candidates instead of `rerank`: at k = 100 a wide beam
|
|
54
|
+
holds true neighbours past the first 300. Highest recall at k = 100 rose from 0.987 to 0.999 on AG News,
|
|
55
|
+
0.970 to 0.999 on arXiv and 0.910 to 0.995 on GIST1M; at k = 10 the early stop ends the re-rank first,
|
|
56
|
+
and speed is unchanged within 1-2%.
|
|
57
|
+
|
|
58
|
+
**Faster builds.**
|
|
59
|
+
|
|
60
|
+
- Building with 16-bit full vectors (`half_vectors=True`) and no walk on principal directions widened each
|
|
61
|
+
stored vector to floats one value at a time for every pair the build compared; it now uses F16C or NEON.
|
|
62
|
+
Such a build took 2.6x as long as an 8-bit one on 300,000 AG News vectors (1.7x on GooAQ, 24 cores); now 1.01x,
|
|
63
|
+
and 0.68-1.02x on nine datasets on a Xeon Gold 6226 (GooAQ 0.82x). 16-bit vectors stay opt-in: they cost up to
|
|
64
|
+
0.006 recall at 10 neighbours on some text embeddings.
|
|
65
|
+
- A build that also times 4-bit codes computes its calibration queries' exact neighbours once, not twice.
|
|
66
|
+
- `refine_ef=` sets the refine pass's beam width (by default efConstruction with a walk on directions, half
|
|
67
|
+
of it without).
|
|
68
|
+
|
|
69
|
+
**Friendlier for a first-time user** (found by installing from PyPI and trying the usual mistakes):
|
|
70
|
+
|
|
71
|
+
- Vectors or queries holding a NaN or an infinity are refused with the row and column (`ValueError: row 42
|
|
72
|
+
contains NaN (column 5)`). Before, such data built an index that calibrated to its widest beam and returned
|
|
73
|
+
noise. C++: `HnswIndex::add` throws `std::invalid_argument`, and `Database` refuses them before they reach
|
|
74
|
+
its log. A log written by an older version that holds such a vector still opens: the vector is skipped
|
|
75
|
+
and counted in `recovery()["skipped"]`, on a replica too.
|
|
76
|
+
- Metric names other libraries use are accepted, in any case: `"euclidean"` and `"l2sq"` for `"l2"`, `"dot"`,
|
|
77
|
+
`"inner_product"` and `"mips"` for `"ip"`, `"angular"` and `"cos"` for `"cosine"`.
|
|
78
|
+
- `save`, `load` and `Database.open` take any path-like object (`pathlib.Path`), not only strings.
|
|
79
|
+
- A negative `k`, `ef` or `rerank` gets `ValueError: k must be 0 or more` instead of a pybind11 cast error.
|
|
80
|
+
- `search` documents what fills a short result: label -1 and distance inf.
|
|
81
|
+
|
|
82
|
+
**Retrieval evaluation** (`epzero.ir`): run files keep full score precision; qrels with a non-integer or
|
|
83
|
+
non-finite grade, or a duplicate judgment, are refused with the file and the offending value; `evaluate(...,
|
|
84
|
+
population=...)` chooses which queries count (`"positive"`, the default and the earlier behaviour, `"judged"`,
|
|
85
|
+
or `"explicit"` with `query_ids=`), and a query missing from the run scores 0.
|
|
86
|
+
|
|
87
|
+
## 0.5.0
|
|
88
|
+
|
|
89
|
+
An index that stays accurate as its data changes, fixed in place; metadata and keyword search in the
|
|
90
|
+
engine; LlamaIndex and Haystack beside LangChain; retrieval evaluation; and Windows. Files written by
|
|
91
|
+
0.4 load unchanged.
|
|
92
|
+
|
|
93
|
+
**Staying accurate after the build.**
|
|
94
|
+
|
|
95
|
+
- `index.recalibrate(queries)` (C++: `epzero::recalibrate`): re-measures the beam width for the
|
|
96
|
+
recall target on real queries and saves it in the profile, without rebuilding.
|
|
97
|
+
- `index.health()` (C++: `check_health`): live and deleted vectors, growth since calibration, and how
|
|
98
|
+
much of the data the principal directions still capture, with advice in plain words: compact,
|
|
99
|
+
recalibrate, or rebuild.
|
|
100
|
+
- `RecallGuard(index)` takes its target and starting beam width from the profile.
|
|
101
|
+
- `index.check_queries(queries)` (C++: `check_queries`) says whether queries look like the data: text
|
|
102
|
+
queries against image vectors sit 2.2-2.3× farther from their nearest neighbours than rows of the data,
|
|
103
|
+
against 0.99-1.09× for queries like the data, and recall calibrated on the data then falls to 0.74-0.80
|
|
104
|
+
for a 0.95 target. Its advice: `recalibrate(queries)`, which restored 0.945-0.958 on VIBE's
|
|
105
|
+
text-to-image sets.
|
|
106
|
+
- `index.requantize()` (C++: `HnswIndex::requantize`, then `refine_links`): for vectors added since the
|
|
107
|
+
build that lie outside the ranges the 8-bit codes were fitted on. It refits the ranges on the live
|
|
108
|
+
vectors, re-encodes them and reconnects the graph, in about half a rebuild's time; after a 4 sd drift
|
|
109
|
+
it brought the beam width for recall 0.95 from 200 back to a rebuild's 12. `health()` reports
|
|
110
|
+
`code_error` and advises it above 0.01.
|
|
111
|
+
- `index.get_vector(label)` returns a stored vector.
|
|
112
|
+
|
|
113
|
+
**Information retrieval.** `epzero.ir`: a `Collection` of documents with string ids, retrieved by vector,
|
|
114
|
+
by keyword (BM25) or both (reciprocal rank fusion), growing and shrinking after the build; TREC run files
|
|
115
|
+
in and out; relevance judgements in TREC or BEIR form; nDCG@k, MAP, recall, precision and MRR, matching
|
|
116
|
+
trec_eval (tested against it); and a BEIR dataset loader.
|
|
117
|
+
|
|
118
|
+
**Stemming.** `TextIndex` reduces English words to their Porter stems, so "connections" matches
|
|
119
|
+
"connected" (`stemmer="none"` keeps words as written). It is the reference implementation's algorithm,
|
|
120
|
+
the one Lucene and Anserini use, and agrees with NLTK's on all 39,011 words of SciFact's and NFCorpus's
|
|
121
|
+
vocabularies. nDCG@10 for BM25 went from 0.660 to 0.688 on SciFact and from 0.305 to 0.321 on NFCorpus
|
|
122
|
+
(BEIR's Anserini baselines: 0.665 and 0.325), and for hybrid search with all-MiniLM-L6-v2 from 0.682 to
|
|
123
|
+
0.713 and from 0.344 to 0.354. Stemmed text indexes are saved as text format 2; files saved before load
|
|
124
|
+
unstemmed, as they were written.
|
|
125
|
+
|
|
126
|
+
**Fixes.** `hybrid_search` searched with a fixed beam width of 64 and the default re-rank, ignoring the
|
|
127
|
+
index's calibrated profile; it now uses the profile unless `ef` is given. Calibration could settle on a
|
|
128
|
+
beam width below k, which only k-sized searches had measured.
|
|
129
|
+
|
|
130
|
+
**File format 5.** Indexes with a profile or 16-bit vectors are written as version 5; 0.4's version 4
|
|
131
|
+
files are still read (a file written by 0.4.0 is part of the test suite). See `docs/file-format.md`.
|
|
132
|
+
|
|
133
|
+
**Indexes grow.** `add()` no longer fails when an index is full: it grows the capacity (at least
|
|
134
|
+
doubling), copying the nodes and keeping the graph; `index.reserve(n)` and `index.capacity` do it ahead.
|
|
135
|
+
The LangChain, LlamaIndex and Haystack stores, which rebuilt their whole graph each time they filled, now
|
|
136
|
+
grow in place: loading 40,000 documents in batches of 100 went from 6.0 s to 3.4 s. Searches on other
|
|
137
|
+
threads wait for a growth, which moves the index's memory; with a RecallGuard attached, growing must be
|
|
138
|
+
done beforehand with `reserve()`.
|
|
139
|
+
|
|
140
|
+
**Metadata in the engine.** `epzero.Metadata` (C++: `MetadataIndex`) keeps str, int, float and bool fields
|
|
141
|
+
per label, with an inverted index per field and ordered numeric values, and `select(where)` returns the
|
|
142
|
+
labels that pass ({field: value}, {field: [values]}, or `$eq`, `$ne`, `$in`, `$nin`, `$gt`, `$gte`, `$lt`,
|
|
143
|
+
`$lte`, `$exists`) for a filtered search. The LangChain store now runs dict filters there instead of
|
|
144
|
+
checking every document in Python. Saved in its own file format, fuzzed in CI.
|
|
145
|
+
|
|
146
|
+
**Memory.** `half_vectors=True` keeps the full vectors as 16-bit floats: about half an index's memory,
|
|
147
|
+
at some speed (up to 17% on GIST1M) and recall (0.003-0.004 on OpenAI embeddings), so never chosen
|
|
148
|
+
automatically. Full-precision search is 4-9% faster, as vector addresses are resolved once per query.
|
|
149
|
+
|
|
150
|
+
**LlamaIndex.** `epzero.llamaindex.EpzeroVectorStore` (`pip install "epzero[llamaindex]"`): nodes with
|
|
151
|
+
their text and metadata, filters in the engine, `delete_ref_doc`, and persistence.
|
|
152
|
+
|
|
153
|
+
**Haystack.** `epzero.haystack.EpzeroDocumentStore` and `EpzeroEmbeddingRetriever`
|
|
154
|
+
(`pip install "epzero[haystack]"`): Haystack filters in the engine where the answer is provably the same,
|
|
155
|
+
and Haystack's document-store test suite passes.
|
|
156
|
+
|
|
157
|
+
**Windows.** The engine builds with MSVC and its tests run on Windows in CI; wheels for Windows (x64).
|
|
158
|
+
|
|
159
|
+
**Easier to read.** `Index`, `Metadata`, `TextIndex` and `Database` print what they hold (size, metric,
|
|
160
|
+
compression, calibrated beam width), and shape and name errors say what was passed.
|
|
161
|
+
|
|
162
|
+
## 0.4.0
|
|
163
|
+
|
|
164
|
+
**Automatic configuration.** `epzero.build(vectors, metric=...)` (C++: `epzero::build_auto` in
|
|
165
|
+
`epzero/auto.h`) configures an index from its data and the machine it is built on:
|
|
166
|
+
|
|
167
|
+
- From the data: 8-bit codes, whether to walk the graph on principal directions (at 256 dimensions or
|
|
168
|
+
more, when few directions hold most of the variance), the build passes, the re-rank, and the beam
|
|
169
|
+
width (`ef`) that reaches a recall target, calibrated on rows held out of the graph or on queries
|
|
170
|
+
you pass (`queries=`).
|
|
171
|
+
- From the machine: the prefetch setting, timed on this CPU, and every core.
|
|
172
|
+
- Measured on an Intel Xeon Gold 6226 and an AMD Threadripper PRO 9985WX: as fast as hand-tuned
|
|
173
|
+
settings (within 1-5%), recall 0.949-0.957 on real queries for a 0.95 target, and 1.3-4.1× Glass's
|
|
174
|
+
queries per second on GIST1M, OpenAI DBpedia and DEEP10M.
|
|
175
|
+
- Every setting can be fixed instead (`epzero.build(vectors, nav_dim=0, M=32)`, or `epzero.plan()`,
|
|
176
|
+
edit, build). `index.plan` shows each setting and why it was chosen.
|
|
177
|
+
- The choices are saved inside the index (`IndexProfile`, file format v4), and `search()` uses them
|
|
178
|
+
when called without settings. A loaded index re-applies its prefetch setting only on the same kind
|
|
179
|
+
of CPU (`epzero.machine()` names it).
|
|
180
|
+
|
|
181
|
+
**Faster search and builds.**
|
|
182
|
+
|
|
183
|
+
- `nav_dim`: walk the graph on 8-bit codes of principal directions, re-ranking with the full vectors.
|
|
184
|
+
With the other changes here, 2.8-4.2× Glass's queries per second on GIST1M and 1.6-2.7× on OpenAI
|
|
185
|
+
DBpedia embeddings at equal recall, on Intel and AMD servers.
|
|
186
|
+
- `refine_links()`: a second build pass in which every node searches the finished graph and
|
|
187
|
+
reconnects; `fill_free_links()` gives free link slots to two-hop neighbours.
|
|
188
|
+
- `fast_build`: build on the 8-bit codes.
|
|
189
|
+
- `rerank_z`: stop the re-rank early once the remaining candidates can't reach the top k.
|
|
190
|
+
- Queries are projected onto principal directions on the integer kernel; the AVX2 and AVX-VNNI integer
|
|
191
|
+
kernels finish with vector loads instead of a scalar tail.
|
|
192
|
+
- The prefetch tuner can fetch a record's every cache line; on a Xeon Gold 6226 that was worth up to
|
|
193
|
+
1.7× on some datasets.
|
|
194
|
+
- PCA runs as blocked matrix products (choosing directions 5× faster on GIST1M), training runs on
|
|
195
|
+
every core, and index memory is zeroed on every core, which spreads it across NUMA nodes.
|
|
196
|
+
|
|
197
|
+
**Fixes.**
|
|
198
|
+
|
|
199
|
+
- `Database`: a write that could not be applied (the database full, or not yet trained) was written to
|
|
200
|
+
the log first, after which every open failed replaying it. Writes are now checked before they are
|
|
201
|
+
logged, and replacing a vector in a full database frees its slot before compacting.
|
|
202
|
+
- `RecallGuard` searched, and measured its reference, with the default re-rank depth; it now uses the
|
|
203
|
+
index's own settings and re-ranks the reference's whole beam. `explain()` and `trace()` likewise.
|
|
204
|
+
- The LangChain store copied every stored vector on each add (quadratic in the store's size).
|
|
205
|
+
- `pip install epzero` from source failed on machines with gRPC installed: it tried to build the
|
|
206
|
+
cluster node, whose protocol files aren't in the package.
|
|
207
|
+
|
|
208
|
+
**Compatibility.** Indexes without a profile are still written in the format older versions read
|
|
209
|
+
(v2, or v3 with principal directions); automatically configured ones are v4, which 0.3 cannot load.
|
|
210
|
+
`search()`'s `k`, `ef`, `rerank` and `rerank_z` now default to the index's profile, which for an index
|
|
211
|
+
built by hand is the old defaults (10, 64, 2 × k, off).
|
|
212
|
+
|
|
213
|
+
Earlier releases are described by their git tags (`v0.2.0`, `v0.3.0`).
|
|
@@ -52,6 +52,7 @@ add_library(epzero_engine
|
|
|
52
52
|
src/distance.cpp
|
|
53
53
|
src/distance_scalar.cpp
|
|
54
54
|
src/hnsw.cpp
|
|
55
|
+
src/metadata.cpp
|
|
55
56
|
src/recall.cpp
|
|
56
57
|
src/database.cpp
|
|
57
58
|
src/text.cpp
|
|
@@ -60,20 +61,38 @@ add_library(epzero_engine
|
|
|
60
61
|
)
|
|
61
62
|
target_include_directories(epzero_engine PUBLIC include PRIVATE src)
|
|
62
63
|
target_link_libraries(epzero_engine PUBLIC Threads::Threads)
|
|
63
|
-
|
|
64
|
+
if(MSVC)
|
|
65
|
+
target_compile_options(epzero_engine PRIVATE /W3 /utf-8 /permissive- /Zc:__cplusplus)
|
|
66
|
+
target_compile_definitions(epzero_engine PRIVATE _CRT_SECURE_NO_WARNINGS NOMINMAX)
|
|
67
|
+
else()
|
|
68
|
+
target_compile_options(epzero_engine PRIVATE -Wall -Wextra -Wpedantic)
|
|
69
|
+
endif()
|
|
64
70
|
set_target_properties(epzero_engine PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
|
65
71
|
|
|
66
72
|
# SIMD kernels get ISA flags per file; the rest of the library stays baseline so the binary
|
|
67
73
|
# runs on any CPU of the architecture and picks the best kernel at runtime.
|
|
68
74
|
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64|amd64")
|
|
69
|
-
target_sources(epzero_engine PRIVATE src/distance_avx2.cpp src/distance_avx512.cpp)
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
target_sources(epzero_engine PRIVATE src/distance_avx2.cpp src/distance_avx512.cpp src/distance_f16c.cpp)
|
|
76
|
+
if(MSVC) # MSVC allows any intrinsic; /arch only lets the compiler use the ISA on its own
|
|
77
|
+
set_source_files_properties(src/distance_f16c.cpp src/distance_avx2.cpp PROPERTIES COMPILE_OPTIONS "/arch:AVX2")
|
|
78
|
+
set_source_files_properties(src/distance_avx512.cpp PROPERTIES COMPILE_OPTIONS "/arch:AVX512")
|
|
79
|
+
else()
|
|
80
|
+
set_source_files_properties(src/distance_f16c.cpp PROPERTIES COMPILE_OPTIONS "-mavx2;-mfma;-mf16c")
|
|
81
|
+
set_source_files_properties(src/distance_avx2.cpp PROPERTIES COMPILE_OPTIONS "-mavx2;-mfma;-mpopcnt")
|
|
82
|
+
set_source_files_properties(src/distance_avx512.cpp PROPERTIES COMPILE_OPTIONS "-mavx512f")
|
|
83
|
+
endif()
|
|
72
84
|
# VNNI integer kernels, where the toolchain can build them: the compiler must know the
|
|
73
85
|
# instructions (GCC 11+, Clang 12+ for AVX-VNNI) and so must the assembler it hands them to
|
|
74
86
|
# (binutils 2.36+ for AVX-VNNI; RHEL 9's 2.35 doesn't), so each check compiles and links a use.
|
|
75
87
|
include(CheckCXXSourceCompiles)
|
|
76
|
-
|
|
88
|
+
if(MSVC)
|
|
89
|
+
set(EPZERO_AVXVNNI_FLAGS "/arch:AVX2")
|
|
90
|
+
set(EPZERO_AVX512VNNI_FLAGS "/arch:AVX512")
|
|
91
|
+
else()
|
|
92
|
+
set(EPZERO_AVXVNNI_FLAGS "-mavx2 -mavxvnni")
|
|
93
|
+
set(EPZERO_AVX512VNNI_FLAGS "-mavx512f -mavx512bw -mavx512vnni")
|
|
94
|
+
endif()
|
|
95
|
+
set(CMAKE_REQUIRED_FLAGS "${EPZERO_AVXVNNI_FLAGS}")
|
|
77
96
|
check_cxx_source_compiles([[
|
|
78
97
|
#include <immintrin.h>
|
|
79
98
|
int main(int argc, char**) {
|
|
@@ -81,7 +100,7 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64|amd64")
|
|
|
81
100
|
a = _mm256_dpbusd_avx_epi32(a, a, a);
|
|
82
101
|
return _mm256_extract_epi32(a, 0);
|
|
83
102
|
}]] EPZERO_TOOLCHAIN_AVXVNNI)
|
|
84
|
-
set(CMAKE_REQUIRED_FLAGS "
|
|
103
|
+
set(CMAKE_REQUIRED_FLAGS "${EPZERO_AVX512VNNI_FLAGS}")
|
|
85
104
|
check_cxx_source_compiles([[
|
|
86
105
|
#include <immintrin.h>
|
|
87
106
|
int main(int argc, char**) {
|
|
@@ -92,12 +111,14 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64|amd64")
|
|
|
92
111
|
unset(CMAKE_REQUIRED_FLAGS)
|
|
93
112
|
if(EPZERO_TOOLCHAIN_AVXVNNI)
|
|
94
113
|
target_sources(epzero_engine PRIVATE src/distance_avxvnni.cpp)
|
|
95
|
-
|
|
114
|
+
string(REPLACE " " ";" flags "${EPZERO_AVXVNNI_FLAGS}")
|
|
115
|
+
set_source_files_properties(src/distance_avxvnni.cpp PROPERTIES COMPILE_OPTIONS "${flags}")
|
|
96
116
|
set_property(SOURCE src/distance.cpp APPEND PROPERTY COMPILE_DEFINITIONS EPZERO_HAVE_AVXVNNI)
|
|
97
117
|
endif()
|
|
98
118
|
if(EPZERO_TOOLCHAIN_AVX512VNNI)
|
|
99
119
|
target_sources(epzero_engine PRIVATE src/distance_avx512vnni.cpp)
|
|
100
|
-
|
|
120
|
+
string(REPLACE " " ";" flags "${EPZERO_AVX512VNNI_FLAGS}")
|
|
121
|
+
set_source_files_properties(src/distance_avx512vnni.cpp PROPERTIES COMPILE_OPTIONS "${flags}")
|
|
101
122
|
set_property(SOURCE src/distance.cpp APPEND PROPERTY COMPILE_DEFINITIONS EPZERO_HAVE_AVX512VNNI)
|
|
102
123
|
endif()
|
|
103
124
|
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64")
|
|
@@ -119,8 +140,9 @@ if(EPZERO_BUILD_TESTS)
|
|
|
119
140
|
FetchContent_MakeAvailable(googletest)
|
|
120
141
|
|
|
121
142
|
enable_testing()
|
|
122
|
-
add_executable(epzero_tests tests/auto_test.cpp tests/distance_test.cpp tests/hnsw_test.cpp tests/recall_test.cpp tests/dataset_test.cpp tests/database_test.cpp tests/text_test.cpp)
|
|
143
|
+
add_executable(epzero_tests tests/auto_test.cpp tests/distance_test.cpp tests/half_test.cpp tests/hnsw_test.cpp tests/metadata_test.cpp tests/recall_test.cpp tests/dataset_test.cpp tests/database_test.cpp tests/text_test.cpp)
|
|
123
144
|
target_link_libraries(epzero_tests PRIVATE epzero_engine GTest::gtest_main)
|
|
145
|
+
target_compile_definitions(epzero_tests PRIVATE EPZERO_TEST_DATA="${CMAKE_CURRENT_SOURCE_DIR}/tests/data")
|
|
124
146
|
if(EMSCRIPTEN)
|
|
125
147
|
# Runs under Node (CMAKE_CROSSCOMPILING_EMULATOR); workers are pre-spawned for the
|
|
126
148
|
# concurrency tests and the real filesystem backs the save/load tests.
|
|
@@ -146,7 +168,7 @@ if(EPZERO_BUILD_BENCH)
|
|
|
146
168
|
endif()
|
|
147
169
|
|
|
148
170
|
if(EPZERO_BUILD_FUZZ)
|
|
149
|
-
foreach(target snapshot graph wal text)
|
|
171
|
+
foreach(target snapshot graph wal text metadata)
|
|
150
172
|
add_executable(fuzz_${target} fuzz/fuzz_${target}.cpp)
|
|
151
173
|
target_link_libraries(fuzz_${target} PRIVATE epzero_engine)
|
|
152
174
|
target_link_options(fuzz_${target} PRIVATE -fsanitize=fuzzer)
|
|
@@ -193,20 +215,26 @@ if(EPZERO_BUILD_NODE AND NOT EMSCRIPTEN)
|
|
|
193
215
|
endif()
|
|
194
216
|
|
|
195
217
|
if(EMSCRIPTEN)
|
|
196
|
-
# ES
|
|
197
|
-
|
|
198
|
-
|
|
218
|
+
# ES modules for the browser demo: `import createEpzero from "./epzero.js"`. epzero-lab.js adds the
|
|
219
|
+
# automatic configuration (build_auto) for the benchmark lab, which is 36 KB more compressed: kept out
|
|
220
|
+
# of the module every other page loads first.
|
|
221
|
+
foreach(web_target epzero_web epzero_lab)
|
|
222
|
+
add_executable(${web_target} wasm/epzero_wasm.cpp)
|
|
223
|
+
target_link_libraries(${web_target} PRIVATE epzero_engine)
|
|
224
|
+
target_link_options(${web_target} PRIVATE
|
|
225
|
+
-lembind -sMODULARIZE=1 -sEXPORT_ES6=1 -sEXPORT_NAME=createEpzero -sENVIRONMENT=web,worker -sSTACK_SIZE=1MB
|
|
226
|
+
# No eval / new Function in the generated bindings, so the site's Content Security Policy can
|
|
227
|
+
# forbid it (only WebAssembly compilation is allowed).
|
|
228
|
+
-sDYNAMIC_EXECUTION=0)
|
|
229
|
+
if(EPZERO_WASM_THREADS)
|
|
230
|
+
# Pre-spawn the workers: the module's own thread blocks while a build runs, so it cannot
|
|
231
|
+
# create new ones on demand.
|
|
232
|
+
target_link_options(${web_target} PRIVATE "-sPTHREAD_POOL_SIZE=Math.min(navigator.hardwareConcurrency,16)")
|
|
233
|
+
endif()
|
|
234
|
+
endforeach()
|
|
199
235
|
set_target_properties(epzero_web PROPERTIES OUTPUT_NAME epzero SUFFIX .js)
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
# No eval / new Function in the generated bindings, so the site's Content Security Policy can
|
|
203
|
-
# forbid it (only WebAssembly compilation is allowed).
|
|
204
|
-
-sDYNAMIC_EXECUTION=0)
|
|
205
|
-
if(EPZERO_WASM_THREADS)
|
|
206
|
-
# Pre-spawn the workers: the module's own thread blocks while a build runs, so it cannot
|
|
207
|
-
# create new ones on demand.
|
|
208
|
-
target_link_options(epzero_web PRIVATE "-sPTHREAD_POOL_SIZE=Math.min(navigator.hardwareConcurrency,16)")
|
|
209
|
-
endif()
|
|
236
|
+
set_target_properties(epzero_lab PROPERTIES OUTPUT_NAME epzero-lab SUFFIX .js)
|
|
237
|
+
target_compile_definitions(epzero_lab PRIVATE EPZERO_WASM_LAB_AUTO=1)
|
|
210
238
|
endif()
|
|
211
239
|
|
|
212
240
|
if(EPZERO_BUILD_PYTHON)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: epzero
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: A fast HNSW vector database in C++20 that configures itself: SIMD search, filtered search, recall monitoring, crash-safe storage
|
|
5
5
|
Keywords: vector database,hnsw,ann,nearest neighbor,embeddings,rag,langchain
|
|
6
6
|
Author: Lajat
|
|
@@ -12,6 +12,7 @@ Classifier: Programming Language :: C++
|
|
|
12
12
|
Classifier: Programming Language :: Python :: 3
|
|
13
13
|
Classifier: Operating System :: POSIX :: Linux
|
|
14
14
|
Classifier: Operating System :: MacOS
|
|
15
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
15
16
|
Classifier: Topic :: Database
|
|
16
17
|
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
17
18
|
Project-URL: Homepage, https://epzero.dev/
|
|
@@ -20,11 +21,17 @@ Requires-Python: >=3.10
|
|
|
20
21
|
Requires-Dist: numpy
|
|
21
22
|
Provides-Extra: langchain
|
|
22
23
|
Requires-Dist: langchain-core>=0.3; extra == "langchain"
|
|
24
|
+
Provides-Extra: llamaindex
|
|
25
|
+
Requires-Dist: llama-index-core>=0.12; extra == "llamaindex"
|
|
26
|
+
Provides-Extra: haystack
|
|
27
|
+
Requires-Dist: haystack-ai>=2.10; extra == "haystack"
|
|
23
28
|
Provides-Extra: test
|
|
24
29
|
Requires-Dist: pytest; extra == "test"
|
|
25
30
|
Requires-Dist: pytest-asyncio; extra == "test"
|
|
26
31
|
Requires-Dist: langchain-core>=0.3; extra == "test"
|
|
27
32
|
Requires-Dist: langchain-tests>=0.3; extra == "test"
|
|
33
|
+
Requires-Dist: llama-index-core>=0.12; extra == "test"
|
|
34
|
+
Requires-Dist: haystack-ai>=2.10; extra == "test"
|
|
28
35
|
Description-Content-Type: text/markdown
|
|
29
36
|
|
|
30
37
|
# epzero
|
|
@@ -45,16 +52,24 @@ An HNSW vector database written from scratch in C++20, with Python bindings.
|
|
|
45
52
|
confidence interval and moves the search effort to hold a target; `explain()` says why any given
|
|
46
53
|
item was not returned. With `per_query=True` each query also stops as soon as its answer settles,
|
|
47
54
|
so easy queries cost less and hard ones search further.
|
|
48
|
-
- **Hybrid search:** `TextIndex` (BM25 keyword search) and `hybrid_search()`,
|
|
49
|
-
with vector search by reciprocal rank fusion.
|
|
55
|
+
- **Hybrid search:** `TextIndex` (BM25 keyword search, with English stemming) and `hybrid_search()`,
|
|
56
|
+
which merges it with vector search by reciprocal rank fusion.
|
|
57
|
+
- **Retrieval evaluation:** `epzero.ir` keeps documents under string ids, runs dense, keyword and
|
|
58
|
+
hybrid retrieval, writes TREC run files and scores them against relevance judgements exactly as
|
|
59
|
+
trec_eval does. On BEIR with all-MiniLM-L6-v2, hybrid reaches nDCG@10 0.713 on SciFact and 0.354 on
|
|
60
|
+
NFCorpus, above either half alone.
|
|
50
61
|
- **Durable:** `Database` adds a write-ahead log with crash recovery and checkpoints.
|
|
51
62
|
- **8-bit quantization** with exact re-ranking, stopped early per query once the rest can't reach
|
|
52
63
|
the top k.
|
|
53
|
-
- **
|
|
64
|
+
- **Stays accurate as data changes:** `health()` says when an index needs recalibrating,
|
|
65
|
+
requantizing, compacting or rebuilding, and each fix runs in place.
|
|
66
|
+
- **LangChain, LlamaIndex and Haystack** stores, each passing its framework's own test suite.
|
|
54
67
|
|
|
55
68
|
```bash
|
|
56
69
|
pip install epzero # the engine
|
|
57
70
|
pip install "epzero[langchain]" # plus the LangChain vector store
|
|
71
|
+
pip install "epzero[llamaindex]" # plus the LlamaIndex vector store
|
|
72
|
+
pip install "epzero[haystack]" # plus the Haystack document store and retriever
|
|
58
73
|
```
|
|
59
74
|
|
|
60
75
|
## Quick start: let it configure itself
|
|
@@ -93,12 +108,56 @@ users get the same `build_auto()`.
|
|
|
93
108
|
If your queries differ from your data (text queries against image vectors, say), pass a few
|
|
94
109
|
hundred of them as `queries=`: recall calibrated on data rows is optimistic for those.
|
|
95
110
|
|
|
111
|
+
**Metadata.** Fields per label, filtered in the engine:
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
meta = epzero.Metadata()
|
|
115
|
+
meta.set_many(labels, [{"source": "faq", "year": 2024}, ...])
|
|
116
|
+
allowed = meta.select({"source": ["faq", "docs"], "year": {"$gte": 2022}})
|
|
117
|
+
labels, distances = index.search(queries, k=10, filter=index.filter(allowed))
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
**After the build.** An index keeps changing; its calibration doesn't, by itself:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
print(index.health()) # growth since calibration, deleted share, code error, fit of the directions, advice
|
|
124
|
+
print(index.check_queries(queries)) # do these queries look like the data? (text vs images: no)
|
|
125
|
+
index.recalibrate(queries) # re-measure the beam width on real queries; saved in the profile
|
|
126
|
+
index.requantize() # vectors drifted outside the 8-bit codes' ranges: refit and reconnect
|
|
127
|
+
guard = epzero.RecallGuard(index, sample_rate=0.01) # or measure live recall and adjust as you go
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
When later vectors drift outside the ranges the 8-bit codes were fitted on, they are clipped and
|
|
131
|
+
the graph links chosen for them suffer: in a synthetic test with a 4 sd drift, the beam width needed
|
|
132
|
+
for recall 0.95 went from 12 to 200. `requantize()` refits the codes and reconnects the graph in about half a rebuild's
|
|
133
|
+
time, back to 12.
|
|
134
|
+
|
|
135
|
+
**An index that keeps growing.** In a graph index, a vector inserted early keeps gaining incoming links
|
|
136
|
+
from everything added near it later, and one inserted late has had no time to. So the newest vectors are
|
|
137
|
+
found less often than in a fresh build of the same data. Two options make an index grown in batches
|
|
138
|
+
behave like a rebuild:
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
index = epzero.build(vectors, extra_backlinks=8) # each insertion is also linked from 8 nearby nodes
|
|
142
|
+
...
|
|
143
|
+
first = len(index) # before a batch (nothing removed since)
|
|
144
|
+
index.add(batch, labels=batch_labels)
|
|
145
|
+
index.refine_links(ef=100, first=first) # at a checkpoint: reconnect the batch, all cores
|
|
146
|
+
|
|
147
|
+
index = epzero.Index.load(path)
|
|
148
|
+
index.set_extra_backlinks(8) # not saved with the index: set it again after load
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Both are off by default. A one-off build gains nothing from them; they are for indexes that keep
|
|
152
|
+
growing. The checkpoint refine visits only the vectors added since `first`, so it takes a small
|
|
153
|
+
fraction of a rebuild's time.
|
|
154
|
+
|
|
96
155
|
## Configured by hand
|
|
97
156
|
|
|
98
157
|
```python
|
|
99
158
|
vectors = np.random.rand(100_000, 128).astype(np.float32)
|
|
100
159
|
index = epzero.Index(dim=128, metric="l2", max_elements=100_000, M=16, ef_construction=200)
|
|
101
|
-
index.add(vectors) # labels 0..n-1 (or pass labels=)
|
|
160
|
+
index.add(vectors) # labels 0..n-1 (or pass labels=); grows as needed
|
|
102
161
|
|
|
103
162
|
labels, distances = index.search(vectors[:5], k=10, ef=64)
|
|
104
163
|
|
|
@@ -145,9 +204,58 @@ metadata. They are compiled into an Epzero filter, so the engine chooses how to
|
|
|
145
204
|
documents instead of over-fetching and discarding. The store passes LangChain's standard
|
|
146
205
|
vector-store test suite.
|
|
147
206
|
|
|
207
|
+
## LlamaIndex
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
from llama_index.core import StorageContext, VectorStoreIndex
|
|
211
|
+
from epzero.llamaindex import EpzeroVectorStore
|
|
212
|
+
|
|
213
|
+
store = EpzeroVectorStore(metric="cosine")
|
|
214
|
+
index = VectorStoreIndex.from_documents(documents, storage_context=StorageContext.from_defaults(vector_store=store))
|
|
215
|
+
index.as_query_engine().query("How do I reset my password?")
|
|
216
|
+
store.persist("./epzero-store") # EpzeroVectorStore.from_persist_path("./epzero-store")
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Metadata filters (`==`, `!=`, `>`, `>=`, `<`, `<=`, `in`, `nin`, combined with AND or OR) run in the
|
|
220
|
+
engine, as do `doc_ids` and `node_ids`; `delete_ref_doc` removes a document's nodes.
|
|
221
|
+
|
|
222
|
+
## Haystack
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
from haystack import Pipeline
|
|
226
|
+
from epzero.haystack import EpzeroDocumentStore, EpzeroEmbeddingRetriever
|
|
227
|
+
|
|
228
|
+
store = EpzeroDocumentStore(metric="cosine")
|
|
229
|
+
store.write_documents(documents) # Documents with embeddings
|
|
230
|
+
pipeline = Pipeline()
|
|
231
|
+
pipeline.add_component("retriever", EpzeroEmbeddingRetriever(document_store=store, top_k=5))
|
|
232
|
+
pipeline.run({"retriever": {"query_embedding": embedding,
|
|
233
|
+
"filters": {"field": "meta.lang", "operator": "==", "value": "en"}}})
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Filters use Haystack's syntax and run in the engine wherever that gives exactly Haystack's answer;
|
|
237
|
+
the rest (ranges on dates, `None`) go to Haystack's reference implementation. The store passes
|
|
238
|
+
Haystack's document-store test suite.
|
|
239
|
+
|
|
240
|
+
## Retrieval evaluation
|
|
241
|
+
|
|
242
|
+
```python
|
|
243
|
+
from epzero import ir
|
|
244
|
+
|
|
245
|
+
corpus, queries, qrels = ir.load_beir("scifact") # a BEIR dataset folder
|
|
246
|
+
collection = ir.Collection.build(list(corpus), doc_vectors, texts=list(corpus.values()), metric="cosine")
|
|
247
|
+
run = collection.retrieve(list(queries), vectors=query_vectors, texts=list(queries.values()),
|
|
248
|
+
k=100, mode="hybrid") # or "dense", "keyword"
|
|
249
|
+
ir.write_run(run, "run.txt", tag="my-system") # TREC format, for CLEF or TREC
|
|
250
|
+
print(ir.evaluate(run, qrels)) # nDCG@10, R@100, MAP, MRR@10
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
`evaluate` matches trec_eval (tested against it, ties included) and also takes `per_query=True` and
|
|
254
|
+
measures like `P@5` or `nDCG@20`. Documents can be added, replaced and removed by id, and a collection
|
|
255
|
+
saves to a folder.
|
|
256
|
+
|
|
148
257
|
## Platforms
|
|
149
258
|
|
|
150
|
-
Wheels for Linux (x86-64 and ARM64, glibc 2.28+)
|
|
151
|
-
to 3.13. Elsewhere, `pip install epzero` builds from source (CMake 3.20+, a C++20 compiler).
|
|
259
|
+
Wheels for Linux (x86-64 and ARM64, glibc 2.28+), macOS (Apple silicon and Intel) and Windows (x64), Python 3.10 to 3.13. Elsewhere, `pip install epzero` builds from source (CMake 3.20+, a C++20 compiler).
|
|
152
260
|
|
|
153
261
|
Live demo, benchmarks and design notes: https://epzero.dev/ · MIT license.
|
|
@@ -43,6 +43,7 @@ struct Options {
|
|
|
43
43
|
std::size_t nav_dim = 0;
|
|
44
44
|
bool fill_links = false;
|
|
45
45
|
bool fast_build = false;
|
|
46
|
+
bool half = false;
|
|
46
47
|
bool fill_after = false;
|
|
47
48
|
std::size_t refine = 0;
|
|
48
49
|
bool refine_exact = false;
|
|
@@ -98,6 +99,7 @@ Options parse(int argc, char** argv) {
|
|
|
98
99
|
else if (arg == "--nav-dim") o.nav_dim = std::stoul(value());
|
|
99
100
|
else if (arg == "--fill-links") o.fill_links = true;
|
|
100
101
|
else if (arg == "--fast-build") o.fast_build = true;
|
|
102
|
+
else if (arg == "--half") o.half = true;
|
|
101
103
|
else if (arg == "--fill-after") o.fill_after = true;
|
|
102
104
|
else if (arg == "--refine") o.refine = std::stoul(value());
|
|
103
105
|
else if (arg == "--refine-exact") o.refine_exact = true;
|
|
@@ -191,7 +193,7 @@ int main(int argc, char** argv) try {
|
|
|
191
193
|
HnswParams params{.dim = dim, .metric = opt.metric, .max_elements = base.n, .M = opt.M,
|
|
192
194
|
.ef_construction = opt.ef_construction, .seed = opt.seed, .quantization = opt.quantization,
|
|
193
195
|
.keep_vectors = opt.keep_vectors, .nav_dim = opt.nav_dim, .fill_links = opt.fill_links,
|
|
194
|
-
.fast_build = opt.fast_build};
|
|
196
|
+
.fast_build = opt.fast_build, .half_vectors = opt.half};
|
|
195
197
|
loaded = std::make_unique<HnswIndex>(params);
|
|
196
198
|
t0 = Clock::now();
|
|
197
199
|
loaded->train(base.data.data(), std::min<std::size_t>(base.n, 100'000)); // no-op unquantized
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"float-l2": {
|
|
3
|
+
"4": {
|
|
4
|
+
"recall": 0.9068,
|
|
5
|
+
"distances": 209.99
|
|
6
|
+
},
|
|
7
|
+
"8": {
|
|
8
|
+
"recall": 0.9068,
|
|
9
|
+
"distances": 209.99
|
|
10
|
+
},
|
|
11
|
+
"16": {
|
|
12
|
+
"recall": 0.9664,
|
|
13
|
+
"distances": 247.212
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"float-cosine": {
|
|
17
|
+
"4": {
|
|
18
|
+
"recall": 0.9042,
|
|
19
|
+
"distances": 222.262
|
|
20
|
+
},
|
|
21
|
+
"8": {
|
|
22
|
+
"recall": 0.9042,
|
|
23
|
+
"distances": 222.262
|
|
24
|
+
},
|
|
25
|
+
"16": {
|
|
26
|
+
"recall": 0.967,
|
|
27
|
+
"distances": 263.986
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"sq8-second-pass": {
|
|
31
|
+
"4": {
|
|
32
|
+
"recall": 0.9132,
|
|
33
|
+
"distances": 234.102
|
|
34
|
+
},
|
|
35
|
+
"8": {
|
|
36
|
+
"recall": 0.9132,
|
|
37
|
+
"distances": 234.102
|
|
38
|
+
},
|
|
39
|
+
"16": {
|
|
40
|
+
"recall": 0.981,
|
|
41
|
+
"distances": 275.388
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"sq8-directions": {
|
|
45
|
+
"32": {
|
|
46
|
+
"recall": 0.4988,
|
|
47
|
+
"distances": 323.592
|
|
48
|
+
},
|
|
49
|
+
"64": {
|
|
50
|
+
"recall": 0.7316,
|
|
51
|
+
"distances": 390.994
|
|
52
|
+
},
|
|
53
|
+
"128": {
|
|
54
|
+
"recall": 0.9518,
|
|
55
|
+
"distances": 508.41
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Fuzzes MetadataIndex::load: arbitrary bytes as a metadata file must either load into an index that is
|
|
2
|
+
// safe to query, change and save, or throw. Never crash, read out of bounds or hit undefined behavior.
|
|
3
|
+
#include <exception>
|
|
4
|
+
#include <string>
|
|
5
|
+
|
|
6
|
+
#include "common.h"
|
|
7
|
+
#include "epzero/metadata.h"
|
|
8
|
+
|
|
9
|
+
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, std::size_t size) {
|
|
10
|
+
static const auto path = epzero::fuzz::scratch("metadata") / "input.meta";
|
|
11
|
+
epzero::fuzz::write_bytes(path, data, size);
|
|
12
|
+
try {
|
|
13
|
+
epzero::MetadataIndex index = epzero::MetadataIndex::load(path.string());
|
|
14
|
+
(void)index.select({{.field = "source", .any_of = {std::string("faq")}}, {.field = "year", .min = 2000.0}});
|
|
15
|
+
(void)index.select({{.field = "year", .max = 1e9, .negate = true}});
|
|
16
|
+
index.set(1, {{"source", std::string("new")}});
|
|
17
|
+
index.remove(1);
|
|
18
|
+
index.save(path.string());
|
|
19
|
+
} catch (const std::exception&) {
|
|
20
|
+
// Rejected cleanly: the expected outcome for corrupt input.
|
|
21
|
+
}
|
|
22
|
+
return 0;
|
|
23
|
+
}
|