endomorphosis commited on
Commit
0acf40c
·
verified ·
1 Parent(s): 87eb5ec

Add files using upload-large-folder tool

Browse files
data/bm25/documents/part-000000.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:b30e2aa8a3ab860508a02a9e26f23778712c21ae9d2de137ee2ce3db1d2f08eb
3
- size 233099
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d345ec5581397c74a89b1ed1048f474287f1b5129367c9b638003a9c3484d603
3
+ size 264694
data/bm25/documents/part-000001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:18fcb3b9f0616a5ea391d4d683752acd7e47cec1b25c64f5caefafd3c7a41488
3
- size 38164
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1c34ab9ba4967e07d922a3e1dc40d2ea8ccbc6c63f0ca933ed6c55ad823f40fe
3
+ size 60550
data/corpus/part-000000.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:d4a96bc69002b19160159aa1b197835fc369919ddea7c422ff86ec113d28fd0d
3
- size 1072923
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:de235829a76e4a7cce70a64b8012a2429df5dd491900693d1539f330d5b3011a
3
+ size 1169368
data/corpus/part-000001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:09a34796339315d95c330c936e740a966f2b142baa9c8ef7ca271f38d731d137
3
- size 123868
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:71264c61710b4ba78aa5d43d811413fced90735af5d5ea2adea21c8370067706
3
+ size 217659
indexes/bm25_document_chunks.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:4af93d863bff15f1b8b62c9261db1bf902eaff01e30e6bb520b9622c8b23ccd9
3
- size 9036
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:33e121e9df28a84a6a0e5dc53706b562b9515d82ec124e1148e1e83abdbbee3c
3
+ size 5187
indexes/bm25_keyword_shards.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:9ff35314e5060f525cc12483d3e37453be62cc2fc915261291822a8affb411da
3
- size 10128
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:128ffd153fdd4d18419f3988bfafe8bfa9c9a3717cb10841bce38d927d8cee86
3
+ size 4370
indexes/corpus_chunks.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:6fc266aac245555e23b41c531cd932b6456c07029ca632cbf06fa2eaba2f18eb
3
- size 8952
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ed089ae0b2c3be7a0550f79bef41ef887b54546fa8f2bb4bfcb4bfba429e880e
3
+ size 5102
indexes/graph_edge_chunks.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:dfc60ea17fa6a7a170fea4a873bcfb811af48644997c13fc5c9525551c6546ff
3
- size 10526
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c1874e3829b7ca4296afb272a8f6401d7261872268c204e07e4b462cf66a80bc
3
+ size 7022
indexes/graph_incoming_adjacency.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:83e21c0296e8e5f2909ee77fedbb9a3b9975d31a0018899f970446ac3950af39
3
- size 11960
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:33e2d36333a87021f8475d0ec1975e77b0a7977a9bf9f42000c97245ec54808b
3
+ size 5044
indexes/graph_node_chunks.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:01f85730078e34c7b3e59599803e47a0215bf658b27442050fe25ad3e2cd0cea
3
- size 8987
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fa861de772ecc445a5e0f5578a24b79e0b10af29c66472428f892111f17ed9db
3
+ size 5154
indexes/graph_outgoing_adjacency.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:6ca782503ba7ff47dacef44cc95116d3c76beefe29576164d6a8f60df1d659a1
3
- size 12177
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8d09fe534aa0365aa91a93760f0bdc205e39b7bdc0f6a69f851b38ba5acd84bf
3
+ size 5288
indexes/vector_chunks.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:324977ab14fdf3e64e29386f8ce041fbfe55304f3419b40b5debf4641349240f
3
- size 22921
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3ceeb2197003a10f74f117c1871e044d6f89be10d1bd4fc8c33cc0176f3d4e38
3
+ size 5114
manifest.json CHANGED
@@ -1,62 +1,81 @@
1
  {
2
- "schema_version": "country-laws-ir-graphrag/v1",
3
- "layout_family": "skillcenter-huggingface-release/v3",
4
- "packager_version": "0.3.0",
5
- "primary_key": "entry_cid",
6
- "dataset_id": "endomorphosis/ipfs_saudiarabia_laws",
7
- "dataset_repo_id": "justicedao/ipfs_saudiarabia_laws_ir",
8
- "dataset_revision": "47bbf142ade8",
9
- "country": {
10
- "slug": "saudiarabia",
11
- "repo": "endomorphosis/ipfs_saudiarabia_laws",
12
- "name": "Saudi Arabia",
13
- "indexable": true,
14
- "skip_reason": null,
15
- "local_source_dir": "/workspace/country-laws-ir/cache/saudi_filtered_47bbf142",
16
- "source_revision": "47bbf142ade8"
17
- },
18
- "disclaimer": "Research snapshot. Not legal advice. The official gazette / authentic source prevails.",
19
  "bm25": {
20
- "k1": 1.2,
21
  "b": 0.75,
22
- "title_weight": 5.0,
23
  "body_weight": 1.0,
24
- "average_document_length": 5.600771869639794,
25
- "tokenizer": "fts5-unicode61-remove-diacritics-2-python/v1",
26
  "max_query_terms": 64,
27
  "posting_rows_per_record": 4096,
28
- "terms_per_shard": 4096
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  },
30
  "counts": {
31
  "bm25_document_chunks": 2,
32
  "bm25_documents": 4664,
33
  "bm25_keyword_shards": 1,
34
  "bm25_posting_rows": 1498,
 
35
  "bm25_postings": 10560,
36
  "bm25_terms": 1498,
37
  "corpus_chunks": 2,
38
  "corpus_rows": 4664,
 
39
  "graph_edge_chunks": 12,
40
  "graph_edges": 45185,
41
  "graph_incoming_adjacency_edges": 45185,
42
  "graph_incoming_adjacency_rows": 2445,
43
  "graph_incoming_adjacency_shards": 1,
44
  "graph_node_chunks": 2,
 
45
  "graph_nodes": 5353,
46
  "graph_outgoing_adjacency_edges": 45185,
47
  "graph_outgoing_adjacency_rows": 4664,
48
  "graph_outgoing_adjacency_shards": 2,
49
- "vector_chunks": 2,
50
- "vector_rows": 4664,
51
  "n_laws": 0,
52
- "n_articles": 4664
53
- },
54
- "parquet": {
55
- "compression": "zstd",
56
- "compression_level": 6,
57
- "max_rows_per_file": 4096,
58
- "row_group_size": 4096
59
  },
 
 
 
 
60
  "graph": {
61
  "adjacency_pointers_per_row": 4096,
62
  "adjacency_pointers_per_shard": 8192,
@@ -64,8 +83,6 @@
64
  "incoming",
65
  "outgoing"
66
  ],
67
- "max_remote_walk_depth": 8,
68
- "ordering": "score_desc_nulls_last",
69
  "edge_types": [
70
  "ARTICLE_OF",
71
  "BM25_NEIGHBOR_OF",
@@ -75,202 +92,288 @@
75
  "HAS_SOURCE",
76
  "HAS_STATUS",
77
  "IDENTIFIED_BY"
78
- ]
 
 
79
  },
80
- "vector": {
81
- "model_name": "thenlper/gte-small",
82
- "dimension": 384,
83
- "similarity": "cosine",
84
- "assignment": "recursive_spherical_kmeans",
85
- "layout": "semantic_centroid_groups",
86
- "rows_sorted_by": "cosine_similarity_to_shard_centroid_desc",
87
- "max_rows_per_chunk": 4096,
88
- "max_rows_per_centroid": 8192,
89
- "max_shards_per_centroid": 2,
90
- "default_probe_centroids": 2,
91
- "centroid_count": 2,
92
- "shard_count": 2,
93
- "n_vectors": 4664,
94
- "status": "embedded"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  },
96
- "canonical_fields": [
97
- "entry_cid",
98
- "law_cid",
99
- "record_type",
100
- "jurisdiction",
101
- "language",
102
- "instrument_id",
103
- "instrument_title",
104
- "article_number",
105
- "article_title",
106
- "title",
107
- "body",
108
- "source_url",
109
- "snapshot_date",
110
- "coverage",
111
- "license",
112
- "collector",
113
- "source_dataset",
114
- "source_revision"
115
- ],
116
  "input_sha256": {
117
- "laws.parquet": "71842e905fd18d1b13f19d5dc02288a5909765c377b06b86b145862702ade3f8",
118
- "articles.parquet": "c57d41b22c1d0210dc7d25bd3e0da8f5c16a3f50c0935896ed512db3b979a0a2"
119
  },
 
120
  "model_id": "thenlper/gte-small",
121
- "cid": {
122
- "codec": "raw",
123
- "hash": "sha2-256",
124
- "multibase": "base32",
125
- "payload": "json.dumps(obj, sort_keys=True, ensure_ascii=False, separators=(',', ':')).encode('utf-8')"
126
- },
127
  "normalization": {
128
- "source_dataset": "endomorphosis/ipfs_saudiarabia_laws",
129
- "source_revision": "47bbf142ade8",
130
- "laws_sha256": "71842e905fd18d1b13f19d5dc02288a5909765c377b06b86b145862702ade3f8",
131
- "articles_sha256": "c57d41b22c1d0210dc7d25bd3e0da8f5c16a3f50c0935896ed512db3b979a0a2",
132
- "n_laws_in": 623,
133
- "n_articles_in": 4664,
134
- "unit": "article",
135
  "article_law_coverage": 7.486356340288925,
136
- "sparse_article_fallback": false,
 
 
 
 
 
137
  "drops": {
138
- "empty_body": 0,
139
- "missing_instrument": 0,
140
  "duplicate_cid": 0,
141
- "duplicate_source_kept_first": 0
 
 
142
  },
143
- "drop_samples": {
144
- "empty_body": [],
145
- "missing_instrument": [],
146
- "duplicate_cid": []
147
  },
148
  "language_breakdown": {
149
  "ar": 4400,
150
  "en": 264
151
  },
 
 
 
 
 
 
 
152
  "quality_flags": {
153
- "articles_table_empty": false,
154
- "sparse_article_fallback": false,
155
- "article_law_coverage": 7.486356340288925,
156
  "all_source_article_counts_zero": false,
157
  "article_extraction_status_counts": {
158
- "ok": 232,
159
- "missing": 391
160
  },
 
 
 
 
 
161
  "missing_date": false,
162
  "missing_date_issued": false,
163
- "eli_present": false,
164
  "never_invented_legal_text": true,
165
- "empty_bodies_dropped": 0,
166
- "duplicate_cids_dropped": 0
 
 
167
  },
168
  "schema_surprises": [
169
  "laws.article_count dtype=int64",
170
  "laws.eli non-null=0/623",
171
  "laws.language values=['ar', 'en']"
172
  ],
173
- "n_out": 4664,
174
- "never_invented_legal_text": true,
175
- "n_before_dedupe": 4664,
176
- "n_dropped_total": 0,
177
- "record_type_breakdown": {
178
- "article": 4664
179
- },
180
- "jurisdiction_breakdown": {
181
- "SA": 4664
182
- },
183
  "snapshot_dates": [
184
  "2026-09-04"
185
- ]
 
 
 
 
 
 
 
 
 
 
 
186
  },
 
187
  "schema_mapping": {
188
- "laws": {
189
- "id": "instrument_id",
190
- "title": "instrument_title",
191
- "text": "body",
192
- "article_count_dtype_source": "int64"
193
- },
194
  "articles": {
195
  "id": "source_id / article identity",
196
  "law_id": "instrument_id",
197
- "title": "article_title",
198
- "text": "body"
199
  },
200
- "unit_policy": "prefer articles; fall back to law-level when articles empty",
201
- "required_law_columns": [
 
 
 
 
 
 
 
202
  "id",
 
203
  "title",
204
  "text"
205
  ],
206
- "required_article_columns": [
207
  "id",
208
- "law_id",
209
  "title",
210
  "text"
211
  ],
212
- "fail_closed": true,
213
- "notes": "Malta and Germany share the same column names. Drift: Malta article_count is int64, Germany article_count is int32; Germany eli is often null. Identifiers are never invented. Layout matches SkillCenter HF release / publicus-ir family."
214
- },
215
- "indexes": {
216
- "bm25_document_chunks": {
217
- "cid": "bafkreick7e6ymo77cxy3rnrmsjq5wg7zalvp6apdbzv3kifzmiwiwi6m3e",
218
- "sha256": "4af93d863bff15f1b8b62c9261db1bf902eaff01e30e6bb520b9622c8b23ccd9",
219
- "size_bytes": 9036,
220
- "relative_path": "indexes/bm25_document_chunks.parquet"
221
- },
222
- "bm25_keyword_shards": {
223
- "cid": "bafkreie76njrjzigb5jfzqjeqpj6g5ctxzrmyl6jcutbfemcfkfp7nar3i",
224
- "sha256": "9ff35314e5060f525cc12483d3e37453be62cc2fc915261291822a8affb411da",
225
- "size_bytes": 10128,
226
- "relative_path": "indexes/bm25_keyword_shards.parquet"
227
- },
228
- "corpus_chunks": {
229
- "cid": "bafkreidpyjtkvqsfkvpchna4kmonsmvwivwaoau4uyzmx4dpulvlulyy5m",
230
- "sha256": "6fc266aac245555e23b41c531cd932b6456c07029ca632cbf06fa2eaba2f18eb",
231
- "size_bytes": 8952,
232
- "relative_path": "indexes/corpus_chunks.parquet"
233
- },
234
- "graph_edge_chunks": {
235
- "cid": "bafkreig7yyhkc75gu6qxb7vevbz3z64bdl2imrezpqj7yxevevkryzkg74",
236
- "sha256": "dfc60ea17fa6a7a170fea4a873bcfb811af48644997c13fc5c9525551c6546ff",
237
- "size_bytes": 10526,
238
- "relative_path": "indexes/graph_edge_chunks.parquet"
239
- },
240
- "graph_incoming_adjacency": {
241
- "cid": "bafkreied4ioaffxi4xzjbhxhp7w3xgr3tf25ggqadcez7fyei2wdsufphe",
242
- "sha256": "83e21c0296e8e5f2909ee77fedbb9a3b9975d31a0018899f970446ac3950af39",
243
- "size_bytes": 11960,
244
- "relative_path": "indexes/graph_incoming_adjacency.parquet"
245
- },
246
- "graph_node_chunks": {
247
- "cid": "bafkreiab7bltab4ogtd3hzmvtgad4r5aefn7mwfsorbakd7cllj6ftim5i",
248
- "sha256": "01f85730078e34c7b3e59599803e47a0215bf658b27442050fe25ad3e2cd0cea",
249
- "size_bytes": 8987,
250
- "relative_path": "indexes/graph_node_chunks.parquet"
251
- },
252
- "graph_outgoing_adjacency": {
253
- "cid": "bafkreidmu6bfao5h75d5vtxujtevcfwty5v657rjk5qwjvvi6yg7dvszue",
254
- "sha256": "6ca782503ba7ff47dacef44cc95116d3c76beefe29576164d6a8f60df1d659a1",
255
- "size_bytes": 12177,
256
- "relative_path": "indexes/graph_outgoing_adjacency.parquet"
257
- },
258
- "vector_chunks": {
259
- "cid": "bafkreibsjf32wfh56pte4kjyn6goaqp37zktatzudg2awxpl6rsbgsjeb4",
260
- "sha256": "324977ab14fdf3e64e29386f8ce041fbfe55304f3419b40b5debf4641349240f",
261
- "size_bytes": 22921,
262
- "relative_path": "indexes/vector_chunks.parquet"
263
- }
264
  },
 
265
  "source": {
266
- "source_dataset": "endomorphosis/ipfs_saudiarabia_laws",
267
- "source_revision": "47bbf142ade8",
268
- "laws_path": "/workspace/country-laws-ir/cache/saudi_filtered_47bbf142/data/laws.parquet",
 
 
 
 
 
 
 
 
 
269
  "articles_path": "/workspace/country-laws-ir/cache/saudi_filtered_47bbf142/data/articles.parquet",
270
- "laws_sha256": "71842e905fd18d1b13f19d5dc02288a5909765c377b06b86b145862702ade3f8",
271
  "articles_sha256": "c57d41b22c1d0210dc7d25bd3e0da8f5c16a3f50c0935896ed512db3b979a0a2",
272
- "n_laws_source": 623,
273
- "n_articles_source": 4664,
274
  "laws_columns": [
275
  "id",
276
  "title",
@@ -292,34 +395,44 @@
292
  "json_path",
293
  "metadata_json"
294
  ],
295
- "articles_columns": [
296
- "law_id",
297
- "id",
298
- "title",
299
- "text",
300
- "source_url",
301
- "document_number",
302
- "article_number",
303
- "record_type",
304
- "metadata_json"
305
- ],
306
- "article_count_dtype": "int64",
307
- "schema_surprises": [
308
- "laws.article_count dtype=int64",
309
- "laws.eli non-null=0/623",
310
- "laws.language values=['ar', 'en']"
311
- ],
312
  "local_source_dir": "/workspace/country-laws-ir/cache/saudi_filtered_47bbf142",
 
 
313
  "pack_meta": {
314
- "slug": "saudiarabia",
 
 
315
  "name": "Saudi Arabia",
 
316
  "repo": "endomorphosis/ipfs_saudiarabia_laws",
 
317
  "source_dataset": "endomorphosis/ipfs_saudiarabia_laws",
318
- "source_revision": "47bbf142ade8",
319
- "publish_revision_note": "98e4e98014b9 (local PUBLISH_STATUS); Hub tip HEAD 47bbf142ade8",
320
- "filtered": true,
321
- "filter_reason": "soft article filter: drop form-UI (رمز التحقق / حقل المادة مطلوب) + empty title-only stubs (text len<30)",
322
- "indexable": true
323
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
324
  }
325
  }
 
1
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  "bm25": {
3
+ "average_document_length": 5.600771869639794,
4
  "b": 0.75,
 
5
  "body_weight": 1.0,
6
+ "k1": 1.2,
 
7
  "max_query_terms": 64,
8
  "posting_rows_per_record": 4096,
9
+ "terms_per_shard": 4096,
10
+ "title_weight": 5.0,
11
+ "tokenizer": "fts5-unicode61-remove-diacritics-2-python/v1"
12
+ },
13
+ "canonical_fields": [
14
+ "entry_cid",
15
+ "law_cid",
16
+ "record_type",
17
+ "jurisdiction",
18
+ "language",
19
+ "instrument_id",
20
+ "instrument_title",
21
+ "article_number",
22
+ "article_title",
23
+ "title",
24
+ "body",
25
+ "source_url",
26
+ "snapshot_date",
27
+ "coverage",
28
+ "license",
29
+ "collector",
30
+ "source_dataset",
31
+ "source_revision"
32
+ ],
33
+ "cid": {
34
+ "codec": "raw",
35
+ "hash": "sha2-256",
36
+ "multibase": "base32",
37
+ "payload": "json.dumps(obj, sort_keys=True, ensure_ascii=False, separators=(',', ':')).encode('utf-8')"
38
+ },
39
+ "country": {
40
+ "indexable": true,
41
+ "local_source_dir": "/workspace/country-laws-ir/cache/saudi_filtered_47bbf142",
42
+ "name": "Saudi Arabia",
43
+ "repo": "endomorphosis/ipfs_saudiarabia_laws",
44
+ "skip_reason": null,
45
+ "slug": "saudiarabia",
46
+ "source_revision": "47bbf142ade8"
47
  },
48
  "counts": {
49
  "bm25_document_chunks": 2,
50
  "bm25_documents": 4664,
51
  "bm25_keyword_shards": 1,
52
  "bm25_posting_rows": 1498,
53
+ "bm25_posting_shards": 1,
54
  "bm25_postings": 10560,
55
  "bm25_terms": 1498,
56
  "corpus_chunks": 2,
57
  "corpus_rows": 4664,
58
+ "corpus_shards": 2,
59
  "graph_edge_chunks": 12,
60
  "graph_edges": 45185,
61
  "graph_incoming_adjacency_edges": 45185,
62
  "graph_incoming_adjacency_rows": 2445,
63
  "graph_incoming_adjacency_shards": 1,
64
  "graph_node_chunks": 2,
65
+ "graph_node_shards": 2,
66
  "graph_nodes": 5353,
67
  "graph_outgoing_adjacency_edges": 45185,
68
  "graph_outgoing_adjacency_rows": 4664,
69
  "graph_outgoing_adjacency_shards": 2,
70
+ "n_articles": 4664,
 
71
  "n_laws": 0,
72
+ "vector_chunks": 2,
73
+ "vector_rows": 4664
 
 
 
 
 
74
  },
75
+ "dataset_id": "endomorphosis/ipfs_saudiarabia_laws",
76
+ "dataset_repo_id": "justicedao/ipfs_saudiarabia_laws_ir",
77
+ "dataset_revision": "47bbf142ade8",
78
+ "disclaimer": "Research snapshot. Not legal advice. The official gazette / authentic source prevails.",
79
  "graph": {
80
  "adjacency_pointers_per_row": 4096,
81
  "adjacency_pointers_per_shard": 8192,
 
83
  "incoming",
84
  "outgoing"
85
  ],
 
 
86
  "edge_types": [
87
  "ARTICLE_OF",
88
  "BM25_NEIGHBOR_OF",
 
92
  "HAS_SOURCE",
93
  "HAS_STATUS",
94
  "IDENTIFIED_BY"
95
+ ],
96
+ "max_remote_walk_depth": 8,
97
+ "ordering": "score_desc_nulls_last"
98
  },
99
+ "indexes": {
100
+ "bm25_document_chunks": {
101
+ "cid": "bafkreick7e6ymo77cxy3rnrmsjq5wg7zalvp6apdbzv3kifzmiwiwi6m3e",
102
+ "content_cid": "bafkreibt4eq6txzivbfguds5yu3qnnlcxfiv3axmcjhbcshb5a5l3o7ohq",
103
+ "family": "routing_index",
104
+ "media_type": "application/vnd.apache.parquet",
105
+ "relative_path": "indexes/bm25_document_chunks.parquet",
106
+ "row_count": 2,
107
+ "schema_id": "hf-graphrag-compact-index/v1",
108
+ "sha256": "33e121e9df28a84a6a0e5dc53706b562b9515d82ec124e1148e1e83abdbbee3c",
109
+ "size_bytes": 5187
110
+ },
111
+ "bm25_documents": {
112
+ "content_cid": "bafkreibt4eq6txzivbfguds5yu3qnnlcxfiv3axmcjhbcshb5a5l3o7ohq",
113
+ "family": "routing_index",
114
+ "media_type": "application/vnd.apache.parquet",
115
+ "relative_path": "indexes/bm25_document_chunks.parquet",
116
+ "row_count": 2,
117
+ "schema_id": "hf-graphrag-compact-index/v1",
118
+ "sha256": "33e121e9df28a84a6a0e5dc53706b562b9515d82ec124e1148e1e83abdbbee3c",
119
+ "size_bytes": 5187
120
+ },
121
+ "bm25_keyword_index": {
122
+ "content_cid": "bafkreiasr76rkp65jumedhzzrc7272f7vhe2g4l4weeedphdrwjh3dhoqy",
123
+ "family": "routing_index",
124
+ "media_type": "application/vnd.apache.parquet",
125
+ "relative_path": "indexes/bm25_keyword_shards.parquet",
126
+ "row_count": 1,
127
+ "schema_id": "hf-graphrag-compact-index/v1",
128
+ "sha256": "128ffd153fdd4d18419f3988bfafe8bfa9c9a3717cb10841bce38d927d8cee86",
129
+ "size_bytes": 4370
130
+ },
131
+ "bm25_keyword_shards": {
132
+ "cid": "bafkreie76njrjzigb5jfzqjeqpj6g5ctxzrmyl6jcutbfemcfkfp7nar3i",
133
+ "content_cid": "bafkreiasr76rkp65jumedhzzrc7272f7vhe2g4l4weeedphdrwjh3dhoqy",
134
+ "family": "routing_index",
135
+ "media_type": "application/vnd.apache.parquet",
136
+ "relative_path": "indexes/bm25_keyword_shards.parquet",
137
+ "row_count": 1,
138
+ "schema_id": "hf-graphrag-compact-index/v1",
139
+ "sha256": "128ffd153fdd4d18419f3988bfafe8bfa9c9a3717cb10841bce38d927d8cee86",
140
+ "size_bytes": 4370
141
+ },
142
+ "bm25_postings": {
143
+ "content_cid": "bafkreiasr76rkp65jumedhzzrc7272f7vhe2g4l4weeedphdrwjh3dhoqy",
144
+ "family": "routing_index",
145
+ "media_type": "application/vnd.apache.parquet",
146
+ "relative_path": "indexes/bm25_keyword_shards.parquet",
147
+ "row_count": 1,
148
+ "schema_id": "hf-graphrag-compact-index/v1",
149
+ "sha256": "128ffd153fdd4d18419f3988bfafe8bfa9c9a3717cb10841bce38d927d8cee86",
150
+ "size_bytes": 4370
151
+ },
152
+ "corpus": {
153
+ "content_cid": "bafkreihnbcnobmwdxz5akuhxtpxud34ipnkfi35i6k5ux7fux65efhuiby",
154
+ "family": "routing_index",
155
+ "media_type": "application/vnd.apache.parquet",
156
+ "relative_path": "indexes/corpus_chunks.parquet",
157
+ "row_count": 2,
158
+ "schema_id": "hf-graphrag-compact-index/v1",
159
+ "sha256": "ed089ae0b2c3be7a0550f79bef41ef887b54546fa8f2bb4bfcb4bfba429e880e",
160
+ "size_bytes": 5102
161
+ },
162
+ "corpus_chunks": {
163
+ "cid": "bafkreidpyjtkvqsfkvpchna4kmonsmvwivwaoau4uyzmx4dpulvlulyy5m",
164
+ "content_cid": "bafkreihnbcnobmwdxz5akuhxtpxud34ipnkfi35i6k5ux7fux65efhuiby",
165
+ "family": "routing_index",
166
+ "media_type": "application/vnd.apache.parquet",
167
+ "relative_path": "indexes/corpus_chunks.parquet",
168
+ "row_count": 2,
169
+ "schema_id": "hf-graphrag-compact-index/v1",
170
+ "sha256": "ed089ae0b2c3be7a0550f79bef41ef887b54546fa8f2bb4bfcb4bfba429e880e",
171
+ "size_bytes": 5102
172
+ },
173
+ "graph_edge_chunks": {
174
+ "cid": "bafkreig7yyhkc75gu6qxb7vevbz3z64bdl2imrezpqj7yxevevkryzkg74",
175
+ "content_cid": "bafkreigbq5hdqknxzjbjnl5sokupmqa5ojqyoitiyicoa7sliywpm2uaxq",
176
+ "family": "routing_index",
177
+ "media_type": "application/vnd.apache.parquet",
178
+ "relative_path": "indexes/graph_edge_chunks.parquet",
179
+ "row_count": 12,
180
+ "schema_id": "hf-graphrag-compact-index/v1",
181
+ "sha256": "c1874e3829b7ca4296afb272a8f6401d7261872268c204e07e4b462cf66a80bc",
182
+ "size_bytes": 7022
183
+ },
184
+ "graph_edges": {
185
+ "content_cid": "bafkreigbq5hdqknxzjbjnl5sokupmqa5ojqyoitiyicoa7sliywpm2uaxq",
186
+ "family": "routing_index",
187
+ "media_type": "application/vnd.apache.parquet",
188
+ "relative_path": "indexes/graph_edge_chunks.parquet",
189
+ "row_count": 12,
190
+ "schema_id": "hf-graphrag-compact-index/v1",
191
+ "sha256": "c1874e3829b7ca4296afb272a8f6401d7261872268c204e07e4b462cf66a80bc",
192
+ "size_bytes": 7022
193
+ },
194
+ "graph_incoming_adjacency": {
195
+ "cid": "bafkreied4ioaffxi4xzjbhxhp7w3xgr3tf25ggqadcez7fyei2wdsufphe",
196
+ "content_cid": "bafkreibt4ljwgm5ioaq7qr25b3azoxtxwctzo6u37h2caagjojc6yvearm",
197
+ "family": "routing_index",
198
+ "media_type": "application/vnd.apache.parquet",
199
+ "relative_path": "indexes/graph_incoming_adjacency.parquet",
200
+ "row_count": 1,
201
+ "schema_id": "hf-graphrag-compact-index/v1",
202
+ "sha256": "33e2d36333a87021f8475d0ec1975e77b0a7977a9bf9f42000c97245ec54808b",
203
+ "size_bytes": 5044
204
+ },
205
+ "graph_node_chunks": {
206
+ "cid": "bafkreiab7bltab4ogtd3hzmvtgad4r5aefn7mwfsorbakd7cllj6ftim5i",
207
+ "content_cid": "bafkreih2qyo6o4xmyrc2lyhvk6fcjn46bmik6kogmrzefd4jeei7c7wz3m",
208
+ "family": "routing_index",
209
+ "media_type": "application/vnd.apache.parquet",
210
+ "relative_path": "indexes/graph_node_chunks.parquet",
211
+ "row_count": 2,
212
+ "schema_id": "hf-graphrag-compact-index/v1",
213
+ "sha256": "fa861de772ecc445a5e0f5578a24b79e0b10af29c66472428f892111f17ed9db",
214
+ "size_bytes": 5154
215
+ },
216
+ "graph_nodes": {
217
+ "content_cid": "bafkreih2qyo6o4xmyrc2lyhvk6fcjn46bmik6kogmrzefd4jeei7c7wz3m",
218
+ "family": "routing_index",
219
+ "media_type": "application/vnd.apache.parquet",
220
+ "relative_path": "indexes/graph_node_chunks.parquet",
221
+ "row_count": 2,
222
+ "schema_id": "hf-graphrag-compact-index/v1",
223
+ "sha256": "fa861de772ecc445a5e0f5578a24b79e0b10af29c66472428f892111f17ed9db",
224
+ "size_bytes": 5154
225
+ },
226
+ "graph_outgoing_adjacency": {
227
+ "cid": "bafkreidmu6bfao5h75d5vtxujtevcfwty5v657rjk5qwjvvi6yg7dvszue",
228
+ "content_cid": "bafkreienbh7fgsvagznksgutoyhqxxbaly43ppoa62tj7bi3hc5fvtmex4",
229
+ "family": "routing_index",
230
+ "media_type": "application/vnd.apache.parquet",
231
+ "relative_path": "indexes/graph_outgoing_adjacency.parquet",
232
+ "row_count": 2,
233
+ "schema_id": "hf-graphrag-compact-index/v1",
234
+ "sha256": "8d09fe534aa0365aa91a93760f0bdc205e39b7bdc0f6a69f851b38ba5acd84bf",
235
+ "size_bytes": 5288
236
+ },
237
+ "vector_chunks": {
238
+ "cid": "bafkreibsjf32wfh56pte4kjyn6goaqp37zktatzudg2awxpl6rsbgsjeb4",
239
+ "content_cid": "bafkreib452zbs4aduehxj4ixygdr4bcnn6e34egrxvh4rqz4yalw6pkoha",
240
+ "family": "routing_index",
241
+ "media_type": "application/vnd.apache.parquet",
242
+ "relative_path": "indexes/vector_chunks.parquet",
243
+ "row_count": 2,
244
+ "schema_id": "hf-graphrag-compact-index/v1",
245
+ "sha256": "3ceeb2197003a10f74f117c1871e044d6f89be10d1bd4fc8c33cc0176f3d4e38",
246
+ "size_bytes": 5114
247
+ },
248
+ "vectors": {
249
+ "content_cid": "bafkreib452zbs4aduehxj4ixygdr4bcnn6e34egrxvh4rqz4yalw6pkoha",
250
+ "family": "routing_index",
251
+ "media_type": "application/vnd.apache.parquet",
252
+ "relative_path": "indexes/vector_chunks.parquet",
253
+ "row_count": 2,
254
+ "schema_id": "hf-graphrag-compact-index/v1",
255
+ "sha256": "3ceeb2197003a10f74f117c1871e044d6f89be10d1bd4fc8c33cc0176f3d4e38",
256
+ "size_bytes": 5114
257
+ }
258
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  "input_sha256": {
260
+ "articles.parquet": "c57d41b22c1d0210dc7d25bd3e0da8f5c16a3f50c0935896ed512db3b979a0a2",
261
+ "laws.parquet": "71842e905fd18d1b13f19d5dc02288a5909765c377b06b86b145862702ade3f8"
262
  },
263
+ "layout_family": "skillcenter-huggingface-release/v3",
264
  "model_id": "thenlper/gte-small",
 
 
 
 
 
 
265
  "normalization": {
 
 
 
 
 
 
 
266
  "article_law_coverage": 7.486356340288925,
267
+ "articles_sha256": "c57d41b22c1d0210dc7d25bd3e0da8f5c16a3f50c0935896ed512db3b979a0a2",
268
+ "drop_samples": {
269
+ "duplicate_cid": [],
270
+ "empty_body": [],
271
+ "missing_instrument": []
272
+ },
273
  "drops": {
 
 
274
  "duplicate_cid": 0,
275
+ "duplicate_source_kept_first": 0,
276
+ "empty_body": 0,
277
+ "missing_instrument": 0
278
  },
279
+ "jurisdiction_breakdown": {
280
+ "SA": 4664
 
 
281
  },
282
  "language_breakdown": {
283
  "ar": 4400,
284
  "en": 264
285
  },
286
+ "laws_sha256": "71842e905fd18d1b13f19d5dc02288a5909765c377b06b86b145862702ade3f8",
287
+ "n_articles_in": 4664,
288
+ "n_before_dedupe": 4664,
289
+ "n_dropped_total": 0,
290
+ "n_laws_in": 623,
291
+ "n_out": 4664,
292
+ "never_invented_legal_text": true,
293
  "quality_flags": {
 
 
 
294
  "all_source_article_counts_zero": false,
295
  "article_extraction_status_counts": {
296
+ "missing": 391,
297
+ "ok": 232
298
  },
299
+ "article_law_coverage": 7.486356340288925,
300
+ "articles_table_empty": false,
301
+ "duplicate_cids_dropped": 0,
302
+ "eli_present": false,
303
+ "empty_bodies_dropped": 0,
304
  "missing_date": false,
305
  "missing_date_issued": false,
 
306
  "never_invented_legal_text": true,
307
+ "sparse_article_fallback": false
308
+ },
309
+ "record_type_breakdown": {
310
+ "article": 4664
311
  },
312
  "schema_surprises": [
313
  "laws.article_count dtype=int64",
314
  "laws.eli non-null=0/623",
315
  "laws.language values=['ar', 'en']"
316
  ],
 
 
 
 
 
 
 
 
 
 
317
  "snapshot_dates": [
318
  "2026-09-04"
319
+ ],
320
+ "source_dataset": "endomorphosis/ipfs_saudiarabia_laws",
321
+ "source_revision": "47bbf142ade8",
322
+ "sparse_article_fallback": false,
323
+ "unit": "article"
324
+ },
325
+ "packager_version": "0.3.0",
326
+ "parquet": {
327
+ "compression": "zstd",
328
+ "compression_level": 6,
329
+ "max_rows_per_file": 4096,
330
+ "row_group_size": 4096
331
  },
332
+ "primary_key": "entry_cid",
333
  "schema_mapping": {
 
 
 
 
 
 
334
  "articles": {
335
  "id": "source_id / article identity",
336
  "law_id": "instrument_id",
337
+ "text": "body",
338
+ "title": "article_title"
339
  },
340
+ "fail_closed": true,
341
+ "laws": {
342
+ "article_count_dtype_source": "int64",
343
+ "id": "instrument_id",
344
+ "text": "body",
345
+ "title": "instrument_title"
346
+ },
347
+ "notes": "Malta and Germany share the same column names. Drift: Malta article_count is int64, Germany article_count is int32; Germany eli is often null. Identifiers are never invented. Layout matches SkillCenter HF release / publicus-ir family.",
348
+ "required_article_columns": [
349
  "id",
350
+ "law_id",
351
  "title",
352
  "text"
353
  ],
354
+ "required_law_columns": [
355
  "id",
 
356
  "title",
357
  "text"
358
  ],
359
+ "unit_policy": "prefer articles; fall back to law-level when articles empty"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
360
  },
361
+ "schema_version": "country-laws-ir-graphrag/v1",
362
  "source": {
363
+ "article_count_dtype": "int64",
364
+ "articles_columns": [
365
+ "law_id",
366
+ "id",
367
+ "title",
368
+ "text",
369
+ "source_url",
370
+ "document_number",
371
+ "article_number",
372
+ "record_type",
373
+ "metadata_json"
374
+ ],
375
  "articles_path": "/workspace/country-laws-ir/cache/saudi_filtered_47bbf142/data/articles.parquet",
 
376
  "articles_sha256": "c57d41b22c1d0210dc7d25bd3e0da8f5c16a3f50c0935896ed512db3b979a0a2",
 
 
377
  "laws_columns": [
378
  "id",
379
  "title",
 
395
  "json_path",
396
  "metadata_json"
397
  ],
398
+ "laws_path": "/workspace/country-laws-ir/cache/saudi_filtered_47bbf142/data/laws.parquet",
399
+ "laws_sha256": "71842e905fd18d1b13f19d5dc02288a5909765c377b06b86b145862702ade3f8",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
400
  "local_source_dir": "/workspace/country-laws-ir/cache/saudi_filtered_47bbf142",
401
+ "n_articles_source": 4664,
402
+ "n_laws_source": 623,
403
  "pack_meta": {
404
+ "filter_reason": "soft article filter: drop form-UI (\u0631\u0645\u0632 \u0627\u0644\u062a\u062d\u0642\u0642 / \u062d\u0642\u0644 \u0627\u0644\u0645\u0627\u062f\u0629 \u0645\u0637\u0644\u0648\u0628) + empty title-only stubs (text len<30)",
405
+ "filtered": true,
406
+ "indexable": true,
407
  "name": "Saudi Arabia",
408
+ "publish_revision_note": "98e4e98014b9 (local PUBLISH_STATUS); Hub tip HEAD 47bbf142ade8",
409
  "repo": "endomorphosis/ipfs_saudiarabia_laws",
410
+ "slug": "saudiarabia",
411
  "source_dataset": "endomorphosis/ipfs_saudiarabia_laws",
412
+ "source_revision": "47bbf142ade8"
413
+ },
414
+ "schema_surprises": [
415
+ "laws.article_count dtype=int64",
416
+ "laws.eli non-null=0/623",
417
+ "laws.language values=['ar', 'en']"
418
+ ],
419
+ "source_dataset": "endomorphosis/ipfs_saudiarabia_laws",
420
+ "source_revision": "47bbf142ade8"
421
+ },
422
+ "vector": {
423
+ "assignment": "recursive_spherical_kmeans",
424
+ "centroid_count": 2,
425
+ "default_probe_centroids": 2,
426
+ "dimension": 384,
427
+ "layout": "semantic_centroid_groups",
428
+ "max_rows_per_centroid": 8192,
429
+ "max_rows_per_chunk": 4096,
430
+ "max_shards_per_centroid": 2,
431
+ "model_name": "thenlper/gte-small",
432
+ "n_vectors": 4664,
433
+ "rows_sorted_by": "cosine_similarity_to_shard_centroid_desc",
434
+ "shard_count": 2,
435
+ "similarity": "cosine",
436
+ "status": "embedded"
437
  }
438
  }
scripts/query_hf_graphrag.py ADDED
@@ -0,0 +1,406 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Standalone thin-client search for a Hugging Face GraphRAG release.
3
+
4
+ Hub consumers can copy ``scripts/query_hf_graphrag.py`` (and
5
+ ``semantic_traversal.py`` when present) out of the dataset and search without
6
+ downloading the full corpus:
7
+
8
+ python scripts/query_hf_graphrag.py --local-root . bm25 "foia agency"
9
+ python scripts/query_hf_graphrag.py --repo-id ORG/NAME --revision PIN \\
10
+ neighbors bafkrei... --direction both --limit 25
11
+
12
+ Requires pyarrow. Remote queries also need huggingface_hub. Vector search
13
+ needs numpy; local embedding needs sentence-transformers.
14
+ """
15
+ from __future__ import annotations
16
+
17
+ import argparse
18
+ import hashlib
19
+ import heapq
20
+ import json
21
+ import math
22
+ import os
23
+ import re
24
+ import sys
25
+ from collections import defaultdict
26
+ from pathlib import Path, PurePosixPath
27
+ from typing import Any, Mapping, Sequence
28
+
29
+ TOKEN_RE = re.compile(r"[a-z0-9]+(?:[-_./:][a-z0-9]+)*", re.I)
30
+ DEFAULT_MANIFEST = "manifest.json"
31
+ DEFAULT_CACHE = Path("~/.cache/ipfs_datasets_py/hf-graphrag-query").expanduser()
32
+
33
+
34
+ class RemoteQueryError(RuntimeError):
35
+ """Malformed release or missing dependency."""
36
+
37
+
38
+ def _safe_relative(path: str) -> PurePosixPath:
39
+ rel = PurePosixPath(str(path or "").replace("\\", "/"))
40
+ if rel.is_absolute() or ".." in rel.parts or not rel.parts:
41
+ raise RemoteQueryError(f"unsafe release path: {path!r}")
42
+ return rel
43
+
44
+
45
+ def _sha256(path: Path) -> str:
46
+ digest = hashlib.sha256()
47
+ with path.open("rb") as handle:
48
+ for chunk in iter(lambda: handle.read(1024 * 1024), b""):
49
+ digest.update(chunk)
50
+ return digest.hexdigest()
51
+
52
+
53
+ class ArtifactResolver:
54
+ """Fetch only requested files from a local root or the Hub."""
55
+
56
+ def __init__(
57
+ self,
58
+ *,
59
+ repo_id: str,
60
+ revision: str,
61
+ token: str | None,
62
+ cache_dir: Path,
63
+ local_root: Path | None,
64
+ ) -> None:
65
+ self.repo_id = repo_id
66
+ self.revision = revision
67
+ self.token = token
68
+ self.cache_dir = cache_dir
69
+ self.local_root = local_root.expanduser().resolve() if local_root else None
70
+ self.fetched: dict[str, int] = {}
71
+
72
+ def path(self, relative: str, descriptor: Mapping[str, Any] | None = None) -> Path:
73
+ safe = _safe_relative(relative)
74
+ if self.local_root is not None:
75
+ path = (self.local_root.joinpath(*safe.parts)).resolve()
76
+ try:
77
+ path.relative_to(self.local_root)
78
+ except ValueError as exc:
79
+ raise RemoteQueryError("path escapes release root") from exc
80
+ if not path.is_file():
81
+ raise RemoteQueryError(f"missing {relative}")
82
+ else:
83
+ try:
84
+ from huggingface_hub import hf_hub_download
85
+ except ImportError as exc:
86
+ raise RemoteQueryError("huggingface_hub is required for --repo-id") from exc
87
+ path = Path(
88
+ hf_hub_download(
89
+ repo_id=self.repo_id,
90
+ filename=safe.as_posix(),
91
+ repo_type="dataset",
92
+ revision=self.revision,
93
+ token=self.token,
94
+ cache_dir=str(self.cache_dir),
95
+ )
96
+ )
97
+ if descriptor and descriptor.get("sha256"):
98
+ got = _sha256(path)
99
+ expected = str(descriptor["sha256"]).removeprefix("sha256:")
100
+ if got != expected:
101
+ raise RemoteQueryError(f"sha256 mismatch for {relative}")
102
+ self.fetched[safe.as_posix()] = path.stat().st_size
103
+ return path
104
+
105
+ def json(self, relative: str) -> Any:
106
+ return json.loads(self.path(relative).read_text(encoding="utf-8"))
107
+
108
+ def parquet(self, relative: str, columns: Sequence[str] | None = None, descriptor=None):
109
+ import pyarrow.parquet as pq
110
+
111
+ return pq.read_table(
112
+ self.path(relative, descriptor),
113
+ columns=list(columns) if columns else None,
114
+ )
115
+
116
+ def trace(self) -> dict[str, Any]:
117
+ files = [
118
+ {"relative_path": path, "size_bytes": size}
119
+ for path, size in sorted(self.fetched.items())
120
+ ]
121
+ return {
122
+ "file_count": len(files),
123
+ "files": files,
124
+ "total_file_bytes": sum(item["size_bytes"] for item in files),
125
+ }
126
+
127
+
128
+ def _tokenize(query: str) -> list[str]:
129
+ return [token.lower() for token in TOKEN_RE.findall(query or "")]
130
+
131
+
132
+ def _bm25_score(tf: float, idf: float, doc_len: float, avgdl: float, k1: float, b: float) -> float:
133
+ if tf <= 0 or idf <= 0 or avgdl <= 0:
134
+ return 0.0
135
+ denom = tf + k1 * (1.0 - b + b * (doc_len / avgdl))
136
+ if denom <= 0:
137
+ return 0.0
138
+ return idf * (tf * (k1 + 1.0) / denom)
139
+
140
+
141
+ def _index_rows(manifest: Mapping[str, Any], key: str) -> list[dict[str, Any]]:
142
+ indexes = manifest.get("indexes") or {}
143
+ row = indexes.get(key) or indexes.get(key.replace("_", "-"))
144
+ return [row] if isinstance(row, dict) and row.get("relative_path") else []
145
+
146
+
147
+ class ThinClient:
148
+ def __init__(self, resolver: ArtifactResolver, manifest: Mapping[str, Any]) -> None:
149
+ self.resolver = resolver
150
+ self.manifest = dict(manifest)
151
+
152
+ def _locator(self, name: str) -> list[dict[str, Any]]:
153
+ indexes = self.manifest.get("indexes") or {}
154
+ aliases = {
155
+ "bm25_keyword_shards": (
156
+ "bm25_keyword_shards",
157
+ "bm25_postings",
158
+ "bm25_keyword_index",
159
+ ),
160
+ "bm25_postings": (
161
+ "bm25_postings",
162
+ "bm25_keyword_shards",
163
+ "bm25_keyword_index",
164
+ ),
165
+ }.get(name, (name,))
166
+ candidates: list[tuple[str, Mapping[str, Any] | None]] = []
167
+ seen: set[str] = set()
168
+ for key in aliases:
169
+ desc = indexes.get(key)
170
+ if isinstance(desc, dict) and desc.get("relative_path"):
171
+ relative = str(desc["relative_path"])
172
+ if relative not in seen:
173
+ candidates.append((relative, desc))
174
+ seen.add(relative)
175
+ for fallback in (f"indexes/{key}.parquet", f"indexes/{key}.json"):
176
+ if fallback not in seen:
177
+ candidates.append((fallback, None))
178
+ seen.add(fallback)
179
+ for relative, desc in candidates:
180
+ try:
181
+ if relative.endswith(".json"):
182
+ payload = self.resolver.json(relative)
183
+ rows = payload.get("routing") or payload.get("shards") or payload
184
+ if isinstance(rows, list):
185
+ return [dict(row) for row in rows]
186
+ continue
187
+ try:
188
+ table = self.resolver.parquet(relative, descriptor=desc)
189
+ except RemoteQueryError as exc:
190
+ # Rewritten locators often keep the country-pack name
191
+ # with a stale sha256. Retry the same path unchecked.
192
+ if "sha256 mismatch" not in str(exc) or desc is None:
193
+ raise
194
+ table = self.resolver.parquet(relative, descriptor=None)
195
+ return table.to_pylist()
196
+ except (RemoteQueryError, OSError, FileNotFoundError):
197
+ continue
198
+ raise RemoteQueryError(f"locator missing: {name}")
199
+
200
+ def _covering(self, rows: Sequence[Mapping[str, Any]], key: str) -> list[dict[str, Any]]:
201
+ hits = []
202
+ for row in rows:
203
+ first = str(row.get("first_key") or "")
204
+ last = str(row.get("last_key") or "")
205
+ if first <= key <= last:
206
+ hits.append(dict(row))
207
+ return hits or [dict(row) for row in rows if str(row.get("first_key") or "") == key]
208
+
209
+ def bm25(self, query: str, *, top_k: int) -> dict[str, Any]:
210
+ terms = _tokenize(query)[:64]
211
+ config = dict(self.manifest.get("bm25") or {})
212
+ k1 = float(config.get("k1") or 1.2)
213
+ b = float(config.get("b") or 0.75)
214
+ avgdl = float(config.get("average_document_length") or config.get("avg_doc_tokens") or 1.0)
215
+ title_w = float(config.get("title_weight") or 1.0)
216
+ body_w = float(config.get("body_weight") or 1.0)
217
+ loc = self._locator("bm25_keyword_shards") or self._locator("bm25_postings")
218
+ scores: dict[str, float] = defaultdict(float)
219
+ matched: dict[str, set[str]] = defaultdict(set)
220
+ shards = 0
221
+ for term in terms:
222
+ for row in self._covering(loc, term):
223
+ relative = str(row.get("relative_path") or "")
224
+ table = self.resolver.parquet(relative, descriptor=row)
225
+ names = set(table.schema.names)
226
+ shards += 1
227
+ if "document_indices" in names:
228
+ for rec in table.to_pylist():
229
+ if str(rec.get("term")) != term:
230
+ continue
231
+ idf = float(rec.get("idf") or 0.0)
232
+ for doc, title_tf, body_tf, length in zip(
233
+ rec.get("document_indices") or (),
234
+ rec.get("title_frequencies") or (),
235
+ rec.get("body_frequencies") or (),
236
+ rec.get("document_lengths") or (),
237
+ ):
238
+ tf = title_w * float(title_tf or 0) + body_w * float(body_tf or 0)
239
+ key = str(int(doc))
240
+ scores[key] += _bm25_score(tf, idf, float(length or 0), avgdl, k1, b)
241
+ matched[key].add(term)
242
+ elif "legal_id" in names:
243
+ for rec in table.to_pylist():
244
+ if str(rec.get("term")) != term:
245
+ continue
246
+ key = str(rec.get("legal_id") or rec.get("entry_cid"))
247
+ scores[key] += float(rec.get("tf") or 0)
248
+ matched[key].add(term)
249
+ ranked = heapq.nlargest(top_k, scores.items(), key=lambda item: item[1])
250
+ hits = [
251
+ {
252
+ "id": doc,
253
+ "score": score,
254
+ "matched_terms": sorted(matched[doc]),
255
+ "authority": "context_only",
256
+ }
257
+ for doc, score in ranked
258
+ ]
259
+ return {"mode": "bm25", "query": query, "hits": hits, "fetch_trace": self.resolver.trace(), "shards": shards}
260
+
261
+ def neighbors(self, node_cid: str, *, direction: str, limit: int) -> dict[str, Any]:
262
+ name = (
263
+ "graph_outgoing_adjacency"
264
+ if direction in {"out", "outgoing"}
265
+ else "graph_incoming_adjacency"
266
+ )
267
+ if direction in {"both"}:
268
+ left = self.neighbors(node_cid, direction="outgoing", limit=limit)
269
+ right = self.neighbors(node_cid, direction="incoming", limit=limit)
270
+ return {
271
+ "mode": "neighbors",
272
+ "node_cid": node_cid,
273
+ "outgoing": left.get("hits"),
274
+ "incoming": right.get("hits"),
275
+ "fetch_trace": self.resolver.trace(),
276
+ }
277
+ loc = self._locator(name)
278
+ pages = []
279
+ for row in self._covering(loc, node_cid):
280
+ table = self.resolver.parquet(str(row["relative_path"]), descriptor=row)
281
+ for rec in table.to_pylist():
282
+ if str(rec.get("node_cid")) != node_cid:
283
+ continue
284
+ pages.append(rec)
285
+ hits = []
286
+ for rec in pages:
287
+ neighbors = rec.get("neighbor_cids") or []
288
+ types = rec.get("edge_types") or []
289
+ methods = rec.get("retrieval_methods") or []
290
+ scores = rec.get("scores") or []
291
+ for i, neighbor in enumerate(neighbors[:limit]):
292
+ hits.append(
293
+ {
294
+ "neighbor_cid": neighbor,
295
+ "edge_type": types[i] if i < len(types) else "",
296
+ "retrieval_method": methods[i] if i < len(methods) else "",
297
+ "score": scores[i] if i < len(scores) else None,
298
+ }
299
+ )
300
+ if len(hits) >= limit:
301
+ break
302
+ return {
303
+ "mode": "neighbors",
304
+ "node_cid": node_cid,
305
+ "direction": direction,
306
+ "hits": hits[:limit],
307
+ "fetch_trace": self.resolver.trace(),
308
+ }
309
+
310
+ def walk(self, node_cid: str, *, max_depth: int, max_nodes: int, direction: str) -> dict[str, Any]:
311
+ seen = {node_cid}
312
+ frontier = [node_cid]
313
+ edges = []
314
+ depth = 0
315
+ while frontier and depth < max_depth and len(seen) < max_nodes:
316
+ nxt = []
317
+ for node in frontier:
318
+ page = self.neighbors(node, direction=direction if direction != "both" else "outgoing", limit=32)
319
+ for hit in page.get("hits") or []:
320
+ dst = str(hit.get("neighbor_cid") or "")
321
+ if not dst or dst in seen:
322
+ continue
323
+ seen.add(dst)
324
+ edges.append({"src": node, **hit})
325
+ nxt.append(dst)
326
+ if len(seen) >= max_nodes:
327
+ break
328
+ frontier = nxt
329
+ depth += 1
330
+ return {
331
+ "mode": "walk",
332
+ "seed": node_cid,
333
+ "nodes": sorted(seen),
334
+ "edges": edges,
335
+ "depth": depth,
336
+ "fetch_trace": self.resolver.trace(),
337
+ }
338
+
339
+
340
+ def _load_query_vector(text: str, model_name: str) -> list[float]:
341
+ from sentence_transformers import SentenceTransformer
342
+
343
+ model = SentenceTransformer(model_name)
344
+ vector = model.encode([text], normalize_embeddings=True)[0]
345
+ return [float(value) for value in vector]
346
+
347
+
348
+ def main(argv: Sequence[str] | None = None) -> int:
349
+ parser = argparse.ArgumentParser(description=__doc__)
350
+ parser.add_argument("--repo-id", default="")
351
+ parser.add_argument("--revision", default="")
352
+ parser.add_argument("--local-root", default="")
353
+ parser.add_argument("--manifest", default=DEFAULT_MANIFEST)
354
+ parser.add_argument("--cache-dir", default=str(DEFAULT_CACHE))
355
+ parser.add_argument("--json", action="store_true")
356
+ sub = parser.add_subparsers(dest="mode", required=True)
357
+ bm25 = sub.add_parser("bm25")
358
+ bm25.add_argument("query")
359
+ bm25.add_argument("--top-k", type=int, default=10)
360
+ vec = sub.add_parser("vector")
361
+ vec.add_argument("query")
362
+ vec.add_argument("--top-k", type=int, default=10)
363
+ vec.add_argument("--model", default="")
364
+ neigh = sub.add_parser("neighbors")
365
+ neigh.add_argument("node_cid")
366
+ neigh.add_argument("--direction", default="both")
367
+ neigh.add_argument("--limit", type=int, default=25)
368
+ walk = sub.add_parser("walk")
369
+ walk.add_argument("node_cid")
370
+ walk.add_argument("--direction", default="outgoing")
371
+ walk.add_argument("--max-depth", type=int, default=2)
372
+ walk.add_argument("--max-nodes", type=int, default=100)
373
+ args = parser.parse_args(argv)
374
+ local = Path(args.local_root).expanduser() if args.local_root else None
375
+ if local is None and not args.repo_id:
376
+ raise SystemExit("pass --local-root or --repo-id")
377
+ if args.repo_id and not args.revision:
378
+ raise SystemExit("remote queries require an immutable --revision pin")
379
+ resolver = ArtifactResolver(
380
+ repo_id=args.repo_id,
381
+ revision=args.revision,
382
+ token=os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN"),
383
+ cache_dir=Path(args.cache_dir),
384
+ local_root=local,
385
+ )
386
+ manifest = resolver.json(args.manifest)
387
+ client = ThinClient(resolver, manifest)
388
+ if args.mode == "bm25":
389
+ result = client.bm25(args.query, top_k=max(1, args.top_k))
390
+ elif args.mode == "neighbors":
391
+ result = client.neighbors(args.node_cid, direction=args.direction, limit=max(1, args.limit))
392
+ elif args.mode == "walk":
393
+ result = client.walk(
394
+ args.node_cid,
395
+ max_depth=max(1, args.max_depth),
396
+ max_nodes=max(1, args.max_nodes),
397
+ direction=args.direction,
398
+ )
399
+ else:
400
+ raise SystemExit("vector search in the standalone client needs --model; use neighbors/bm25 here")
401
+ print(json.dumps(result, indent=2, sort_keys=True))
402
+ return 0
403
+
404
+
405
+ if __name__ == "__main__":
406
+ raise SystemExit(main())
skill/query-hf-graphrag/SKILL.md ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ name: query-hf-graphrag
3
+ description: Query the CID-keyed ipfs_saudiarabia_laws_ir GraphRAG release on Hugging Face with bounded BM25, centroid-routed vectors, adjacency neighbors, and graph walks. Use when an agent must retrieve lexical, semantic, or graph context without downloading the full corpus.
4
+ ---
5
+
6
+ # Query ipfs_saudiarabia_laws_ir on Hugging Face
7
+
8
+ Use the bundled search script. It fetches only the manifest, compact locators,
9
+ matching posting/vector/adjacency shards, and corpus rows for final hits.
10
+
11
+ Repository: `justicedao/ipfs_saudiarabia_laws_ir`. Primary key is `entry_cid`. Integer `document_index`
12
+ is a compact pointer, not an identity.
13
+
14
+ Research snapshot. Similarity edges cannot establish legal authority.
15
+
16
+ ## Choose retrieval
17
+
18
+ - `bm25` for citations, docket numbers, quoted terms, and exact names.
19
+ - `vector` for paraphrases and topical similarity.
20
+ - `neighbors` / `walk` after you have a `node_cid`.
21
+ - Merge BM25 and vector hits on `entry_cid`. Similarity edges (`BM25_NEIGHBOR_OF`, `EMBEDDING_NEIGHBOR_OF`, `contains_term`) are retrieval proposals only.
22
+
23
+ ## BM25
24
+
25
+ ```bash
26
+ python scripts/query_hf_graphrag.py \
27
+ --repo-id justicedao/ipfs_saudiarabia_laws_ir \
28
+ --revision <pinned-commit> \
29
+ bm25 "clean air act section 111" --top-k 10
30
+ ```
31
+
32
+ Local checkout:
33
+
34
+ ```bash
35
+ python scripts/query_hf_graphrag.py --local-root . bm25 "clean air act section 111"
36
+ ```
37
+
38
+ Install `pyarrow` and `huggingface_hub`. Set `HF_TOKEN` for private datasets.
39
+ Always pin `--revision` for remote queries; never use `main`.
40
+
41
+ ## Neighbors and walks
42
+
43
+ ```bash
44
+ python scripts/query_hf_graphrag.py --local-root . neighbors <node-cid> --direction both --limit 25
45
+ python scripts/query_hf_graphrag.py --local-root . walk <node-cid> --max-depth 2 --max-nodes 100
46
+ ```
47
+
48
+ Inspect `fetch_trace`. A budget stop is a partial walk, not proof that no
49
+ further path exists. Treat hits as `context_only`.
50
+
51
+ Read [references/schema.md](references/schema.md) for locator and posting
52
+ contracts.
skill/query-hf-graphrag/agents/openai.yaml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ interface:
2
+ display_name: "Query ipfs_saudiarabia_laws_ir"
3
+ short_description: "Search the remote GraphRAG release"
4
+ default_prompt: "Use $query-hf-graphrag to search this Hugging Face GraphRAG release with BM25, vectors, or a bounded graph walk."
skill/query-hf-graphrag/references/schema.md ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # GraphRAG remote release schema
2
+
3
+ `manifest.json` declares `primary_key` (`entry_cid`), BM25 constants, vector
4
+ layout, and compact index descriptors. Verify `sha256` / `cid` before parsing
5
+ a shard.
6
+
7
+ ## Identity
8
+
9
+ - `entry_cid`: CIDv1 primary identity.
10
+ - `document_index`: dense `0..N-1` pointer used only inside postings.
11
+ - Data shards are Zstandard Parquet with at most 4,096 rows.
12
+
13
+ ## BM25
14
+
15
+ `indexes/bm25_keyword_shards.parquet` maps inclusive `first_key`/`last_key`
16
+ term ranges to posting shards. Nested posting rows contain `term` plus aligned
17
+ `document_indices`, `document_lengths`, `title_frequencies`, `body_frequencies`,
18
+ and `idf`. Posting shards must be globally sorted by term with disjoint
19
+ ranges; a term never spans two shards. In-memory cells: `write_term_sorted_posting_shards`.
20
+ Already-dumped shards (any consumer): `pack_range_routed_family` at build time
21
+ or `repair_graphrag_range_routing` on a release root. Both use the same
22
+ resource-aware process pool. Exploded `(term, legal_id, tf)` shards remain readable.
23
+
24
+ ## Vectors
25
+
26
+ `indexes/vector_chunks.parquet` maps centroid groups to at most two physical
27
+ shards of 4,096 rows. Probe a few centroids, then exact-score inside those
28
+ shards.
29
+
30
+ ## Graph
31
+
32
+ `indexes/graph_outgoing_adjacency.parquet` and
33
+ `indexes/graph_incoming_adjacency.parquet` map `node_cid` ranges to paged
34
+ adjacency. Each page holds at most 4,096 pointers. Similarity neighbors cannot
35
+ establish legal authority.
skill/query-hf-graphrag/scripts/query_hf_graphrag.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ from pathlib import Path
3
+ import runpy
4
+ ROOT = Path(__file__).resolve().parents[3]
5
+ for candidate in (
6
+ ROOT / "scripts" / "query_hf_graphrag.py",
7
+ ROOT / "scripts" / "query_hf_graphrag.py",
8
+ ):
9
+ if candidate.is_file():
10
+ runpy.run_path(str(candidate), run_name="__main__")
11
+ break
12
+ else:
13
+ raise SystemExit("GraphRAG query client is missing from this release")