mcy98 commited on
Commit
95ddd04
·
verified ·
1 Parent(s): 63d14da

Delete folder annotations/annotation_141 with huggingface_hub

Browse files
annotations/annotation_141/2210.15748v2.pdf DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:3e3996c9b3234a4e05fb7cd3f34a034eada091c764d506071b4d47abed27ab2a
3
- size 1255848
 
 
 
 
annotations/annotation_141/DESSERT/__init__.py DELETED
File without changes
annotations/annotation_141/DESSERT/generation.py DELETED
File without changes
annotations/annotation_141/canonical.py DELETED
@@ -1,263 +0,0 @@
1
- # =============================================================================
2
- # DESSERT (Paper-aware) Python Reference Implementation — Fully Commented
3
- # =============================================================================
4
- # This file adds detailed, paper-grounded commentary to explain how each part
5
- # of the code corresponds to the DESSERT algorithm in the NeurIPS 2023 paper
6
- # “DESSERT: An Efficient Algorithm for Vector Set Search with Vector Set Queries”
7
- # (arXiv:2210.15748v2). We specifically:
8
- #
9
- # (1) Explain functionality and how it maps to the paper’s Algorithm 1 (Indexing)
10
- # and Algorithm 2 (Querying).:contentReference[oaicite:0]{index=0}
11
- # (2) Call out discrepancies between this reference code and the paper’s
12
- # description/implementation details. In short, we implement the core logic
13
- # faithfully but simplify several engineering optimizations (e.g., TinyTable,
14
- # k-means prefiltering, collision-to-sim lookup) described in Section 5.:contentReference[oaicite:1]{index=1}
15
- # (3) Make explicit where the code necessarily fills in unspecified details from the
16
- # paper (e.g., SRP sampling rate, exact data structures).
17
- #
18
- # Quick mapping to the paper:
19
- # - Paper §3 introduces DESSERT: Algorithm 1 (Building Index) and Algorithm 2
20
- # (Querying). This file’s `build_index()` ≈ Algorithm 1; `search()` ≈ Algorithm 2.:contentReference[oaicite:2]{index=2}
21
- # - Scoring model F(Q,S) = A({ σ({ sim(q, x) : x ∈ S }) | q ∈ Q }): we expose
22
- # σ and A as user-configurable callables (e.g., σ = max, A = sum for ColBERT).:contentReference[oaicite:3]{index=3}
23
- # - We use SRP-style LSH to generate L hash values per vector by concatenating
24
- # `srps_per_table` projections per table (the “concatenation trick”).:contentReference[oaicite:4]{index=4}
25
- #
26
- # IMPORTANT DISCREPANCIES vs. the paper (high-level):
27
- # - Paper uses TinyTable (compact per-document, per-table inverted lists over hash
28
- # buckets) for memory- and cache-efficiency; here we use Python dicts of lists
29
- # for clarity (Section 5: “Space Optimized Sketches”).:contentReference[oaicite:5]{index=5}
30
- # - Paper optionally applies a k-means–based inverted-index prefilter (filter_k /
31
- # filter_probe) before full DESSERT scoring; we omit this optimization (Section 5:
32
- # “Filtering”).:contentReference[oaicite:6]{index=6}
33
- # - Paper estimates sim(q,x) from LSH collision counts (with concatenation trick,
34
- # Eq. (1): sim = exp( ln p / C )). Here we *prune with LSH* but then compute
35
- # *exact cosine similarity* on candidates. This is faithful to the set-to-set
36
- # scoring form (σ∘sim then A) but differs from the paper’s “counts→sim lookup”
37
- # estimator discussed in §5 (“The Concatenation Trick”).:contentReference[oaicite:7]{index=7}
38
- # - Paper discusses theory (choice of L, δ, runtime bounds) in §4; we do not
39
- # compute L from theory—hyperparameters are user-set.:contentReference[oaicite:8]{index=8}
40
- #
41
- # Impact of discrepancies:
42
- # - Correctness of the A∘σ scoring form is preserved (σ and A configurable).
43
- # - Efficiency may be lower than the paper’s C++ implementation on very large
44
- # corpora because we compute exact cosine similarities on LSH-pruned candidates,
45
- # skip TinyTable, and skip k-means prefiltering.
46
- #
47
- # ColBERT connection: The paper notes ColBERT is an instantiation where
48
- # sim = cosine, σ = max, A = sum (“sum of max similarities”). Exposing σ and A
49
- # makes this code match the ColBERT-style late interaction scoring out of the box.:contentReference[oaicite:9]{index=9}
50
- # =============================================================================
51
-
52
- import numpy as np
53
- import heapq
54
- from typing import List, Tuple, Callable
55
-
56
-
57
- class DessertIndex:
58
- def __init__(self, input_dim: int, srps_per_table: int, num_tables: int,
59
- sigma: Callable[[List[float]], float] = max,
60
- A: Callable[[List[float]], float] = np.mean,
61
- seed: int = 42):
62
- """
63
- Constructor = Paper’s *index initialization* phase (before Algorithm 1).
64
- - input_dim (d): embedding dimensionality R^d.
65
- - srps_per_table (C in the paper’s Section 5): number of SRP projections
66
- concatenated per table; larger C => fewer collisions (tighter buckets).:contentReference[oaicite:10]{index=10}
67
- - num_tables (L): number of independent LSH tables (repetitions).:contentReference[oaicite:11]{index=11}
68
- - sigma (σ): inner aggregation on {sim(q, x) : x ∈ S}. E.g., max for ColBERT.:contentReference[oaicite:12]{index=12}
69
- - A: outer aggregation over q ∈ Q. E.g., sum (ColBERT) or mean.:contentReference[oaicite:13]{index=13}
70
- - seed: RNG seed for reproducibility.
71
-
72
- Discrepancy / filled-in detail:
73
- - We choose a *sampling rate* of 30% of dimensions for each SRP vector
74
- (self.sample_size = ceil(0.3 * d)). The paper does not mandate this exact
75
- rate; it only requires an LSH family with p(h(x)=h(y)) aligned with similarity
76
- (e.g., signed random projections for cosine). We set a reasonable default here.:contentReference[oaicite:14]{index=14}
77
- """
78
- self.num_tables = num_tables
79
- self.srps_per_table = srps_per_table
80
- self.total_num_srps = srps_per_table * num_tables
81
- self.dim = input_dim
82
- self.sample_size = int(np.ceil(self.dim * 0.3)) # <- engineer-chosen; paper-agnostic
83
-
84
- # Generate SRP “directions” and sampled coordinates for all L*C projections.
85
- # Paper basis: LSH functions f_t with collision probability ~ sim(q, x),
86
- # then concatenate C hashes per table to tighten buckets (Section 5, Eq. (1)).:contentReference[oaicite:15]{index=15}
87
- rng = np.random.default_rng(seed)
88
- self.indices = rng.choice(self.dim, size=(self.total_num_srps, self.sample_size))
89
- self.random_bits = rng.choice([-1, 1], size=(self.total_num_srps, self.sample_size))
90
-
91
- # Per-table hash maps: table[t][hash] -> list of (doc_id, x)
92
- # Paper stores per-document TinyTables mapping (t, h) -> positions j in S_i
93
- # (Algorithm 1’s D[i]_{t,h}); we store actual vectors for clarity.:contentReference[oaicite:16]{index=16}
94
- self.tables = [dict() for _ in range(num_tables)]
95
- self.docs: List[List[np.ndarray]] = [] # List of documents; each document is a list of vectors
96
-
97
- # Aggregation operators as described in §1.1 / §3 (A ∘ σ).:contentReference[oaicite:17]{index=17}
98
- self.sigma = sigma
99
- self.A = A
100
-
101
- def _compute_hash(self, vec: np.ndarray) -> List[int]:
102
- """
103
- Paper analog: compute LSH values h_{t}(vec) for each table t, where each
104
- table’s hash is a concatenation of srps_per_table SRPs (Section 5 “Concatenation Trick”).:contentReference[oaicite:18]{index=18}
105
-
106
- Implementation note (discrepancy):
107
- - We implement SRP by sampling coordinates and projecting onto ±1 “directions”.
108
- Paper only requires an LSH family matching cosine; exact SRP construction and
109
- sampling scheme are not prescribed → we fill in a standard, simple SRP variant.
110
- - We return *integer* hashes by bit-packing C sign bits per table. Paper describes
111
- the concatenation conceptually (C bits per table) but does not mandate the exact
112
- representation; this encoding is a straightforward realization.:contentReference[oaicite:19]{index=19}
113
- """
114
- hashes = []
115
- for t in range(self.num_tables):
116
- bits = []
117
- for j in range(self.srps_per_table):
118
- idx = t * self.srps_per_table + j
119
- # Signed projection: sign( <vec[indices], random_bits> )
120
- proj = np.dot(vec[self.indices[idx]], self.random_bits[idx])
121
- bits.append(1 if proj > 0 else 0)
122
- # Concatenate C bits into a base-2 integer (bucket id for table t).
123
- hash_val = int("".join(map(str, bits)), 2)
124
- hashes.append(hash_val)
125
- return hashes
126
-
127
- def build_index(self, docs: List[np.ndarray]):
128
- """
129
- Algorithm 1 — Building a DESSERT Index (Paper §3):​:contentReference[oaicite:20]{index=20}
130
- Input: vector-set collection D = {S_1, …, S_N}
131
- For each document S_i and each vector x ∈ S_i:
132
- - compute LSH hashes h_t(x) for all tables t ∈ [1..L]
133
- - insert x (or its position j) into bucket (t, h_t(x)) of document i
134
- Output: index structure D (sketches D[i]).
135
-
136
- Correspondence:
137
- - Our per-table dict plays the role of D[i]_{t,h} in Algorithm 1. For simplicity,
138
- we store (doc_id, x) pairs rather than per-document TinyTables. Paper uses a compact
139
- layout (TinyTable) per document for memory efficiency (Section 5).:contentReference[oaicite:21]{index=21}
140
-
141
- Discrepancy:
142
- - Paper’s D[i]_{t,h} stores positions j (vector ids) to save memory and enable tight
143
- contiguous layouts; we store full vectors (x), which is simpler but heavier.:contentReference[oaicite:22]{index=22}
144
- """
145
- self.docs = [list(doc) for doc in docs] # Cast each doc array to list of 1D vectors
146
- for doc_id, vectors in enumerate(self.docs):
147
- for x in vectors:
148
- hashes = self._compute_hash(x)
149
- for t, h in enumerate(hashes):
150
- self.tables[t].setdefault(h, []).append((doc_id, x))
151
-
152
- def search(self, Q: np.ndarray, top_k: int = 5) -> List[Tuple[int, float]]:
153
- """
154
- Algorithm 2 — Querying a DESSERT Index (Paper §3):​:contentReference[oaicite:23]{index=23}
155
- Input: index D, query set Q = {q_1,…,q_mq}
156
- For each q in Q, compute its L hashes; for each document S_i,
157
- tally collisions per element j (or gather candidates), estimate similarities,
158
- apply inner aggregation σ to get agg_q for S_i, then apply outer aggregation A
159
- over q ∈ Q to get final score_i; return top documents by score.
160
-
161
- Our realization (with discrepancies called out):
162
- - We *use LSH as a pruning stage* to gather candidates in S_i that share a bucket
163
- with q (for any table t). This approximates lines 8–11 of Algorithm 2 (counting
164
- collisions per element) but instead of mapping “count/L → sim via Eq. (1)”
165
- (paper §5), we compute *exact cosine similarity* between q and each candidate x.:contentReference[oaicite:24]{index=24}
166
- - We then apply σ on the set of similarities for the current q and S_i, and A across q.
167
- - This preserves the structure F(Q,S)=A({σ(sim(q,·))}) and the ColBERT-style setting
168
- (σ=max, A=sum) the paper highlights (Related Work: “ColBERT and PLAID”).:contentReference[oaicite:25]{index=25}
169
-
170
- Practical note:
171
- - Because we filter by doc_id == i, we only compute similarities for the current S_i,
172
- faithfully building s(q, S_i) before σ and A (Table 1 notation).:contentReference[oaicite:26]{index=26}
173
- """
174
- scores = []
175
- for i, S in enumerate(self.docs):
176
- agg_q_list = [] # holds σ(...) per q for this document i
177
- for q in Q:
178
- # ---- Candidate gathering by LSH bucket matches (Algorithm 2: “collisions”) ----
179
- q_hashes = self._compute_hash(q)
180
- candidates = []
181
- for t, h in enumerate(q_hashes):
182
- if h in self.tables[t]:
183
- for (doc_id, x) in self.tables[t][h]:
184
- if doc_id == i: # restrict to current document S_i
185
- candidates.append(x)
186
- # Note (minor nuance): we do not deduplicate candidates. With σ=max (default),
187
- # duplicates are harmless; for other σ (e.g., mean), deduplication could be added.
188
-
189
- # ---- Similarity computation: exact cosine on pruned set (discrepancy) ----
190
- # Paper proposes computing collision counts and converting to similarity using
191
- # Eq. (1) with concatenation (precomputed lookup over count/L). We instead
192
- # compute cosine directly here (simpler, still aligned with F’s form).:contentReference[oaicite:27]{index=27}
193
- sims = []
194
- for x in candidates:
195
- sim = np.dot(q, x) / (np.linalg.norm(q) * np.linalg.norm(x) + 1e-8)
196
- sims.append(sim)
197
-
198
- # ---- Inner aggregation σ over s(q, S_i) ----
199
- # Matches σ({sim(q, x): x ∈ S_i}). For ColBERT: σ = max.:contentReference[oaicite:28]{index=28}
200
- if sims:
201
- agg_q_list.append(self.sigma(sims))
202
- else:
203
- agg_q_list.append(0.0) # no collisions → σ over empty set → 0
204
-
205
- # ---- Outer aggregation A over q ∈ Q ----
206
- # Matches A({agg_q | q ∈ Q}). For ColBERT: A = sum.:contentReference[oaicite:29]{index=29}
207
- score_i = self.A(agg_q_list)
208
- scores.append((i, score_i))
209
-
210
- # Return top-k documents by score (ties broken by order). Paper’s Algorithm 2 returns
211
- # argmax over i; here we generalize to top-k ranking for retrieval use cases.:contentReference[oaicite:30]{index=30}
212
- return heapq.nlargest(top_k, scores, key=lambda x: x[1])
213
-
214
-
215
-
216
- # =============================================================================
217
- # Additional notes on discrepancies and design choices:
218
- # -----------------------------------------------------------------------------
219
- # (A) TinyTable vs. Python dict
220
- # Paper: TinyTable stores compact per-doc tables; each table is split into offset
221
- # lists and vector-id lists to minimize overhead (Section 5 “Space Optimized
222
- # Sketches”). Our Python dict(list) structure is clear but not memory optimal.:contentReference[oaicite:34]{index=34}
223
- #
224
- # (B) Filtering (k-means inverted index)
225
- # Paper: optional k-means prefilter to reduce candidate docs (filter_probe, filter_k)
226
- # before DESSERT scoring (Section 5 “Filtering”). We omit this step here for
227
- # simplicity; add it to improve scalability on large N.:contentReference[oaicite:35]{index=35}
228
- #
229
- # (C) Collision-to-similarity mapping (Eq. (1))
230
- # Paper: With C-bit concatenation per table, estimate p̂ = count/L, then map to
231
- # similarity via sim ≈ exp( ln p̂ / C ). Precompute a (count→sim) lookup table for
232
- # speed (since count/L ∈ {0, 1/L, …, 1}). Here we directly compute cosine for
233
- # pruned candidates instead of using counts→sim; this is the main algorithmic
234
- # *estimation* discrepancy. The A∘σ set-scoring structure remains consistent.:contentReference[oaicite:36]{index=36}
235
- #
236
- # (D) Hyperparameters from theory
237
- # Paper §4 provides probability-of-success and runtime bounds with a recommended
238
- # order for L in terms of N, m_q, m, δ (e.g., L = O(log(N m_q m / δ))). We do not
239
- # auto-tune L or C from these bounds; the user sets them. For correctness of the
240
- # aggregation semantics, this is fine; for production efficiency, tune L/C empirically.:contentReference[oaicite:37]{index=37}
241
- #
242
- # (E) Data stored in buckets
243
- # Paper stores vector ids j for each (t,h) within each document i (D[i]_{t,h} = {j}).
244
- # We store full (doc_id, x) to keep the code self-contained; in practice, store ids
245
- # and keep a separate matrix of vectors to reduce memory and cache misses.:contentReference[oaicite:38]{index=38}
246
- #
247
- # (F) Deduplication of candidates
248
- # Paper counts collisions per element j (Algorithm 2 lines 8–11). Our candidate list
249
- # may contain duplicates when a vector collides across multiple tables. With σ = max,
250
- # duplicates are harmless; with mean-based σ, consider deduplicating to avoid bias.:contentReference[oaicite:39]{index=39}
251
- #
252
- # (G) Similarity function
253
- # Paper assumes LSH families where p(h(x)=h(y)) tracks similarity (cosine, ℓ2, Jaccard).
254
- # We hard-code cosine in the exact-sim stage; changing sim requires adapting both SRP
255
- # and the similarity computation (or using count→sim lookup as in the paper).:contentReference[oaicite:40]{index=40}
256
- #
257
- # (H) ColBERT setting
258
- # The paper explicitly calls out ColBERT’s F with sim = cosine, σ = max, A = sum.
259
- # Our default example uses exactly this, so experimental behavior matches the paper’s
260
- # cited ColBERT-style aggregation semantics.:contentReference[oaicite:41]{index=41}
261
- # =============================================================================
262
-
263
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
annotations/annotation_141/function_info.json DELETED
@@ -1,201 +0,0 @@
1
- [
2
- {
3
- "function_name": "DessertIndex.init",
4
- "file_path": "canonical.py",
5
- "function_calls": [
6
- {
7
- "function_call_name": "np.ceil",
8
- "functionality": "Return the ceiling of the input value.",
9
- "input": "self.dim * 0.3",
10
- "output": "float",
11
- "location_or_namespace": "numpy"
12
- },
13
- {
14
- "function_call_name": "int",
15
- "functionality": "Cast value to integer.",
16
- "input": "np.ceil(...)",
17
- "output": "int",
18
- "location_or_namespace": "builtins"
19
- },
20
- {
21
- "function_call_name": "np.random.default_rng",
22
- "functionality": "Create a random number generator instance.",
23
- "input": "seed (int)",
24
- "output": "numpy.random.Generator",
25
- "location_or_namespace": "numpy.random"
26
- },
27
- {
28
- "function_call_name": "Generator.choice",
29
- "functionality": "Randomly sample indices/elements with a given size.",
30
- "input": "a (int or array-like), size (tuple[int, int])",
31
- "output": "ndarray",
32
- "location_or_namespace": "numpy.random.Generator"
33
- },
34
- {
35
- "function_call_name": "dict",
36
- "functionality": "Create an empty dictionary.",
37
- "input": "",
38
- "output": "dict",
39
- "location_or_namespace": "builtins"
40
- },
41
- {
42
- "function_call_name": "range",
43
- "functionality": "Create an integer range iterator.",
44
- "input": "num_tables (int)",
45
- "output": "range",
46
- "location_or_namespace": "builtins"
47
- }
48
- ]
49
- },
50
- {
51
- "function_name": "DessertIndex._compute_hash",
52
- "file_path": "canonical.py",
53
- "function_calls": [
54
- {
55
- "function_call_name": "range",
56
- "functionality": "Create an integer range iterator.",
57
- "input": "self.num_tables or self.srps_per_table",
58
- "output": "range",
59
- "location_or_namespace": "builtins"
60
- },
61
- {
62
- "function_call_name": "np.dot",
63
- "functionality": "Dot product between two arrays/vectors.",
64
- "input": "vec[self.indices[idx]], self.random_bits[idx]",
65
- "output": "float",
66
- "location_or_namespace": "numpy"
67
- },
68
- {
69
- "function_call_name": "list.append",
70
- "functionality": "Append an element to a list.",
71
- "input": "element",
72
- "output": "None",
73
- "location_or_namespace": "builtins (list method)"
74
- },
75
- {
76
- "function_call_name": "map",
77
- "functionality": "Apply a function to each item of an iterable.",
78
- "input": "str, bits",
79
- "output": "iterator",
80
- "location_or_namespace": "builtins"
81
- },
82
- {
83
- "function_call_name": "str.join",
84
- "functionality": "Concatenate an iterable of strings with a separator.",
85
- "input": "map(str, bits)",
86
- "output": "str",
87
- "location_or_namespace": "builtins (str method)"
88
- },
89
- {
90
- "function_call_name": "int",
91
- "functionality": "Convert a string to integer with base.",
92
- "input": "binary_string, base=2",
93
- "output": "int",
94
- "location_or_namespace": "builtins"
95
- }
96
- ]
97
- },
98
- {
99
- "function_name": "DessertIndex.build_index",
100
- "file_path": "canonical.py",
101
- "function_calls": [
102
- {
103
- "function_call_name": "list",
104
- "functionality": "Convert iterable to list.",
105
- "input": "doc",
106
- "output": "list",
107
- "location_or_namespace": "builtins"
108
- },
109
- {
110
- "function_call_name": "enumerate",
111
- "functionality": "Enumerate iterable with indices.",
112
- "input": "self.docs or hashes",
113
- "output": "iterator of (index, value)",
114
- "location_or_namespace": "builtins"
115
- },
116
- {
117
- "function_call_name": "DessertIndex._compute_hash",
118
- "functionality": "Compute L concatenated SRP hash values for a vector.",
119
- "input": "x (list[float])",
120
- "output": "list[int]",
121
- "location_or_namespace": "canonical.py"
122
- },
123
- {
124
- "function_call_name": "dict.setdefault",
125
- "functionality": "Return value for key; set default if key missing.",
126
- "input": "h (key), [] (default)",
127
- "output": "list",
128
- "location_or_namespace": "builtins (dict method)"
129
- },
130
- {
131
- "function_call_name": "list.append",
132
- "functionality": "Append an element to a list.",
133
- "input": "(doc_id, x)",
134
- "output": "None",
135
- "location_or_namespace": "builtins (list method)"
136
- }
137
- ]
138
- },
139
- {
140
- "function_name": "DessertIndex.search",
141
- "file_path": "canonical.py",
142
- "function_calls": [
143
- {
144
- "function_call_name": "enumerate",
145
- "functionality": "Enumerate iterable with indices.",
146
- "input": "self.docs or q_hashes",
147
- "output": "iterator of (index, value)",
148
- "location_or_namespace": "builtins"
149
- },
150
- {
151
- "function_call_name": "DessertIndex._compute_hash",
152
- "functionality": "Compute L concatenated SRP hash values for a vector.",
153
- "input": "q (list[float])",
154
- "output": "list[int]",
155
- "location_or_namespace": "canonical.py"
156
- },
157
- {
158
- "function_call_name": "list.append",
159
- "functionality": "Append an element to a list.",
160
- "input": "x or sim or agg value or (i, score_i)",
161
- "output": "None",
162
- "location_or_namespace": "builtins (list method)"
163
- },
164
- {
165
- "function_call_name": "np.dot",
166
- "functionality": "Dot product between two arrays/vectors.",
167
- "input": "q, x",
168
- "output": "float",
169
- "location_or_namespace": "numpy"
170
- },
171
- {
172
- "function_call_name": "np.linalg.norm",
173
- "functionality": "Vector 2-norm.",
174
- "input": "q or x",
175
- "output": "float",
176
- "location_or_namespace": "numpy.linalg"
177
- },
178
- {
179
- "function_call_name": "self.sigma",
180
- "functionality": "Inner aggregation σ over similarities for a single q (e.g., max or mean).",
181
- "input": "sims (list[float])",
182
- "output": "float",
183
- "location_or_namespace": "callback (user-supplied; defaults: builtins.max)"
184
- },
185
- {
186
- "function_call_name": "self.A",
187
- "functionality": "Outer aggregation A across query vectors (e.g., sum or mean).",
188
- "input": "agg_q_list (list[float])",
189
- "output": "float",
190
- "location_or_namespace": "callback (user-supplied; defaults: numpy.mean or builtins.sum)"
191
- },
192
- {
193
- "function_call_name": "heapq.nlargest",
194
- "functionality": "Return the n largest elements from iterable according to key.",
195
- "input": "top_k, scores, key=lambda x: x[1]",
196
- "output": "list of top-k items",
197
- "location_or_namespace": "heapq"
198
- }
199
- ]
200
- }
201
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
annotations/annotation_141/instruction.txt DELETED
@@ -1,58 +0,0 @@
1
- # Code Generation Instruction: DESSERT (Vector-Set Indexing & Querying)
2
-
3
- ## Goal
4
-
5
- Implement the **main interface functions** of the DESSERT algorithm for vector-set search, as defined in **Section 3 (Algorithms 1–2)** of *“DESSERT: An Efficient Algorithm for Vector Set Search with Vector Set Queries”*. The first function builds a DESSERT index over a collection of vector sets (Algorithm 1). The second function queries that index with a vector-set query and returns the top-k targets scored by the set-to-set relevance function **F(Q, S) = A({ σ({ sim(q,x) : x∈S }) | q∈Q })** (Algorithm 2).&#x20;
6
-
7
- ---
8
-
9
- ### **Instruction 1: Build the DESSERT Index**
10
-
11
- * **Functionality Description:** Construct a DESSERT index over a collection of target vector sets as described in **Algorithm 1 (Building a DESSERT Index)**. The index must store, for each target set, sufficient hash-based information to enable efficient estimation of pairwise similarities required by **A ∘ σ** during querying.
12
- * **Expected Function Name:** `build_dessert_index`
13
- * **Input:**
14
-
15
- * `docs` (list\[list\[list\[float]]]): A corpus where each document/set is a list of embedding vectors; each vector is a list of floats.
16
- * `num_tables` (int): The number of independent hash tables (**L**).
17
- * `hashes_per_table` (int): The number of concatenated hashes per table (**C**).
18
- * `seed` (int, optional): Random seed for reproducibility.
19
- * **Output:**
20
-
21
- * `index_data` (dict): An opaque index structure containing all information needed to query (including any parameters such as **L** and **C**). The exact layout is implementation-defined.
22
-
23
- ---
24
-
25
- ### **Instruction 2: Query the DESSERT Index**
26
-
27
- * **Functionality Description:** Implement the **Algorithm 2 (Querying a DESSERT Index)** interface. Given a DESSERT index produced by Algorithm 1 and a query set **Q**, compute **A({ σ({ sim(q,x) }) })** over all targets and return the **top-k** targets by score. The query logic should (i) generate the query’s hash signatures compatible with the index, (ii) identify candidate elements per target via those hashes, (iii) produce per-query-vector scores via **σ**, and (iv) aggregate across query vectors via **A** to form the final document score.
28
- * **Expected Function Name:** `dessert_query`
29
- * **Input:**
30
-
31
- * `index_data` (dict): A DESSERT index previously returned by `build_dessert_index`.
32
- * `query_set` (list\[list\[float]]): The query set **Q**, a list of embedding vectors.
33
- * `top_k` (int): Number of top results to return.
34
- * `inner_agg` (str): Name of the inner aggregation **σ** to apply over `{ sim(q,x) : x∈S }` for each `q` (e.g., `"max"` or `"mean"`).
35
- * `outer_agg` (str): Name of the outer aggregation **A** to apply over `{ agg_q : q∈Q }` (e.g., `"sum"` or `"mean"`).
36
- * `weights` (list\[float], optional): Optional weights for a weighted outer aggregation **A** over the query vectors.
37
- * `similarity` (str, optional): Similarity function identifier for `sim(q,x)` (e.g., `"cosine"`).
38
- * **Output:**
39
-
40
- * `ranked_results` (list\[list]): A list of length ≤ `top_k`; each item is `[doc_id (int), score (float)]` in descending score order.
41
-
42
- ---
43
-
44
- ## Key Constraints and Considerations (apply to both functions)
45
-
46
- * **Abstraction over implementation:** Define and use only the interfaces above. Do **not** mention specific libraries, tensor types, custom classes, file formats, or storage engines. Internal data structures inside `index_data` are implementation-defined.
47
- * **Paper alignment:**
48
-
49
- * Index construction and query behavior must follow **Algorithm 1** and **Algorithm 2** in Section 3, respectively.
50
- * The scoring form **F(Q, S) = A ∘ σ** must be respected; `inner_agg` and `outer_agg` control these choices (e.g., ColBERT-style `σ = max`, `A = sum`).&#x20;
51
- * **Hashing assumptions:** Use an LSH family appropriate for the chosen `similarity` so that the probability of hash collision increases with similarity. Concatenating multiple hashes per table (parameter **C** = `hashes_per_table`) is expected to control bucket selectivity, consistent with the paper’s description.&#x20;
52
- * **Input flexibility:** Support variable set sizes per document and per query. No assumption about fixed dimensions beyond vectors being lists of floats.
53
- * **Determinism option:** If `seed` is provided during index building, calls using the same `index_data` and `query_set` should be reproducible.
54
- * **Output contract:** `dessert_query` must **not** mutate `index_data`; it returns a fresh ranking limited to `top_k`.
55
-
56
- ---
57
-
58
- **Interface function names:** `build_dessert_index`, `dessert_query`
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
annotations/annotation_141/latex.txt DELETED
@@ -1,117 +0,0 @@
1
- \section{Algorithm}
2
- At a high level, a DESSERT index $\mathcal{D}$ compresses the collection of target sets into a form that makes set to set similarity operations efficient to calculate. This is done by replacing each set $S_i$ with a sketch $\mathcal{D}[i]$ that contains the LSH values of each $x_j \in S_i$. At query time, we compare the corresponding LSH values of the query set $Q$ with the hashes in each $\mathcal{D}[i]$ to approximate the pairwise similarity matrix between $Q$ and $S$ (Figure~\ref{fig:trecall}). This matrix is used as the input for the aggregation functions $A$ and $\sigma$ to rank the target sets and return an estimate of $S^*$.
3
-
4
- We assume the existence of a locality-sensitive hashing (LSH) family $\mathcal{H} \subset (\mathbb{R}^d \rightarrow \mathbb{Z}$) such that for all LSH functions $h \in \mathcal{H}$, $p(h(x) = h(y)) = \simwritten(x, y)$. LSH functions with this property exist for cosine similarity (signed random projections)~\cite{10.1145/509907.509965}, Euclidean similarity ($p$-stable projections)~\cite{10.1145/997817.997857}, and Jaccard similarity (minhash or simhash)~\cite{10.5555/829502.830043}. LSH is a well-developed theoretical framework with a wide variety of results and extensions~\cite{andoni2015optimal,andoni2014beyond,ji2012super,shrivastava2015improved}. See Appendix~\ref{appendix-lsh} for a deeper overview.
5
-
6
- % The DESSERT index $\mathcal{D}$ is an array of sketches, with one sketch $\mathcal{D}[i]$ corresponding to each set $S_i$. Each sketch supports a single operation, querying, that takes an input set $Q$ and returns an estimate of the ranking score $F(Q, S_i)$. The DESSERT index as a whole supports the vector set search problem with vector set queries: after indexing, querying a DESSERT index returns an estimate of $S^*$.
7
-
8
- Algorithm~\ref{alg:indexing} describes how to construct a DESSERT index $\mathcal{D}$. We first take $L$ LSH functions $f_t$ for $t \in [1, L]$, $f_t \in \mathcal{H}$. We next loop over each $S_i$ to construct $\mathcal{D}[i]$. For a given $S_i$, we arbitrarily assign an identifier $j$ to each vector $x \in S_i$, $j \in [1, |S_i|]$. We next partition the set $[1, m_i]$ using each hash function $h_t$, such that for a partition $p_t$, indices $j_1$ and $j_2$ are in the same set in the partition iff $h(S_{j_1}) = h(S_{j_2})$. We represent the results of these partitions in a universal hash table indexed by hash function id and hash function value, such that
9
- $\mathcal{D}[i]_{t, h} = \{j \,|\, x_j \in S_i \wedge f_t(x_j) = h\}$.
10
-
11
- Algorithm \ref{alg:query} describes how to query a DESSERT index $\mathcal{D}$. At a high level, we query each sketch $\mathcal{D}_i$ to get an estimate of $F(Q, S_i)$, $score_i$, and then take the argmax over the \textit{estimates} to get an estimate of $\argmax_{i \in \{1, \ldots N\}} F(Q, S_i)$. To get these estimates, we first compute the hashes $h_{t, q}$ for each query $q$ and LSH function $f_t$. Then, to get an estimate $score_i$ for a set $S_i$, we loop over the hashes $h_{t, q}$ for each query vector $q$ and count how often each index $j$ appears in $\mathcal{D}[i]_{t, h_{t,q}}$. After we finish this step, we have a count for each $j$ that represents how many times $h_t(q) = h_t(x_j)$. Equivalently, since $p(h(x) = h(y)) = \simwritten(x, y)$, if we divide by $L$ we have an estimate for $\simwritten(x_j, q)$. We then apply $\sigma$ to these estimates and save the result in a variable $\text{agg}_q$ to build up the inputs to $A$, and then apply $A$ to get our final estimate for $F(Q, S_i)$, which we store in $score_i$.
12
-
13
-
14
-
15
-
16
- \begin{table}[t]
17
- \centering
18
- \caption{Notation table with examples from the document search application.}
19
- \begin{tabular}{cll}
20
- \toprule
21
- Notation & Definition & Intuition (Document Search) \\
22
- \midrule
23
- $D$ &Set of target vector sets & Collection of documents\\
24
- % \midrule
25
- $N$ & Cardinality $|D|$ & Number of documents \\
26
- % \midrule
27
- $\mathcal{D}$ & DESSERT index of $D$ & Search index data structure\\
28
- % \midrule
29
- $S_i$ & Target vector set $i$ & $i$th document\\
30
- % \midrule
31
- $Q$ & Query vector set & Multi-word query (e.g., a question)\\
32
- % \midrule
33
- $S^*$ & See Definition~\ref{def:problem} & The most relevant document to $Q$\\
34
- % \midrule
35
- $x_j \in S_i$ & $j$th vector in target set $S_i$ & Embedding from document $i$\\
36
- % \midrule
37
- $q_j \in Q$ & $j$th vector in query set $Q$ & Embedding from a query\\
38
- % \midrule
39
- $d$ & $s_j, x_j \in \mathbb{R}^d$ & Embedding dimension \\
40
- % \midrule
41
- $m_i$, $m$ & Cardinality $|S_i|$, $m_i = m$ & Number of embeddings in $i$th document\\
42
- % \midrule
43
- $F(Q, S_i)$ & $Q$ and $S_i$ relevance score & Measures query-document similarity \\
44
- % \midrule
45
- $score_i$ & Estimate of $F(Q, S_i)$ & Approximation of relevance score\\
46
- % \midrule
47
- $\mathcal{D}[i]$ & Sketch of $i$th target set & Estimates relevance score for $S_i$ and any $Q$\\
48
- % \midrule
49
- $\simwritten(a, b)$ & $a$ and $b$ vector similarity & Embedding similarity\\
50
- % \midrule
51
- $A$, $\sigma$ & See Section~\ref{sec:formal} & Components of relevance score\\
52
- % \midrule
53
- $L$& Number of hashes & Larger $L$ increases accuracy and latency\\
54
- % \midrule
55
- $f_i$ & $i$th LSH function & Often maps nearby points to the same value\\
56
- % \midrule
57
- $\mat{s}(q,S_i)$, $\mat{s}$ & $\simwritten(q, x_j)$ for $x_j \in S_i$ & Query embedding similarities with $S_i$\\
58
- \bottomrule
59
- \end{tabular}
60
- \label{tab:notation}
61
- \end{table}
62
-
63
- \begin{figure}
64
- \begin{minipage}[t]{0.36\textwidth}
65
-
66
- \begin{algorithm}[H]
67
- \begin{algorithmic}[1]
68
- \STATE {\bfseries Input:} $N$ sets $S_i$, $|S_i| = m_i$
69
- \STATE {\bfseries Output:} A DESSERT index $\mathcal{D}$
70
- \STATE $\mathcal{D} = $ an array of $N$ hash tables, each indexed by $x \in \mathbb{Z}^2$
71
- \FOR{$i = 1$ to $N$}
72
- \FOR{$x_j$ {\bfseries in} $S_i$}
73
- \FOR{$t=1$ {\bfseries to} $L$}
74
- \STATE $h = f_t(x_j)$
75
- \STATE $\mathcal{D}[i]_{t, h} = \mathcal{D}[i]_{t, h} \cup \{j\}$
76
- \ENDFOR
77
- \ENDFOR
78
- \ENDFOR
79
- \STATE Return $\mathcal{D}$
80
- \end{algorithmic}
81
- \caption{Building a DESSERT Index}
82
- \label{alg:indexing}
83
- \end{algorithm}
84
-
85
- \end{minipage}\hfill
86
- \begin{minipage}[t]{0.6\textwidth}
87
-
88
-
89
- \begin{algorithm}[H]
90
- \begin{algorithmic}[1]
91
- \STATE {\bfseries Input:} DESSERT index $\mathcal{D}$, query set $Q$, $|Q| = m_q$.
92
- \STATE {\bfseries Output:} Estimate of $\argmax_{i \in \{1\ldots N\}} A \circ \sigma (Q, S_i)$
93
- \FOR{$q$ {\bfseries in} $Q$}
94
- \STATE $h_{1, q}, \ldots , h_{L, q} = f_1(q), \ldots, f_L(q)$
95
- \ENDFOR
96
- \FOR{$i = 1$ to $N$}
97
- \FOR{$q$ {\bfseries in} $Q$}
98
- \STATE $\hat{\mat{s}} = 0$
99
- \FOR{$t=1$ {\bfseries to} $L$}
100
- \FOR{$j$ {\bfseries in} $\mathcal{D}[i]_{t, h_{t, q}}$}
101
- \STATE $\hat{\mat{s}}_j = \hat{\mat{s}}_j + 1$
102
- \ENDFOR
103
- \ENDFOR
104
- \STATE $\hat{\mat{s}}$ = $\hat{\mat{s}}$ / L
105
- \STATE $agg_q = \sigma(\hat{\mat{s}})$
106
- \ENDFOR
107
- \STATE $score_i = A(\{agg_q \,|\, q \in Q\})$
108
- \ENDFOR
109
- \STATE Return $\argmax_{i\in \{1\ldots N\}} score_i$
110
- \end{algorithmic}
111
- \caption{Querying a DESSERT Index}
112
- \label{alg:query}
113
- \end{algorithm}
114
-
115
- \end{minipage}
116
- % \caption{Two Algorithms Side by Side}
117
- \end{figure}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
annotations/annotation_141/requirements.txt DELETED
@@ -1 +0,0 @@
1
- numpy>=1.20.0
 
 
annotations/annotation_141/test.py DELETED
@@ -1,211 +0,0 @@
1
- import os
2
- import sys
3
- import random
4
- import unittest
5
- import numpy as np
6
- import numpy.testing as npt
7
-
8
- # --- Robust loaders with adapters ---
9
- # These let the tests run whether a module exposes the exact interface functions
10
- # (build_dessert_index, dessert_query) OR only a DessertIndex class with methods.
11
- BASE_DIR = os.path.dirname(os.path.abspath(__file__))
12
- DESSERT_DIR = os.path.join(BASE_DIR, "DESSERT")
13
- if DESSERT_DIR not in sys.path:
14
- sys.path.insert(0, DESSERT_DIR)
15
-
16
-
17
- def _load_impls(module_name):
18
- mod = __import__(module_name)
19
-
20
- # Native interface present
21
- if hasattr(mod, "build_dessert_index") and hasattr(mod, "dessert_query"):
22
- return {
23
- "build": mod.build_dessert_index,
24
- "query": mod.dessert_query,
25
- "adapter": False,
26
- "module": mod,
27
- }
28
-
29
- # Fallback adapter over a DessertIndex class (canonical reference code)
30
- if hasattr(mod, "DessertIndex"):
31
- def _build_adapter(docs, num_tables, hashes_per_table, seed=None):
32
- # Expect numpy arrays for the class path
33
- d = int(docs[0].shape[1])
34
- idx = mod.DessertIndex(
35
- input_dim=d,
36
- srps_per_table=hashes_per_table,
37
- num_tables=num_tables,
38
- seed=(seed if seed is not None else 42),
39
- )
40
- idx.build_index(docs) # docs: List[np.ndarray], each (m_i, d)
41
- return {"_adapter": True, "index_obj": idx}
42
-
43
- def _query_adapter(index_data, query_set, top_k, inner_agg, outer_agg,
44
- weights=None, similarity="cosine"):
45
- # Map names to callables expected by the class
46
- sigma = max if inner_agg == "max" else (np.mean if inner_agg == "mean" else None)
47
- A = sum if outer_agg == "sum" else (np.mean if outer_agg == "mean" else None)
48
- idx = index_data["index_obj"]
49
- # Temporarily override aggregators
50
- old_sigma, old_A = getattr(idx, "sigma", None), getattr(idx, "A", None)
51
- idx.sigma, idx.A = sigma, A
52
- results = idx.search(query_set, top_k=top_k) # returns List[(doc_id, score)]
53
- idx.sigma, idx.A = old_sigma, old_A
54
- # Normalize to list[list]
55
- return [[int(doc), float(score)] for (doc, score) in results]
56
-
57
- return {
58
- "build": _build_adapter,
59
- "query": _query_adapter,
60
- "adapter": True,
61
- "module": mod,
62
- }
63
-
64
- raise ImportError(
65
- f"Module '{module_name}' must expose build_dessert_index/dessert_query "
66
- "or a DessertIndex class."
67
- )
68
-
69
- def _set_seed(seed=2025):
70
- random.seed(seed)
71
- os.environ["PYTHONHASHSEED"] = str(seed)
72
- np.random.seed(seed)
73
-
74
- def _normalize_results(res):
75
- # Normalize to list of [int, float], preserving order
76
- norm = []
77
- for item in res:
78
- if isinstance(item, (list, tuple)) and len(item) == 2:
79
- doc, score = item
80
- norm.append([int(doc), float(score)])
81
- else:
82
- raise AssertionError("Result items must be 2-tuples/lists [doc_id, score].")
83
- return norm
84
-
85
- def _compare_rankings(testcase, r1, r2, rtol=1e-6, atol=1e-8):
86
- testcase.assertEqual(len(r1), len(r2), "Length mismatch in ranked results.")
87
- for (d1, s1), (d2, s2) in zip(r1, r2):
88
- testcase.assertEqual(d1, d2, "Doc ID mismatch at a ranking position.")
89
- npt.assert_allclose([s1], [s2], rtol=rtol, atol=atol, err_msg="Score mismatch.")
90
-
91
- class TestDessertEquivalence(unittest.TestCase):
92
- @classmethod
93
- def setUpClass(cls):
94
- # Load both implementations (canonical & generated)
95
- cls.canon = _load_impls("canonical")
96
- cls.gen = _load_impls("generation")
97
-
98
-
99
- def setUp(self):
100
- _set_seed(314159)
101
-
102
- # Small, representative data: 5 docs with variable sizes, dim=16
103
- rng = np.random.default_rng(123)
104
- self.docs_np = [
105
- rng.standard_normal((3, 16)),
106
- rng.standard_normal((5, 16)),
107
- rng.standard_normal((4, 16)),
108
- rng.standard_normal((6, 16)),
109
- rng.standard_normal((2, 16)),
110
- ]
111
- self.query_np = rng.standard_normal((3, 16))
112
-
113
- # For the function-style interface (if present), we can also offer Python lists.
114
- self.docs_py = [arr.tolist() for arr in self.docs_np]
115
- self.query_py = self.query_np.tolist()
116
-
117
- # Hashing params (small)
118
- self.L = 4 # num_tables
119
- self.C = 3 # hashes_per_table
120
- self.SEED = 777
121
-
122
- # Utility to call build/query for either module, regardless of interface style
123
- def _build(self, impl):
124
- if impl["adapter"]:
125
- return impl["build"](self.docs_np, self.L, self.C, seed=self.SEED)
126
- else:
127
- return impl["build"](self.docs_py, self.L, self.C, seed=self.SEED)
128
-
129
- def _query(self, impl, index_data, top_k, inner_agg, outer_agg):
130
- if impl["adapter"]:
131
- return impl["query"](index_data, self.query_np, top_k, inner_agg, outer_agg,
132
- weights=None, similarity="cosine")
133
- else:
134
- return impl["query"](index_data, self.query_py, top_k, inner_agg, outer_agg,
135
- weights=None, similarity="cosine")
136
-
137
- # ---------- Tests ----------
138
-
139
- def test_equivalence_max_sum_top3(self):
140
- """ColBERT-style: σ=max, A=sum; top_k=3"""
141
- _set_seed(1)
142
- canon_idx = self._build(self.canon)
143
- _set_seed(1)
144
- gen_idx = self._build(self.gen)
145
-
146
- _set_seed(2)
147
- canon_res = _normalize_results(self._query(self.canon, canon_idx, top_k=3,
148
- inner_agg="max", outer_agg="sum"))
149
- _set_seed(2)
150
- gen_res = _normalize_results(self._query(self.gen, gen_idx, top_k=3,
151
- inner_agg="max", outer_agg="sum"))
152
-
153
- _compare_rankings(self, canon_res, gen_res)
154
-
155
- def test_equivalence_mean_mean_full(self):
156
- """σ=mean, A=mean; full ranking (top_k = #docs)"""
157
- k_full = len(self.docs_np)
158
-
159
- _set_seed(3)
160
- canon_idx = self._build(self.canon)
161
- _set_seed(3)
162
- gen_idx = self._build(self.gen)
163
-
164
- _set_seed(4)
165
- canon_res = _normalize_results(self._query(self.canon, canon_idx, top_k=k_full,
166
- inner_agg="mean", outer_agg="mean"))
167
- _set_seed(4)
168
- gen_res = _normalize_results(self._query(self.gen, gen_idx, top_k=k_full,
169
- inner_agg="mean", outer_agg="mean"))
170
-
171
- _compare_rankings(self, canon_res, gen_res)
172
-
173
- def test_equivalence_topk_exceeds_docs(self):
174
- """top_k > number of docs should still return ≤ #docs and be identical."""
175
- k_big = len(self.docs_np) + 10
176
-
177
- _set_seed(5)
178
- canon_idx = self._build(self.canon)
179
- _set_seed(5)
180
- gen_idx = self._build(self.gen)
181
-
182
- _set_seed(6)
183
- canon_res = _normalize_results(self._query(self.canon, canon_idx, top_k=k_big,
184
- inner_agg="max", outer_agg="sum"))
185
- _set_seed(6)
186
- gen_res = _normalize_results(self._query(self.gen, gen_idx, top_k=k_big,
187
- inner_agg="max", outer_agg="sum"))
188
-
189
- _compare_rankings(self, canon_res, gen_res)
190
-
191
- def test_equivalence_different_hash_params(self):
192
- """Sanity across a different (L, C) setting."""
193
- self.L, self.C = 6, 2
194
-
195
- _set_seed(7)
196
- canon_idx = self._build(self.canon)
197
- _set_seed(7)
198
- gen_idx = self._build(self.gen)
199
-
200
- _set_seed(8)
201
- canon_res = _normalize_results(self._query(self.canon, canon_idx, top_k=3,
202
- inner_agg="max", outer_agg="sum"))
203
- _set_seed(8)
204
- gen_res = _normalize_results(self._query(self.gen, gen_idx, top_k=3,
205
- inner_agg="max", outer_agg="sum"))
206
-
207
- _compare_rankings(self, canon_res, gen_res)
208
-
209
-
210
- if __name__ == "__main__":
211
- unittest.main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
annotations/annotation_141/test.sh DELETED
@@ -1 +0,0 @@
1
- python test.py