Datasets:
Add files using upload-large-folder tool
Browse files- data/bm25/documents/part-000000.parquet +2 -2
- data/corpus/part-000001.parquet +2 -2
- indexes/bm25_document_chunks.parquet +2 -2
- indexes/bm25_keyword_shards.parquet +2 -2
- indexes/corpus_chunks.parquet +2 -2
- indexes/graph_edge_chunks.parquet +2 -2
- indexes/graph_incoming_adjacency.parquet +2 -2
- indexes/graph_node_chunks.parquet +2 -2
- indexes/graph_outgoing_adjacency.parquet +2 -2
- indexes/vector_chunks.parquet +2 -2
- manifest.json +304 -191
- scripts/query_hf_graphrag.py +406 -0
- skill/query-hf-graphrag/SKILL.md +52 -0
- skill/query-hf-graphrag/agents/openai.yaml +4 -0
- skill/query-hf-graphrag/references/schema.md +35 -0
- skill/query-hf-graphrag/scripts/query_hf_graphrag.py +13 -0
data/bm25/documents/part-000000.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:77dfbd11a77a6cbe0596f45db41365b5e8269c3c536d489694f0504f6c22b90b
|
| 3 |
+
size 321405
|
data/corpus/part-000001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e0998691e5c8e9e93a771cd67c9dfa50f44ce7bf5698ee57516743d2a549c381
|
| 3 |
+
size 187293
|
indexes/bm25_document_chunks.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1056f11fb8d579c2a3fb9339d8a93eb475e103410a3475209adce4e182b5b7bf
|
| 3 |
+
size 5194
|
indexes/bm25_keyword_shards.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5f5a28a730d380b6d0158b2439b4c5a1e59946c1578113aed52a0f0a8ded6373
|
| 3 |
+
size 5255
|
indexes/corpus_chunks.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ca1185ce7ea4756b3a164fceccf4881667e52de914e274db7cab0687b6a9399a
|
| 3 |
+
size 5108
|
indexes/graph_edge_chunks.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:938dba1f5f47192e0e78f00cc0f53b4cd39c60c2e846d66edb730e057d7b3bc2
|
| 3 |
+
size 6669
|
indexes/graph_incoming_adjacency.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a24b9f00eae42ae42acac8b990041d335f1588c142d1fa0ade0f1af1a8e39ee8
|
| 3 |
+
size 5042
|
indexes/graph_node_chunks.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f2c33e53fa66ec3a9dcc46fece52993bfaaab381e65984b6da0c82ee2fd76ab2
|
| 3 |
+
size 5156
|
indexes/graph_outgoing_adjacency.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:61d79a563b45f571a0ad770f2619993b39bbe9fcd57ed52cec676829758b648b
|
| 3 |
+
size 5295
|
indexes/vector_chunks.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9fb000629434bb3240e9c8e6cc66476af6db2cf4d9e2af024fb533e803eb032c
|
| 3 |
+
size 5116
|
manifest.json
CHANGED
|
@@ -1,59 +1,78 @@
|
|
| 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_pakistan_laws",
|
| 7 |
-
"dataset_repo_id": "justicedao/ipfs_pakistan_laws_ir",
|
| 8 |
-
"dataset_revision": "1455aac2978239f7047f06cf5755b217b315b158",
|
| 9 |
-
"country": {
|
| 10 |
-
"slug": "pakistan",
|
| 11 |
-
"repo": "endomorphosis/ipfs_pakistan_laws",
|
| 12 |
-
"name": "Pakistan",
|
| 13 |
-
"indexable": true
|
| 14 |
-
},
|
| 15 |
-
"disclaimer": "Research snapshot. Not legal advice. The official gazette / authentic source prevails.",
|
| 16 |
"bm25": {
|
| 17 |
-
"
|
| 18 |
"b": 0.75,
|
| 19 |
-
"title_weight": 5.0,
|
| 20 |
"body_weight": 1.0,
|
| 21 |
-
"
|
| 22 |
-
"tokenizer": "fts5-unicode61-remove-diacritics-2-python/v1",
|
| 23 |
"max_query_terms": 64,
|
| 24 |
"posting_rows_per_record": 4096,
|
| 25 |
-
"terms_per_shard": 4096
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
},
|
| 27 |
"counts": {
|
| 28 |
"bm25_document_chunks": 2,
|
| 29 |
"bm25_documents": 4189,
|
| 30 |
"bm25_keyword_shards": 7,
|
| 31 |
"bm25_posting_rows": 28374,
|
|
|
|
| 32 |
"bm25_postings": 897615,
|
| 33 |
"bm25_terms": 28374,
|
| 34 |
"corpus_chunks": 2,
|
| 35 |
"corpus_rows": 4189,
|
|
|
|
| 36 |
"graph_edge_chunks": 10,
|
| 37 |
"graph_edges": 40442,
|
| 38 |
"graph_incoming_adjacency_edges": 40442,
|
| 39 |
"graph_incoming_adjacency_rows": 3733,
|
| 40 |
"graph_incoming_adjacency_shards": 1,
|
| 41 |
"graph_node_chunks": 2,
|
|
|
|
| 42 |
"graph_nodes": 5171,
|
| 43 |
"graph_outgoing_adjacency_edges": 40442,
|
| 44 |
"graph_outgoing_adjacency_rows": 4189,
|
| 45 |
"graph_outgoing_adjacency_shards": 2,
|
| 46 |
-
"
|
| 47 |
-
"vector_rows": 4189,
|
| 48 |
"n_laws": 0,
|
| 49 |
-
"
|
| 50 |
-
|
| 51 |
-
"parquet": {
|
| 52 |
-
"compression": "zstd",
|
| 53 |
-
"compression_level": 6,
|
| 54 |
-
"max_rows_per_file": 4096,
|
| 55 |
-
"row_group_size": 4096
|
| 56 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
"graph": {
|
| 58 |
"adjacency_pointers_per_row": 4096,
|
| 59 |
"adjacency_pointers_per_shard": 8192,
|
|
@@ -61,8 +80,6 @@
|
|
| 61 |
"incoming",
|
| 62 |
"outgoing"
|
| 63 |
],
|
| 64 |
-
"max_remote_walk_depth": 8,
|
| 65 |
-
"ordering": "score_desc_nulls_last",
|
| 66 |
"edge_types": [
|
| 67 |
"ARTICLE_OF",
|
| 68 |
"BM25_NEIGHBOR_OF",
|
|
@@ -72,94 +89,221 @@
|
|
| 72 |
"HAS_SOURCE",
|
| 73 |
"HAS_STATUS",
|
| 74 |
"IDENTIFIED_BY"
|
| 75 |
-
]
|
|
|
|
|
|
|
| 76 |
},
|
| 77 |
-
"
|
| 78 |
-
"
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
"
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
},
|
| 93 |
-
"canonical_fields": [
|
| 94 |
-
"entry_cid",
|
| 95 |
-
"law_cid",
|
| 96 |
-
"record_type",
|
| 97 |
-
"jurisdiction",
|
| 98 |
-
"language",
|
| 99 |
-
"instrument_id",
|
| 100 |
-
"instrument_title",
|
| 101 |
-
"article_number",
|
| 102 |
-
"article_title",
|
| 103 |
-
"title",
|
| 104 |
-
"body",
|
| 105 |
-
"source_url",
|
| 106 |
-
"snapshot_date",
|
| 107 |
-
"coverage",
|
| 108 |
-
"license",
|
| 109 |
-
"collector",
|
| 110 |
-
"source_dataset",
|
| 111 |
-
"source_revision"
|
| 112 |
-
],
|
| 113 |
"input_sha256": {
|
| 114 |
-
"
|
| 115 |
-
"
|
| 116 |
},
|
|
|
|
| 117 |
"model_id": "thenlper/gte-small",
|
| 118 |
-
"cid": {
|
| 119 |
-
"codec": "raw",
|
| 120 |
-
"hash": "sha2-256",
|
| 121 |
-
"multibase": "base32",
|
| 122 |
-
"payload": "json.dumps(obj, sort_keys=True, ensure_ascii=False, separators=(',', ':')).encode('utf-8')"
|
| 123 |
-
},
|
| 124 |
"normalization": {
|
| 125 |
-
"source_dataset": "endomorphosis/ipfs_pakistan_laws",
|
| 126 |
-
"source_revision": "1455aac2978239f7047f06cf5755b217b315b158",
|
| 127 |
-
"laws_sha256": "3e78a111290f997799a167ea90495ba28ea8a429eb4fdf8d46a30066f017c8d0",
|
| 128 |
-
"articles_sha256": "c64c476a788b97fe949e5cb0a583753c9cb12e45b68bbf553a86ab5a4086113f",
|
| 129 |
-
"n_laws_in": 958,
|
| 130 |
-
"n_articles_in": 4189,
|
| 131 |
-
"unit": "article",
|
| 132 |
"article_law_coverage": 4.372651356993737,
|
| 133 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
"drops": {
|
| 135 |
-
"empty_body": 0,
|
| 136 |
-
"missing_instrument": 0,
|
| 137 |
"duplicate_cid": 0,
|
| 138 |
-
"duplicate_source_kept_first": 0
|
|
|
|
|
|
|
| 139 |
},
|
| 140 |
-
"
|
| 141 |
-
"
|
| 142 |
-
"missing_instrument": [],
|
| 143 |
-
"duplicate_cid": []
|
| 144 |
},
|
| 145 |
"language_breakdown": {
|
| 146 |
"en": 4189
|
| 147 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
"quality_flags": {
|
| 149 |
-
"articles_table_empty": false,
|
| 150 |
-
"sparse_article_fallback": false,
|
| 151 |
-
"article_law_coverage": 4.372651356993737,
|
| 152 |
"all_source_article_counts_zero": false,
|
| 153 |
"article_extraction_status_counts": {
|
| 154 |
-
"
|
| 155 |
-
"
|
| 156 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
"missing_date": false,
|
| 158 |
"missing_date_issued": true,
|
| 159 |
-
"eli_present": false,
|
| 160 |
"never_invented_legal_text": true,
|
| 161 |
-
"
|
| 162 |
-
|
|
|
|
|
|
|
| 163 |
},
|
| 164 |
"schema_surprises": [
|
| 165 |
"laws.article_count dtype=int32",
|
|
@@ -167,107 +311,66 @@
|
|
| 167 |
"laws.eli non-null=0/958",
|
| 168 |
"laws.language values=['en']"
|
| 169 |
],
|
| 170 |
-
"n_out": 4189,
|
| 171 |
-
"never_invented_legal_text": true,
|
| 172 |
-
"n_before_dedupe": 4189,
|
| 173 |
-
"n_dropped_total": 0,
|
| 174 |
-
"record_type_breakdown": {
|
| 175 |
-
"article": 4189
|
| 176 |
-
},
|
| 177 |
-
"jurisdiction_breakdown": {
|
| 178 |
-
"PK": 4189
|
| 179 |
-
},
|
| 180 |
"snapshot_dates": [
|
| 181 |
"2026-09-03"
|
| 182 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
},
|
|
|
|
| 184 |
"schema_mapping": {
|
| 185 |
-
"laws": {
|
| 186 |
-
"id": "instrument_id",
|
| 187 |
-
"title": "instrument_title",
|
| 188 |
-
"text": "body",
|
| 189 |
-
"article_count_dtype_source": "int32"
|
| 190 |
-
},
|
| 191 |
"articles": {
|
| 192 |
"id": "source_id / article identity",
|
| 193 |
"law_id": "instrument_id",
|
| 194 |
-
"
|
| 195 |
-
"
|
| 196 |
},
|
| 197 |
-
"
|
| 198 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
"id",
|
|
|
|
| 200 |
"title",
|
| 201 |
"text"
|
| 202 |
],
|
| 203 |
-
"
|
| 204 |
"id",
|
| 205 |
-
"law_id",
|
| 206 |
"title",
|
| 207 |
"text"
|
| 208 |
],
|
| 209 |
-
"
|
| 210 |
-
"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."
|
| 211 |
-
},
|
| 212 |
-
"indexes": {
|
| 213 |
-
"bm25_document_chunks": {
|
| 214 |
-
"cid": "bafkreibweooqqhvormikdxj5sobo5rsm7xpr44npkd44updtcqign25nka",
|
| 215 |
-
"sha256": "36239d081eae8b10a1dd3d9382eec64cfddf1e71af50f9ca3c73141066ebad50",
|
| 216 |
-
"size_bytes": 9041,
|
| 217 |
-
"relative_path": "indexes/bm25_document_chunks.parquet"
|
| 218 |
-
},
|
| 219 |
-
"bm25_keyword_shards": {
|
| 220 |
-
"cid": "bafkreifdycukwlbfr5qguzvydycne5lsdel65pzk6nnxakb4xev4odte6i",
|
| 221 |
-
"sha256": "a3c0a8ab2c258f606a66b81e04d275721917eebf2af35b70283cb92bc70e64f2",
|
| 222 |
-
"size_bytes": 10862,
|
| 223 |
-
"relative_path": "indexes/bm25_keyword_shards.parquet"
|
| 224 |
-
},
|
| 225 |
-
"corpus_chunks": {
|
| 226 |
-
"cid": "bafkreif5e77tq4ssvc37s3obghhyx5hanjfl7ckn4yn7hplmx3rzhukcyu",
|
| 227 |
-
"sha256": "bd27ff387252a8b7f96dc131cf8bf4e06a4abf894de61bf3bd6cbee393d142c5",
|
| 228 |
-
"size_bytes": 8959,
|
| 229 |
-
"relative_path": "indexes/corpus_chunks.parquet"
|
| 230 |
-
},
|
| 231 |
-
"graph_edge_chunks": {
|
| 232 |
-
"cid": "bafkreialkroh3qbkmczcmffhxf6s5n7rmbpcc7w4ojy26wnejtet6hudmi",
|
| 233 |
-
"sha256": "0b545c7dc02a60b22614a7b97d2eb7f1605e217edc7271af59a44cc93f1e8362",
|
| 234 |
-
"size_bytes": 10236,
|
| 235 |
-
"relative_path": "indexes/graph_edge_chunks.parquet"
|
| 236 |
-
},
|
| 237 |
-
"graph_incoming_adjacency": {
|
| 238 |
-
"cid": "bafkreig4sordi3o2wm5x33j4oasim6mqbeyomsd5snusqffdiqjurk3jzu",
|
| 239 |
-
"sha256": "dc93a2346ddab33b7ded3c70248679900930e6487d93692814a3441348ab69cd",
|
| 240 |
-
"size_bytes": 11958,
|
| 241 |
-
"relative_path": "indexes/graph_incoming_adjacency.parquet"
|
| 242 |
-
},
|
| 243 |
-
"graph_node_chunks": {
|
| 244 |
-
"cid": "bafkreiebzxmpmol3wdpn5pnfxpn4p24nohbgznzxqhagkpkzt4g3w2mncu",
|
| 245 |
-
"sha256": "81cdd8f6397bb0dedebda5bbdbc7eb8d71c26cb73781c0653d599f0dbb698d15",
|
| 246 |
-
"size_bytes": 8991,
|
| 247 |
-
"relative_path": "indexes/graph_node_chunks.parquet"
|
| 248 |
-
},
|
| 249 |
-
"graph_outgoing_adjacency": {
|
| 250 |
-
"cid": "bafkreihldpn2sp4z7wmlbvnskq3miocwaagq5xpfevz5dkdvileeiq22rq",
|
| 251 |
-
"sha256": "eb1bdba93f99fd98b0d5b25436c43856000d0edde52573d1a87542c844435a8c",
|
| 252 |
-
"size_bytes": 12182,
|
| 253 |
-
"relative_path": "indexes/graph_outgoing_adjacency.parquet"
|
| 254 |
-
},
|
| 255 |
-
"vector_chunks": {
|
| 256 |
-
"cid": "bafkreihuoy7brzfhcbunx47dtnl3oy442lknpjyqixg45krjrrnt6gi6u4",
|
| 257 |
-
"sha256": "f4763e18e4a71068dbf3e39b57b7639cd2d4d7a71045cdceaa298c5b3f191ea7",
|
| 258 |
-
"size_bytes": 22883,
|
| 259 |
-
"relative_path": "indexes/vector_chunks.parquet"
|
| 260 |
-
}
|
| 261 |
},
|
|
|
|
| 262 |
"source": {
|
| 263 |
-
"
|
| 264 |
-
"
|
| 265 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
"articles_path": "/workspace/country-laws-ir/cache/hf/datasets--endomorphosis--ipfs_pakistan_laws/snapshots/1455aac2978239f7047f06cf5755b217b315b158/data/articles.parquet",
|
| 267 |
-
"laws_sha256": "3e78a111290f997799a167ea90495ba28ea8a429eb4fdf8d46a30066f017c8d0",
|
| 268 |
"articles_sha256": "c64c476a788b97fe949e5cb0a583753c9cb12e45b68bbf553a86ab5a4086113f",
|
| 269 |
-
"n_laws_source": 958,
|
| 270 |
-
"n_articles_source": 4189,
|
| 271 |
"laws_columns": [
|
| 272 |
"id",
|
| 273 |
"title",
|
|
@@ -289,23 +392,33 @@
|
|
| 289 |
"json_path",
|
| 290 |
"metadata_json"
|
| 291 |
],
|
| 292 |
-
"
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
"text",
|
| 297 |
-
"source_url",
|
| 298 |
-
"document_number",
|
| 299 |
-
"article_number",
|
| 300 |
-
"record_type",
|
| 301 |
-
"metadata_json"
|
| 302 |
-
],
|
| 303 |
-
"article_count_dtype": "int32",
|
| 304 |
"schema_surprises": [
|
| 305 |
"laws.article_count dtype=int32",
|
| 306 |
"laws.date_issued is entirely null",
|
| 307 |
"laws.eli non-null=0/958",
|
| 308 |
"laws.language values=['en']"
|
| 309 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
}
|
| 311 |
}
|
|
|
|
| 1 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
"bm25": {
|
| 3 |
+
"average_document_length": 1026.2346622105515,
|
| 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 |
+
"name": "Pakistan",
|
| 42 |
+
"repo": "endomorphosis/ipfs_pakistan_laws",
|
| 43 |
+
"slug": "pakistan"
|
| 44 |
},
|
| 45 |
"counts": {
|
| 46 |
"bm25_document_chunks": 2,
|
| 47 |
"bm25_documents": 4189,
|
| 48 |
"bm25_keyword_shards": 7,
|
| 49 |
"bm25_posting_rows": 28374,
|
| 50 |
+
"bm25_posting_shards": 7,
|
| 51 |
"bm25_postings": 897615,
|
| 52 |
"bm25_terms": 28374,
|
| 53 |
"corpus_chunks": 2,
|
| 54 |
"corpus_rows": 4189,
|
| 55 |
+
"corpus_shards": 2,
|
| 56 |
"graph_edge_chunks": 10,
|
| 57 |
"graph_edges": 40442,
|
| 58 |
"graph_incoming_adjacency_edges": 40442,
|
| 59 |
"graph_incoming_adjacency_rows": 3733,
|
| 60 |
"graph_incoming_adjacency_shards": 1,
|
| 61 |
"graph_node_chunks": 2,
|
| 62 |
+
"graph_node_shards": 2,
|
| 63 |
"graph_nodes": 5171,
|
| 64 |
"graph_outgoing_adjacency_edges": 40442,
|
| 65 |
"graph_outgoing_adjacency_rows": 4189,
|
| 66 |
"graph_outgoing_adjacency_shards": 2,
|
| 67 |
+
"n_articles": 4189,
|
|
|
|
| 68 |
"n_laws": 0,
|
| 69 |
+
"vector_chunks": 2,
|
| 70 |
+
"vector_rows": 4189
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
},
|
| 72 |
+
"dataset_id": "endomorphosis/ipfs_pakistan_laws",
|
| 73 |
+
"dataset_repo_id": "justicedao/ipfs_pakistan_laws_ir",
|
| 74 |
+
"dataset_revision": "1455aac2978239f7047f06cf5755b217b315b158",
|
| 75 |
+
"disclaimer": "Research snapshot. Not legal advice. The official gazette / authentic source prevails.",
|
| 76 |
"graph": {
|
| 77 |
"adjacency_pointers_per_row": 4096,
|
| 78 |
"adjacency_pointers_per_shard": 8192,
|
|
|
|
| 80 |
"incoming",
|
| 81 |
"outgoing"
|
| 82 |
],
|
|
|
|
|
|
|
| 83 |
"edge_types": [
|
| 84 |
"ARTICLE_OF",
|
| 85 |
"BM25_NEIGHBOR_OF",
|
|
|
|
| 89 |
"HAS_SOURCE",
|
| 90 |
"HAS_STATUS",
|
| 91 |
"IDENTIFIED_BY"
|
| 92 |
+
],
|
| 93 |
+
"max_remote_walk_depth": 8,
|
| 94 |
+
"ordering": "score_desc_nulls_last"
|
| 95 |
},
|
| 96 |
+
"indexes": {
|
| 97 |
+
"bm25_document_chunks": {
|
| 98 |
+
"cid": "bafkreibweooqqhvormikdxj5sobo5rsm7xpr44npkd44updtcqign25nka",
|
| 99 |
+
"content_cid": "bafkreiaqk3yr7ogvphbkh64thhmkspvuoxqqgqikgr2sbgw44tqyfnnxx4",
|
| 100 |
+
"family": "routing_index",
|
| 101 |
+
"media_type": "application/vnd.apache.parquet",
|
| 102 |
+
"relative_path": "indexes/bm25_document_chunks.parquet",
|
| 103 |
+
"row_count": 2,
|
| 104 |
+
"schema_id": "hf-graphrag-compact-index/v1",
|
| 105 |
+
"sha256": "1056f11fb8d579c2a3fb9339d8a93eb475e103410a3475209adce4e182b5b7bf",
|
| 106 |
+
"size_bytes": 5194
|
| 107 |
+
},
|
| 108 |
+
"bm25_documents": {
|
| 109 |
+
"content_cid": "bafkreiaqk3yr7ogvphbkh64thhmkspvuoxqqgqikgr2sbgw44tqyfnnxx4",
|
| 110 |
+
"family": "routing_index",
|
| 111 |
+
"media_type": "application/vnd.apache.parquet",
|
| 112 |
+
"relative_path": "indexes/bm25_document_chunks.parquet",
|
| 113 |
+
"row_count": 2,
|
| 114 |
+
"schema_id": "hf-graphrag-compact-index/v1",
|
| 115 |
+
"sha256": "1056f11fb8d579c2a3fb9339d8a93eb475e103410a3475209adce4e182b5b7bf",
|
| 116 |
+
"size_bytes": 5194
|
| 117 |
+
},
|
| 118 |
+
"bm25_keyword_index": {
|
| 119 |
+
"content_cid": "bafkreic7liukomgtqc3nafmleq43jrnb4wmunqkxqej25vjkb4fi33ldom",
|
| 120 |
+
"family": "routing_index",
|
| 121 |
+
"media_type": "application/vnd.apache.parquet",
|
| 122 |
+
"relative_path": "indexes/bm25_keyword_shards.parquet",
|
| 123 |
+
"row_count": 7,
|
| 124 |
+
"schema_id": "hf-graphrag-compact-index/v1",
|
| 125 |
+
"sha256": "5f5a28a730d380b6d0158b2439b4c5a1e59946c1578113aed52a0f0a8ded6373",
|
| 126 |
+
"size_bytes": 5255
|
| 127 |
+
},
|
| 128 |
+
"bm25_keyword_shards": {
|
| 129 |
+
"cid": "bafkreifdycukwlbfr5qguzvydycne5lsdel65pzk6nnxakb4xev4odte6i",
|
| 130 |
+
"content_cid": "bafkreic7liukomgtqc3nafmleq43jrnb4wmunqkxqej25vjkb4fi33ldom",
|
| 131 |
+
"family": "routing_index",
|
| 132 |
+
"media_type": "application/vnd.apache.parquet",
|
| 133 |
+
"relative_path": "indexes/bm25_keyword_shards.parquet",
|
| 134 |
+
"row_count": 7,
|
| 135 |
+
"schema_id": "hf-graphrag-compact-index/v1",
|
| 136 |
+
"sha256": "5f5a28a730d380b6d0158b2439b4c5a1e59946c1578113aed52a0f0a8ded6373",
|
| 137 |
+
"size_bytes": 5255
|
| 138 |
+
},
|
| 139 |
+
"bm25_postings": {
|
| 140 |
+
"content_cid": "bafkreic7liukomgtqc3nafmleq43jrnb4wmunqkxqej25vjkb4fi33ldom",
|
| 141 |
+
"family": "routing_index",
|
| 142 |
+
"media_type": "application/vnd.apache.parquet",
|
| 143 |
+
"relative_path": "indexes/bm25_keyword_shards.parquet",
|
| 144 |
+
"row_count": 7,
|
| 145 |
+
"schema_id": "hf-graphrag-compact-index/v1",
|
| 146 |
+
"sha256": "5f5a28a730d380b6d0158b2439b4c5a1e59946c1578113aed52a0f0a8ded6373",
|
| 147 |
+
"size_bytes": 5255
|
| 148 |
+
},
|
| 149 |
+
"corpus": {
|
| 150 |
+
"content_cid": "bafkreigkcgc447veovvtufspz3gpjcawm7ss32iu4j2nw7fla2d3nkjzti",
|
| 151 |
+
"family": "routing_index",
|
| 152 |
+
"media_type": "application/vnd.apache.parquet",
|
| 153 |
+
"relative_path": "indexes/corpus_chunks.parquet",
|
| 154 |
+
"row_count": 2,
|
| 155 |
+
"schema_id": "hf-graphrag-compact-index/v1",
|
| 156 |
+
"sha256": "ca1185ce7ea4756b3a164fceccf4881667e52de914e274db7cab0687b6a9399a",
|
| 157 |
+
"size_bytes": 5108
|
| 158 |
+
},
|
| 159 |
+
"corpus_chunks": {
|
| 160 |
+
"cid": "bafkreif5e77tq4ssvc37s3obghhyx5hanjfl7ckn4yn7hplmx3rzhukcyu",
|
| 161 |
+
"content_cid": "bafkreigkcgc447veovvtufspz3gpjcawm7ss32iu4j2nw7fla2d3nkjzti",
|
| 162 |
+
"family": "routing_index",
|
| 163 |
+
"media_type": "application/vnd.apache.parquet",
|
| 164 |
+
"relative_path": "indexes/corpus_chunks.parquet",
|
| 165 |
+
"row_count": 2,
|
| 166 |
+
"schema_id": "hf-graphrag-compact-index/v1",
|
| 167 |
+
"sha256": "ca1185ce7ea4756b3a164fceccf4881667e52de914e274db7cab0687b6a9399a",
|
| 168 |
+
"size_bytes": 5108
|
| 169 |
+
},
|
| 170 |
+
"graph_edge_chunks": {
|
| 171 |
+
"cid": "bafkreialkroh3qbkmczcmffhxf6s5n7rmbpcc7w4ojy26wnejtet6hudmi",
|
| 172 |
+
"content_cid": "bafkreietrw5b6x2hdexa46hqbtapko2m2oogbqxii3lg5w3tbycx26z3yi",
|
| 173 |
+
"family": "routing_index",
|
| 174 |
+
"media_type": "application/vnd.apache.parquet",
|
| 175 |
+
"relative_path": "indexes/graph_edge_chunks.parquet",
|
| 176 |
+
"row_count": 10,
|
| 177 |
+
"schema_id": "hf-graphrag-compact-index/v1",
|
| 178 |
+
"sha256": "938dba1f5f47192e0e78f00cc0f53b4cd39c60c2e846d66edb730e057d7b3bc2",
|
| 179 |
+
"size_bytes": 6669
|
| 180 |
+
},
|
| 181 |
+
"graph_edges": {
|
| 182 |
+
"content_cid": "bafkreietrw5b6x2hdexa46hqbtapko2m2oogbqxii3lg5w3tbycx26z3yi",
|
| 183 |
+
"family": "routing_index",
|
| 184 |
+
"media_type": "application/vnd.apache.parquet",
|
| 185 |
+
"relative_path": "indexes/graph_edge_chunks.parquet",
|
| 186 |
+
"row_count": 10,
|
| 187 |
+
"schema_id": "hf-graphrag-compact-index/v1",
|
| 188 |
+
"sha256": "938dba1f5f47192e0e78f00cc0f53b4cd39c60c2e846d66edb730e057d7b3bc2",
|
| 189 |
+
"size_bytes": 6669
|
| 190 |
+
},
|
| 191 |
+
"graph_incoming_adjacency": {
|
| 192 |
+
"cid": "bafkreig4sordi3o2wm5x33j4oasim6mqbeyomsd5snusqffdiqjurk3jzu",
|
| 193 |
+
"content_cid": "bafkreifcjopqb2xeflscvswixgiaihjtl4kyrqkc2h5avxqpdly2ry465a",
|
| 194 |
+
"family": "routing_index",
|
| 195 |
+
"media_type": "application/vnd.apache.parquet",
|
| 196 |
+
"relative_path": "indexes/graph_incoming_adjacency.parquet",
|
| 197 |
+
"row_count": 1,
|
| 198 |
+
"schema_id": "hf-graphrag-compact-index/v1",
|
| 199 |
+
"sha256": "a24b9f00eae42ae42acac8b990041d335f1588c142d1fa0ade0f1af1a8e39ee8",
|
| 200 |
+
"size_bytes": 5042
|
| 201 |
+
},
|
| 202 |
+
"graph_node_chunks": {
|
| 203 |
+
"cid": "bafkreiebzxmpmol3wdpn5pnfxpn4p24nohbgznzxqhagkpkzt4g3w2mncu",
|
| 204 |
+
"content_cid": "bafkreihsym7fh6tg5q5j3tcg73hffgj37kvlhapglgclnwqmqlxc7v3kwi",
|
| 205 |
+
"family": "routing_index",
|
| 206 |
+
"media_type": "application/vnd.apache.parquet",
|
| 207 |
+
"relative_path": "indexes/graph_node_chunks.parquet",
|
| 208 |
+
"row_count": 2,
|
| 209 |
+
"schema_id": "hf-graphrag-compact-index/v1",
|
| 210 |
+
"sha256": "f2c33e53fa66ec3a9dcc46fece52993bfaaab381e65984b6da0c82ee2fd76ab2",
|
| 211 |
+
"size_bytes": 5156
|
| 212 |
+
},
|
| 213 |
+
"graph_nodes": {
|
| 214 |
+
"content_cid": "bafkreihsym7fh6tg5q5j3tcg73hffgj37kvlhapglgclnwqmqlxc7v3kwi",
|
| 215 |
+
"family": "routing_index",
|
| 216 |
+
"media_type": "application/vnd.apache.parquet",
|
| 217 |
+
"relative_path": "indexes/graph_node_chunks.parquet",
|
| 218 |
+
"row_count": 2,
|
| 219 |
+
"schema_id": "hf-graphrag-compact-index/v1",
|
| 220 |
+
"sha256": "f2c33e53fa66ec3a9dcc46fece52993bfaaab381e65984b6da0c82ee2fd76ab2",
|
| 221 |
+
"size_bytes": 5156
|
| 222 |
+
},
|
| 223 |
+
"graph_outgoing_adjacency": {
|
| 224 |
+
"cid": "bafkreihldpn2sp4z7wmlbvnskq3miocwaagq5xpfevz5dkdvileeiq22rq",
|
| 225 |
+
"content_cid": "bafkreidb26nfmo2f6vy2bllxb4tbtgj3hg56t7gvp3ksz3dhnauxlc3erm",
|
| 226 |
+
"family": "routing_index",
|
| 227 |
+
"media_type": "application/vnd.apache.parquet",
|
| 228 |
+
"relative_path": "indexes/graph_outgoing_adjacency.parquet",
|
| 229 |
+
"row_count": 2,
|
| 230 |
+
"schema_id": "hf-graphrag-compact-index/v1",
|
| 231 |
+
"sha256": "61d79a563b45f571a0ad770f2619993b39bbe9fcd57ed52cec676829758b648b",
|
| 232 |
+
"size_bytes": 5295
|
| 233 |
+
},
|
| 234 |
+
"vector_chunks": {
|
| 235 |
+
"cid": "bafkreihuoy7brzfhcbunx47dtnl3oy442lknpjyqixg45krjrrnt6gi6u4",
|
| 236 |
+
"content_cid": "bafkreie7waagffbuxmzeb2oi43ggmr3k63nsz5gz4kxqet5vgpuah2ydfq",
|
| 237 |
+
"family": "routing_index",
|
| 238 |
+
"media_type": "application/vnd.apache.parquet",
|
| 239 |
+
"relative_path": "indexes/vector_chunks.parquet",
|
| 240 |
+
"row_count": 2,
|
| 241 |
+
"schema_id": "hf-graphrag-compact-index/v1",
|
| 242 |
+
"sha256": "9fb000629434bb3240e9c8e6cc66476af6db2cf4d9e2af024fb533e803eb032c",
|
| 243 |
+
"size_bytes": 5116
|
| 244 |
+
},
|
| 245 |
+
"vectors": {
|
| 246 |
+
"content_cid": "bafkreie7waagffbuxmzeb2oi43ggmr3k63nsz5gz4kxqet5vgpuah2ydfq",
|
| 247 |
+
"family": "routing_index",
|
| 248 |
+
"media_type": "application/vnd.apache.parquet",
|
| 249 |
+
"relative_path": "indexes/vector_chunks.parquet",
|
| 250 |
+
"row_count": 2,
|
| 251 |
+
"schema_id": "hf-graphrag-compact-index/v1",
|
| 252 |
+
"sha256": "9fb000629434bb3240e9c8e6cc66476af6db2cf4d9e2af024fb533e803eb032c",
|
| 253 |
+
"size_bytes": 5116
|
| 254 |
+
}
|
| 255 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
"input_sha256": {
|
| 257 |
+
"articles.parquet": "c64c476a788b97fe949e5cb0a583753c9cb12e45b68bbf553a86ab5a4086113f",
|
| 258 |
+
"laws.parquet": "3e78a111290f997799a167ea90495ba28ea8a429eb4fdf8d46a30066f017c8d0"
|
| 259 |
},
|
| 260 |
+
"layout_family": "skillcenter-huggingface-release/v3",
|
| 261 |
"model_id": "thenlper/gte-small",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
"normalization": {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
"article_law_coverage": 4.372651356993737,
|
| 264 |
+
"articles_sha256": "c64c476a788b97fe949e5cb0a583753c9cb12e45b68bbf553a86ab5a4086113f",
|
| 265 |
+
"drop_samples": {
|
| 266 |
+
"duplicate_cid": [],
|
| 267 |
+
"empty_body": [],
|
| 268 |
+
"missing_instrument": []
|
| 269 |
+
},
|
| 270 |
"drops": {
|
|
|
|
|
|
|
| 271 |
"duplicate_cid": 0,
|
| 272 |
+
"duplicate_source_kept_first": 0,
|
| 273 |
+
"empty_body": 0,
|
| 274 |
+
"missing_instrument": 0
|
| 275 |
},
|
| 276 |
+
"jurisdiction_breakdown": {
|
| 277 |
+
"PK": 4189
|
|
|
|
|
|
|
| 278 |
},
|
| 279 |
"language_breakdown": {
|
| 280 |
"en": 4189
|
| 281 |
},
|
| 282 |
+
"laws_sha256": "3e78a111290f997799a167ea90495ba28ea8a429eb4fdf8d46a30066f017c8d0",
|
| 283 |
+
"n_articles_in": 4189,
|
| 284 |
+
"n_before_dedupe": 4189,
|
| 285 |
+
"n_dropped_total": 0,
|
| 286 |
+
"n_laws_in": 958,
|
| 287 |
+
"n_out": 4189,
|
| 288 |
+
"never_invented_legal_text": true,
|
| 289 |
"quality_flags": {
|
|
|
|
|
|
|
|
|
|
| 290 |
"all_source_article_counts_zero": false,
|
| 291 |
"article_extraction_status_counts": {
|
| 292 |
+
"missing": 632,
|
| 293 |
+
"ok": 326
|
| 294 |
},
|
| 295 |
+
"article_law_coverage": 4.372651356993737,
|
| 296 |
+
"articles_table_empty": false,
|
| 297 |
+
"duplicate_cids_dropped": 0,
|
| 298 |
+
"eli_present": false,
|
| 299 |
+
"empty_bodies_dropped": 0,
|
| 300 |
"missing_date": false,
|
| 301 |
"missing_date_issued": true,
|
|
|
|
| 302 |
"never_invented_legal_text": true,
|
| 303 |
+
"sparse_article_fallback": false
|
| 304 |
+
},
|
| 305 |
+
"record_type_breakdown": {
|
| 306 |
+
"article": 4189
|
| 307 |
},
|
| 308 |
"schema_surprises": [
|
| 309 |
"laws.article_count dtype=int32",
|
|
|
|
| 311 |
"laws.eli non-null=0/958",
|
| 312 |
"laws.language values=['en']"
|
| 313 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
"snapshot_dates": [
|
| 315 |
"2026-09-03"
|
| 316 |
+
],
|
| 317 |
+
"source_dataset": "endomorphosis/ipfs_pakistan_laws",
|
| 318 |
+
"source_revision": "1455aac2978239f7047f06cf5755b217b315b158",
|
| 319 |
+
"sparse_article_fallback": false,
|
| 320 |
+
"unit": "article"
|
| 321 |
+
},
|
| 322 |
+
"packager_version": "0.3.0",
|
| 323 |
+
"parquet": {
|
| 324 |
+
"compression": "zstd",
|
| 325 |
+
"compression_level": 6,
|
| 326 |
+
"max_rows_per_file": 4096,
|
| 327 |
+
"row_group_size": 4096
|
| 328 |
},
|
| 329 |
+
"primary_key": "entry_cid",
|
| 330 |
"schema_mapping": {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
"articles": {
|
| 332 |
"id": "source_id / article identity",
|
| 333 |
"law_id": "instrument_id",
|
| 334 |
+
"text": "body",
|
| 335 |
+
"title": "article_title"
|
| 336 |
},
|
| 337 |
+
"fail_closed": true,
|
| 338 |
+
"laws": {
|
| 339 |
+
"article_count_dtype_source": "int32",
|
| 340 |
+
"id": "instrument_id",
|
| 341 |
+
"text": "body",
|
| 342 |
+
"title": "instrument_title"
|
| 343 |
+
},
|
| 344 |
+
"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.",
|
| 345 |
+
"required_article_columns": [
|
| 346 |
"id",
|
| 347 |
+
"law_id",
|
| 348 |
"title",
|
| 349 |
"text"
|
| 350 |
],
|
| 351 |
+
"required_law_columns": [
|
| 352 |
"id",
|
|
|
|
| 353 |
"title",
|
| 354 |
"text"
|
| 355 |
],
|
| 356 |
+
"unit_policy": "prefer articles; fall back to law-level when articles empty"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
},
|
| 358 |
+
"schema_version": "country-laws-ir-graphrag/v1",
|
| 359 |
"source": {
|
| 360 |
+
"article_count_dtype": "int32",
|
| 361 |
+
"articles_columns": [
|
| 362 |
+
"law_id",
|
| 363 |
+
"id",
|
| 364 |
+
"title",
|
| 365 |
+
"text",
|
| 366 |
+
"source_url",
|
| 367 |
+
"document_number",
|
| 368 |
+
"article_number",
|
| 369 |
+
"record_type",
|
| 370 |
+
"metadata_json"
|
| 371 |
+
],
|
| 372 |
"articles_path": "/workspace/country-laws-ir/cache/hf/datasets--endomorphosis--ipfs_pakistan_laws/snapshots/1455aac2978239f7047f06cf5755b217b315b158/data/articles.parquet",
|
|
|
|
| 373 |
"articles_sha256": "c64c476a788b97fe949e5cb0a583753c9cb12e45b68bbf553a86ab5a4086113f",
|
|
|
|
|
|
|
| 374 |
"laws_columns": [
|
| 375 |
"id",
|
| 376 |
"title",
|
|
|
|
| 392 |
"json_path",
|
| 393 |
"metadata_json"
|
| 394 |
],
|
| 395 |
+
"laws_path": "/workspace/country-laws-ir/cache/hf/datasets--endomorphosis--ipfs_pakistan_laws/snapshots/1455aac2978239f7047f06cf5755b217b315b158/data/laws.parquet",
|
| 396 |
+
"laws_sha256": "3e78a111290f997799a167ea90495ba28ea8a429eb4fdf8d46a30066f017c8d0",
|
| 397 |
+
"n_articles_source": 4189,
|
| 398 |
+
"n_laws_source": 958,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
"schema_surprises": [
|
| 400 |
"laws.article_count dtype=int32",
|
| 401 |
"laws.date_issued is entirely null",
|
| 402 |
"laws.eli non-null=0/958",
|
| 403 |
"laws.language values=['en']"
|
| 404 |
+
],
|
| 405 |
+
"source_dataset": "endomorphosis/ipfs_pakistan_laws",
|
| 406 |
+
"source_revision": "1455aac2978239f7047f06cf5755b217b315b158"
|
| 407 |
+
},
|
| 408 |
+
"vector": {
|
| 409 |
+
"assignment": "recursive_spherical_kmeans",
|
| 410 |
+
"centroid_count": 2,
|
| 411 |
+
"default_probe_centroids": 2,
|
| 412 |
+
"dimension": 384,
|
| 413 |
+
"layout": "semantic_centroid_groups",
|
| 414 |
+
"max_rows_per_centroid": 8192,
|
| 415 |
+
"max_rows_per_chunk": 4096,
|
| 416 |
+
"max_shards_per_centroid": 2,
|
| 417 |
+
"model_name": "thenlper/gte-small",
|
| 418 |
+
"n_vectors": 4189,
|
| 419 |
+
"rows_sorted_by": "cosine_similarity_to_shard_centroid_desc",
|
| 420 |
+
"shard_count": 2,
|
| 421 |
+
"similarity": "cosine",
|
| 422 |
+
"status": "embedded"
|
| 423 |
}
|
| 424 |
}
|
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_pakistan_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_pakistan_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_pakistan_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_pakistan_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_pakistan_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")
|