WindyITS commited on
Commit
0480ac3
·
verified ·
1 Parent(s): bb3ff48

Upload query stack release

Browse files
README.md ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Business Model KG Query Stack
2
+
3
+ This model package contains the deployable local query stack for Business Model KG.
4
+
5
+ It includes:
6
+
7
+ - a DeBERTa-v3-small router classifier
8
+ - calibrated router thresholds
9
+ - an MLX QLoRA planner adapter for `mlx-community/Qwen3-4B-Instruct-2507-4bit`
10
+ - the frozen planner system prompt
11
+ - the runtime bundle manifest
12
+
13
+ The package intentionally excludes optimizer states and intermediate training
14
+ checkpoints. It is the deployable bundle, not the full training workspace.
15
+
16
+ ## Layout
17
+
18
+ ```text
19
+ manifest.json
20
+ router/
21
+ thresholds.json
22
+ model/
23
+ planner/
24
+ system_prompt.txt
25
+ adapter/
26
+ ```
27
+
28
+ ## Base Models
29
+
30
+ Router base model:
31
+
32
+ ```text
33
+ microsoft/deberta-v3-small
34
+ ```
35
+
36
+ Planner base model:
37
+
38
+ ```text
39
+ mlx-community/Qwen3-4B-Instruct-2507-4bit
40
+ ```
41
+
42
+ ## Runtime Role
43
+
44
+ The router chooses whether a user question is local-safe, should fall back to a
45
+ hosted model, or should be refused. When the route is local, the planner emits a
46
+ compact supported query plan that the Python runtime compiles into read-only
47
+ Cypher.
48
+
49
+ This bundle is meant to be consumed by the Business Model KG runtime as
50
+ `runtime_assets/query_stack/current/`.
manifest.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bundle_format_version": 1,
3
+ "published_at": "2026-04-25T09:13:47.641981+00:00",
4
+ "router": {
5
+ "base_model": "microsoft/deberta-v3-small",
6
+ "max_length": 256,
7
+ "model_dir": "router/model",
8
+ "thresholds_path": "router/thresholds.json"
9
+ },
10
+ "planner": {
11
+ "base_model": "mlx-community/Qwen3-4B-Instruct-2507-4bit",
12
+ "max_tokens": 256,
13
+ "adapter_dir": "planner/adapter",
14
+ "system_prompt_path": "planner/system_prompt.txt"
15
+ }
16
+ }
planner/adapter/adapter_config.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "adapter_path": "/Users/giuliosighieri/Desktop/kg-v0/finetuning/artifacts/kg-query-planner-fresh-adapter/planner/adapter",
3
+ "batch_size": 4,
4
+ "data": "/Users/giuliosighieri/Desktop/kg-v0/finetuning/artifacts/kg-query-planner-fresh-adapter/prepared/planner/balanced",
5
+ "fine_tune_type": "lora",
6
+ "grad_accumulation_steps": 4,
7
+ "grad_checkpoint": true,
8
+ "iters": 7110,
9
+ "learning_rate": 0.0001,
10
+ "lora_parameters": {
11
+ "rank": 16,
12
+ "dropout": 0.05,
13
+ "scale": 32.0
14
+ },
15
+ "lr_schedule": null,
16
+ "mask_prompt": true,
17
+ "max_seq_length": 4096,
18
+ "model": "mlx-community/Qwen3-4B-Instruct-2507-4bit",
19
+ "num_layers": 16,
20
+ "optimizer": "adam",
21
+ "optimizer_config": {
22
+ "adam": {}
23
+ },
24
+ "project_name": null,
25
+ "report_to": null,
26
+ "resume_adapter_file": "/Users/giuliosighieri/Desktop/kg-v0/finetuning/artifacts/kg-query-planner-fresh-adapter/planner/adapter/checkpoints/0002000/adapters.safetensors",
27
+ "resume_checkpoint_dir": "/Users/giuliosighieri/Desktop/kg-v0/finetuning/artifacts/kg-query-planner-fresh-adapter/planner/adapter/checkpoints/0002000",
28
+ "save_every": 500,
29
+ "seed": 7,
30
+ "steps_per_eval": 2370,
31
+ "steps_per_report": 10,
32
+ "test": false,
33
+ "train": true,
34
+ "val_batches": -1
35
+ }
planner/adapter/adapters.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d910f5e542f6e7b351d8141855504be94644ac5c86fa1f70bcdbb73f1e7c40a9
3
+ size 58744712
planner/adapter/train_config.yaml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ model: 'mlx-community/Qwen3-4B-Instruct-2507-4bit'
2
+ train: true
3
+ test: false
4
+ data: '/Users/giuliosighieri/Desktop/kg-v0/finetuning/artifacts/kg-query-planner-fresh-adapter/prepared/planner/balanced'
5
+ seed: 7
6
+ num_layers: 16
7
+ batch_size: 4
8
+ iters: 7110
9
+ val_batches: -1
10
+ learning_rate: 0.0001
11
+ steps_per_report: 10
12
+ steps_per_eval: 2370
13
+ adapter_path: '/Users/giuliosighieri/Desktop/kg-v0/finetuning/artifacts/kg-query-planner-fresh-adapter/planner/adapter'
14
+ save_every: 500
15
+ max_seq_length: 4096
16
+ grad_checkpoint: true
17
+ grad_accumulation_steps: 4
18
+ mask_prompt: true
19
+ lora_parameters:
20
+ rank: 16
21
+ dropout: 0.05
22
+ scale: 32.0
23
+ resume_checkpoint_dir: '/Users/giuliosighieri/Desktop/kg-v0/finetuning/artifacts/kg-query-planner-fresh-adapter/planner/adapter/checkpoints/0002000'
planner/system_prompt.txt ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ You translate natural-language questions into compact JSON plans for the production business-model knowledge graph. Do not write Cypher. The runtime compiles your plan into Cypher deterministically.
2
+
3
+ OUTPUT CONTRACT
4
+ - For supported requests return {"answerable": true, "family": "...", "payload": {...}}.
5
+ - For unsupported, ambiguous, or out-of-coverage requests return {"answerable": false, "reason": "..."}
6
+ - Valid refusal reasons are unsupported_schema, unsupported_metric, unsupported_time, ambiguous_closed_label, ambiguous_request, write_request, and beyond_local_coverage.
7
+ - Output compact JSON only. No markdown, no prose, no explanation, no chain-of-thought.
8
+
9
+ DATABASE ARCHITECTURE
10
+ - Node labels: Company, BusinessSegment, Offering, CustomerType, Channel, RevenueModel, and Place.
11
+ - Relationship types: HAS_SEGMENT, OFFERS, SERVES, SELLS_THROUGH, MONETIZES_VIA, OPERATES_IN, and PARTNERS_WITH.
12
+ - Company nodes are keyed by name.
13
+ - BusinessSegment and Offering are company-scoped in downstream querying.
14
+ - SERVES and SELLS_THROUGH live on BusinessSegment in the local-safe query families.
15
+ - MONETIZES_VIA lives only on Offering.
16
+ - OPERATES_IN and PARTNERS_WITH live only on Company.
17
+ - Offering families use Offering-[:OFFERS]->Offering recursively.
18
+ - Place nodes may carry within_places and includes_places arrays for geographic rollups.
19
+
20
+ CLOSED LABELS
21
+ - CustomerType is a closed vocabulary. Valid labels are consumers, small businesses, mid-market companies, large enterprises, developers, IT professionals, government agencies, educational institutions, healthcare organizations, financial services firms, manufacturers, and retailers.
22
+ - Channel is a closed vocabulary. Valid labels are direct sales, online, retail, distributors, resellers, OEMs, system integrators, managed service providers, and marketplaces.
23
+ - RevenueModel is a closed vocabulary. Valid labels are subscription, advertising, licensing, consumption-based, hardware sales, service fees, royalties, and transaction fees.
24
+ - Always normalize user wording to the exact canonical closed label before returning payload values.
25
+ - Examples: government, public sector, or agencies -> government agencies.
26
+ - Examples: healthcare firms, hospitals, providers, or health systems -> healthcare organizations.
27
+ - Examples: enterprise customers -> large enterprises when that is the closest canonical label.
28
+ - If the wording does not map clearly to one canonical closed label, refuse with ambiguous_closed_label.
29
+
30
+ OPEN LITERAL COPYING
31
+ - companies, partners, segments, offerings, and places are open-class literals, not closed vocabularies.
32
+ - Copy open-class literals exactly as written in the user request unless an exact canonical place synonym is already established elsewhere in the prompt.
33
+ - Never paraphrase, respell, split, merge, autocorrect, or partially normalize company, partner, segment, or offering names.
34
+ - Do not invent punctuation or whitespace inside copied literals.
35
+ - Examples: Nimbus Health -> companies:["Nimbus Health"]; MediSupply -> partners:["MediSupply"]; Vector Industrial -> companies:["Vector Industrial"].
36
+ - Only normalize closed vocabularies such as customer_types, channels, and revenue_models.
37
+
38
+ QUERY FAMILY CATALOG
39
+ - companies_list
40
+ - segments_by_company
41
+ - offerings_by_company
42
+ - offerings_by_segment
43
+ - companies_by_segment_filters
44
+ - segments_by_segment_filters
45
+ - companies_by_cross_segment_filters
46
+ - descendant_offerings_by_root
47
+ - companies_by_descendant_revenue
48
+ - companies_by_place
49
+ - segments_by_place_and_segment_filters
50
+ - companies_by_partner
51
+ - boolean_exists
52
+ - count_aggregate
53
+ - ranking_topk
54
+
55
+ PAYLOAD FIELDS
56
+ - Use only these payload keys when they are needed: companies, segments, offerings, customer_types, channels, revenue_models, places, partners, binding_scope, hierarchy_mode, aggregate_spec, base_family, and limit.
57
+ - companies, segments, offerings, places, and partners are list-valued union filters by default.
58
+ - Repeated customer_types, channels, offerings, and revenue_models inside segment-filter families are cumulative constraints, not free-form prose.
59
+ - binding_scope is same_segment or across_segments.
60
+ - hierarchy_mode is direct or descendant.
61
+ - boolean_exists uses base_family plus the same filter payload as the referenced lookup family.
62
+ - count_aggregate uses aggregate_spec.kind=count, aggregate_spec.base_family, and aggregate_spec.count_target.
63
+ - ranking_topk uses aggregate_spec.kind=ranking and one whitelisted ranking metric.
64
+
65
+ SUPPORTED AGGREGATES
66
+ - Count targets: company, segment, and offering.
67
+ - Whitelisted ranking metrics are customer_type_by_company_count, channel_by_segment_count, revenue_model_by_company_count, and company_by_matched_segment_count.
68
+ - Use limit for top-k style requests.
69
+
70
+ REFUSE IN THESE CASES
71
+ - Temporal questions, trends, dates, or year-over-year requests -> unsupported_time.
72
+ - Unsupported metrics such as revenue amounts, prices, growth, employees, or suppliers -> unsupported_metric or unsupported_schema.
73
+ - Write or mutate requests -> write_request.
74
+ - Free-form explanations, why-questions, and unsupported set comparisons -> beyond_local_coverage.
75
+ - Ambiguous requests that do not map safely to one family and payload -> ambiguous_request.
router/model/added_tokens.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "[MASK]": 128000
3
+ }
router/model/config.json ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "DebertaV2ForSequenceClassification"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "bos_token_id": 1,
7
+ "dtype": "float32",
8
+ "eos_token_id": 2,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 768,
12
+ "id2label": {
13
+ "0": "api_fallback",
14
+ "1": "local",
15
+ "2": "refuse"
16
+ },
17
+ "initializer_range": 0.02,
18
+ "intermediate_size": 3072,
19
+ "label2id": {
20
+ "api_fallback": 0,
21
+ "local": 1,
22
+ "refuse": 2
23
+ },
24
+ "layer_norm_eps": 1e-07,
25
+ "legacy": true,
26
+ "max_position_embeddings": 512,
27
+ "max_relative_positions": -1,
28
+ "model_type": "deberta-v2",
29
+ "norm_rel_ebd": "layer_norm",
30
+ "num_attention_heads": 12,
31
+ "num_hidden_layers": 6,
32
+ "pad_token_id": 0,
33
+ "pooler_dropout": 0,
34
+ "pooler_hidden_act": "gelu",
35
+ "pooler_hidden_size": 768,
36
+ "pos_att_type": [
37
+ "p2c",
38
+ "c2p"
39
+ ],
40
+ "position_biased_input": false,
41
+ "position_buckets": 256,
42
+ "relative_attention": true,
43
+ "share_att_key": true,
44
+ "transformers_version": "4.57.6",
45
+ "type_vocab_size": 0,
46
+ "vocab_size": 128100
47
+ }
router/model/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6ef0e8d3c5c9ebe4723f66544dfd1b45d49a4e0d435708056d94e99b09fafd9f
3
+ size 567601628
router/model/special_tokens_map.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "[CLS]",
3
+ "cls_token": "[CLS]",
4
+ "eos_token": "[SEP]",
5
+ "mask_token": "[MASK]",
6
+ "pad_token": "[PAD]",
7
+ "sep_token": "[SEP]",
8
+ "unk_token": {
9
+ "content": "[UNK]",
10
+ "lstrip": false,
11
+ "normalized": true,
12
+ "rstrip": false,
13
+ "single_word": false
14
+ }
15
+ }
router/model/spm.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c679fbf93643d19aab7ee10c0b99e460bdbc02fedf34b92b05af343b4af586fd
3
+ size 2464616
router/model/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
router/model/tokenizer_config.json ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "[CLS]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "[SEP]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "[UNK]",
29
+ "lstrip": false,
30
+ "normalized": true,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "128000": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "bos_token": "[CLS]",
45
+ "clean_up_tokenization_spaces": false,
46
+ "cls_token": "[CLS]",
47
+ "do_lower_case": false,
48
+ "eos_token": "[SEP]",
49
+ "extra_special_tokens": {},
50
+ "mask_token": "[MASK]",
51
+ "model_max_length": 1000000000000000019884624838656,
52
+ "pad_token": "[PAD]",
53
+ "sep_token": "[SEP]",
54
+ "sp_model_kwargs": {},
55
+ "split_by_punct": false,
56
+ "tokenizer_class": "DebertaV2Tokenizer",
57
+ "unk_token": "[UNK]",
58
+ "vocab_type": "spm"
59
+ }
router/model/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:65d4e26fe0faa624bcecbbbe5f82997efbf2bda39abfbde6863411e79da6e325
3
+ size 5969
router/model/training_summary.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "output_dir": "/Users/giuliosighieri/Desktop/kg-v0/finetuning/artifacts/kg-query-planner/router/model",
3
+ "train_examples": 8000,
4
+ "valid_examples": 1200,
5
+ "label_counts": {
6
+ "api_fallback": 1500,
7
+ "local": 5000,
8
+ "refuse": 1500
9
+ },
10
+ "train_metrics": {
11
+ "train_runtime": 157.9059,
12
+ "train_samples_per_second": 303.978,
13
+ "train_steps_per_second": 18.999,
14
+ "total_flos": 202218153306336.0,
15
+ "train_loss": 0.05477014222391881,
16
+ "epoch": 3.0
17
+ }
18
+ }
router/thresholds.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "temperature": 0.9993856549263,
3
+ "local_threshold": {
4
+ "threshold": 5.6824406783562154e-05,
5
+ "precision": 0.9702457956015524,
6
+ "recall": 1.0,
7
+ "support": 773
8
+ },
9
+ "refuse_threshold": {
10
+ "threshold": 8.565641473978758e-05,
11
+ "precision": 0.9527896995708155,
12
+ "recall": 1.0,
13
+ "support": 233
14
+ },
15
+ "planner_gate_open": true
16
+ }