| Denial Type |
LOC" is deterministic and immutable
Network Effect Gate — Clusters appear in marketplace only after 2+ distinct tenants contribute (MIN_CLUSTERS_FOR_MARKETPLACE = 2)
Contribution-Based Access — Tenants earn credits for contributions, spend credits to query clusters
Maturity Tiers — Clusters progress through tiers (Embryonic → Emerging → Mature → Canonical) as they grow
Aggregate Intelligence — Cluster-level metrics synthesize evidence, outcomes, and patterns from all members
Clustering Algorithm
Cluster ID Generation
For any precedent, cluster_id is deterministic:
def cluster_id(payer: str, denial_type: str, loc: Optional[str]) -> str:
"""Generate cluster_id from precedent fields.
Args:
payer: Insurance company name (e.g., "Cigna")
denial_type: Denial category (e.g., "Frequency Limit")
loc: Level of care or None for non-LOC denials
Returns:
Cluster ID in format "Payer | Denial Type | LOC" or "Payer | Denial Type |
"
"""
if loc is None:
return f"{payer} | {denial_type} |
"
return f"{payer} | {denial_type} |
{loc}"
Examples:
- Cigna IOP frequency limit:
"Cigna | Frequency Limit |
IOP"
- UHC medical necessity (any LOC):
"UHC | Medical Necessity |
"
- Aetna PHP-only:
"Aetna | Level of Care |
PHP"
Cluster Discovery
When precedent is created:
-- Step 1: Calculate cluster_id
cluster_id = cluster_id(precedent.payer, precedent.denial_type, precedent.loc)
-- Step 2: Check if cluster exists
SELECT id FROM marketplace_clusters WHERE cluster_id = ?
-- Step 3: If not, create it
INSERT INTO marketplace_clusters (cluster_id, payer, denial_type, loc, contributor_count, ipo_count)
VALUES (?, payer, denial_type, loc, 1, 1);
-- Step 4: Increment ipo_count if cluster exists
UPDATE marketplace_clusters SET ipo_count = ipo_count + 1 WHERE cluster_id = ?
-- Step 5: Check if contributor is already in cluster
SELECT COUNT() FROM contribution_scores
WHERE cluster_id = ? AND tenant_id = current_tenant_id
-- Step 6: If new contributor, increment contributor_count
UPDATE marketplace_clusters SET contributor_count = contributor_count + 1 WHERE cluster_id = ?
INSERT INTO contribution_scores (tenant_id, cluster_id, ipo_count) VALUES (?, ?, 1)
Network Effect Gate
KEY RULE: Clusters only appear in marketplace after 2+ distinct tenants contribute.
Why? Prevent single-tenant seed data from polluting marketplace. Force genuine multi-tenant collaboration.
Implementation:
-- Query for browsable clusters (marketplace)
SELECT FROM marketplace_clusters
WHERE tenant_id = $1 -- Current tenant
AND contributor_count >= 2 -- Network gate
AND maturity_tier IN ('Emerging', 'Mature', 'Canonical')
ORDER BY ipo_count DESC;
-- Query for my clusters (showing progression toward marketplace)
SELECT FROM marketplace_clusters
WHERE tenant_id = $1
ORDER BY contributor_count DESC, ipo_count DESC;
Lifecycle Example:
| Event | Cluster State | Visible? |
| Tenant A creates first precedent | contributor_count=1 (Embryonic) | Private (A only) |
| Tenant B creates second precedent | contributor_count=2 (Emerging) | Public (appears in marketplace) |
| Tenant C creates third | contributor_count=3 (Mature) | Public |
| 10 more from mixed tenants | contributor_count=13 (Canonical) | Public (top tier) |
Maturity Tiers
Clusters progress through maturity based on growth metrics:
Embryonic (Tier 1)
Criteria: 1 contributor, any precedent count
State: Private, not in marketplace
Signals: Single tenant exploring domain
Actions: Owner can refine, validate, prepare for sharing
Emerging (Tier 2)
Criteria: 2–3 contributors, <10 precedents
State: Public (appears in marketplace)
Signals: Early multi-tenant collaboration
Incentive: First contributor bonus (extra credits) for unlocking marketplace
Actions: Community building, evidence synthesis
Mature (Tier 3)
Criteria: 4+ contributors, 10+ precedents, 50%+ win rate
State: Public, featured
Signals: Proven evidence base, consistent outcomes
Incentive: Higher-quality precedents earn more credits
Actions: Drift monitoring, narrative pattern synthesis
Canonical (Tier 4)
Criteria: 20+ precedents, 70%+ win rate, <7 days avg resolution
State: Public, pinned, featured
Signals: Gold standard for denial pattern
Incentive: Highest credit rewards, referenced in training
Actions: Annual validation, evidence synthesis
Tier Progression
Recalculate nightly or on precedent creation:
UPDATE marketplace_clusters
SET maturity_tier = CASE
WHEN contributor_count = 1 THEN 'Embryonic'
WHEN contributor_count <= 3 AND ipo_count < 10 THEN 'Emerging'
WHEN contributor_count >= 4
AND ipo_count >= 10
AND (SELECT COUNT() FILTER(WHERE outcome='Won') FROM precedent_objects WHERE cluster_id = mc.cluster_id) / ipo_count > 0.5
THEN 'Mature'
WHEN ipo_count >= 20
AND (SELECT COUNT() FILTER(WHERE outcome='Won') FROM precedent_objects WHERE cluster_id = mc.cluster_id) / ipo_count > 0.7
AND (SELECT AVG(time_to_resolution_days) FROM precedent_objects WHERE cluster_id = mc.cluster_id) < 7
THEN 'Canonical'
ELSE 'Emerging'
END
WHERE last_refreshed < NOW() - INTERVAL '1 day';
Aggregate Metrics
Each cluster synthesizes data from all member precedents:
win_rate
SELECT COUNT() FILTER(WHERE outcome='Won') 100.0 / COUNT() AS win_rate
FROM precedent_objects
WHERE cluster_id = $1;
Use: Indicate cluster strength. "70%+ win rate = Canonical"
avg_resolution_days
SELECT AVG(time_to_resolution_days) AS avg_resolution
FROM precedent_objects
WHERE cluster_id = $1 AND outcome IN ('Won', 'Lost', 'Partial');
Use: Indicate efficiency. "<7 days = gold standard"
top_evidence_types
{
"clinical_notes": 0.85, // 85% of successful appeals used clinical notes
"psychiatric_evaluation": 0.78,
"gaf_score": 0.92,
"functional_assessment": 0.45
}
Use: Guide new contributors on what evidence to gather.
narrative_patterns
{
"functional_impact": 0.85, // 85% of Won appeals emphasized functional impact
"evidence_combination": 0.72,
"escalation_path": 0.40,
"parity_law_reference": 0.55
}
Use: Show what narrative strategies work for this denial type.
evidence_kit_composite
Merged evidence requirements from all cluster precedents:
{
"required": [
"Clinical notes (30 days)",
"Psychiatric evaluation",
"GAF score",
"Functional assessment"
],
"recommended": [
"Prior hospitalization records",
"School/work functional history"
],
"optional": [
"Research articles",
"Expert opinions"
]
}
Use: New users building appeal in this cluster know exactly what evidence to gather.
Drift Detection
Clusters are flagged if metrics trend negatively:
{
"outcome_trending_down": false, // Win rate declining month/month
"resolution_time_increasing": false, // Taking longer to resolve
"contributor_churn": false, // Contributors leaving (count decreasing)
"evidence_effectiveness_declining": false // New precedents have lower win rate
}
Trigger: Recalculated on precedent update or nightly
Example:
-- Check if win_rate is declining
SELECT
DATE_TRUNC('month', created_at)::DATE AS month,
COUNT() FILTER(WHERE outcome='Won') 100.0 / COUNT() AS win_rate
FROM precedent_objects
WHERE cluster_id = $1 AND created_at > NOW() - INTERVAL '12 months'
GROUP BY DATE_TRUNC('month', created_at)
ORDER BY month DESC;
Action: If trending down > 10% MoM, flag cluster for review.
Credit Integration
Contribution Mint (Create Precedent)
When precedent is added to cluster:
-- Calculate credits earned
credits = base_amount evidence_quality_multiplier
base_amount = 10
multiplier = 1.0 (Minimal) | 1.5 (Moderate) |
2.0 (Strong)
-- Log to credit_ledger
INSERT INTO credit_ledger (
event_type='contribution_mint',
amount=credits,
tenant_id=current_tenant,
reference_id=precedent_id,
metadata={'evidence_score': '...', 'outcome': '...'}
);
-- Update contribution_scores
UPDATE contribution_scores
SET ipo_count = ipo_count + 1
WHERE tenant_id = current_tenant AND cluster_id = ?;