# What Are the Three-Tier Edge Confidence Scores in Code-Review-Graph?

> Understand the three-tier edge confidence scores in Code-Review-Graph: EXTRACTED, INFERRED, and AMBIGUOUS. Learn what each means and their confidence levels for relationship reliability.

- Repository: [Tirth Kanani/code-review-graph](https://github.com/tirth8205/code-review-graph)
- Tags: deep-dive
- Published: 2026-07-19

---

**The three-tier edge confidence scores in Code-Review-Graph categorize relationship reliability as EXTRACTED (directly from source), INFERRED (heuristic or AI-derived), or AMBIGUOUS (uncertain), each paired with a 0.0–1.0 float indicating specific confidence strength.**

The `tirth8205/code-review-graph` repository implements a sophisticated trust system for code relationships using categorical tiers alongside numeric confidence values. Understanding these three-tier edge confidence scores helps developers prioritize which automated code reviews require manual verification and which relationships are derived directly from static analysis.

## How Edge Confidence Works

Every relationship (edge) in the knowledge graph stores two complementary confidence indicators:

- **A float value** between 0.0 and 1.0 representing quantitative certainty
- **A categorical tier** (`EXTRACTED`, `INFERRED`, or `AMBIGUOUS`) describing the qualitative source of that confidence

This dual system allows the graph to distinguish between explicitly visible code relationships and those deduced through inference, enabling precise filtering and risk assessment during code review automation.

## The Three Confidence Tiers Explained

### EXTRACTED

The **EXTRACTED** tier indicates that the edge was **directly extracted** from source code via static analysis. Because the relationship is explicitly visible in the code—such as a concrete import statement, function call, or language-specific construct—this tier carries the highest default trust.

According to the source code in [`code_review_graph/graph.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/graph.py), the `Edge` dataclass defaults new edges to this tier with maximum confidence:

```python

# From code_review_graph/graph.py lines 68-119

@dataclass
class Edge:
    source: str
    target: str
    confidence: float = 1.0           # Default: maximum confidence

    confidence_tier: str = "EXTRACTED" # Default: directly extracted

```

### INFERRED

The **INFERRED** tier marks edges created through **heuristics or language models** when the relationship is not explicitly present in the source but can be reasonably deduced. Common scenarios include dynamic imports, convention-based references, or patterns learned from similar codebases.

The [`event_resolver.py`](https://github.com/tirth8205/code-review-graph/blob/main/event_resolver.py) module specifically assigns this tier when synthesizing edges from runtime-like cues or AI-driven knowledge graph expansion:

```python

# From code_review_graph/event_resolver.py lines 106-108

# Example of creating an inferred edge

edge = Edge(
    source=caller,
    target=callee,
    confidence=0.85,
    confidence_tier="INFERRED"
)

```

### AMBIGUOUS

The **AMBIGUOUS** tier flags **uncertain or conflicting relationships** where the analyzer detected a possible connection but cannot determine its exact nature. This typically occurs with wildcard imports, dynamically generated code, or conflicting signals from multiple analysis passes. Edges with this tier usually carry lower float confidence values and explicitly signal the need for human review.

## Database Schema Implementation

The confidence system was introduced in **migration v9**, which added the `confidence` and `confidence_tier` columns to the SQLite `edges` table. As implemented in [`code_review_graph/migrations.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/migrations.py) (lines 229-238), the schema stores these values as:

- `confidence`: REAL (floating-point)
- `confidence_tier`: TEXT (constrained to the three valid tiers)

This schema design allows efficient SQL filtering by tier while preserving precise numeric confidence for ranking algorithms.

## Working with Confidence Scores in Python

The following examples demonstrate how to interact with the three-tier system using the `Graph` API.

### Accessing Edge Confidence Information

```python
from code_review_graph.graph import Graph

# Load a graph for a repository (example: the current working directory)

g = Graph.load("./")          # automatically loads the SQLite DB for the repo

# Iterate over all edges and print their confidence information

for edge in g.edges():
    print(
        f"{edge.source} → {edge.target}",
        f"confidence={edge.confidence:.2f}",
        f"tier={edge.confidence_tier}"
    )

```

### Filtering by Confidence Tier

```python

# Show only edges that were inferred (i.e., not directly extracted)

inferred_edges = [
    e for e in g.edges() if e.confidence_tier == "INFERRED"
]

print(f"Found {len(inferred_edges)} inferred edges")

```

### Ranking by Numeric Confidence

```python

# Sort edges by descending confidence (high‑confidence edges first)

sorted_edges = sorted(g.edges(), key=lambda e: e.confidence, reverse=True)

# Print the top‑5 most confident relationships

for e in sorted_edges[:5]:
    print(f"{e.source} → {e.target} ({e.confidence_tier}, {e.confidence:.2f})")

```

## Summary

- **EXTRACTED** edges come directly from static code analysis and default to `confidence=1.0` as defined in [`code_review_graph/graph.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/graph.py)
- **INFERRED** edges are generated via heuristics or AI models, explicitly set in modules like [`code_review_graph/event_resolver.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/event_resolver.py)
- **AMBIGUOUS** edges indicate uncertain relationships requiring manual verification, typically with low float confidence values
- The database schema stores both the float confidence and categorical tier in the `edges` table since migration v9
- The README documents this feature as "Three-tier confidence scoring (EXTRACTED/INFERRED/AMBIGUOUS) with float scores on edges"

## Frequently Asked Questions

### What is the default confidence tier when creating a new edge?

New `Edge` objects default to the **EXTRACTED** tier with a confidence value of **1.0**. This default is hardcoded in the `Edge` dataclass within [`code_review_graph/graph.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/graph.py) (lines 68-119), ensuring that explicitly parsed relationships start with maximum trust unless the creating module overrides these values.

### How does the INFERRED tier differ from EXTRACTED in the codebase?

**EXTRACTED** edges originate from direct static analysis of source code where the relationship is syntactically visible, while **INFERRED** edges are synthesized by components like the event resolver when the connection is implied but not explicitly written. As seen in [`code_review_graph/event_resolver.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/event_resolver.py) (lines 106-108), inferred edges are explicitly constructed with the `INFERRED` tier label and typically carry confidence values below 1.0.

### What float confidence range should trigger manual review?

Edges with confidence scores **below 0.5** or those explicitly marked with the **AMBIGUOUS** tier warrant manual review, as these indicate either weak heuristic matches or conflicting analysis signals. The AMBIGUOUS tier specifically exists to flag relationships where the analyzer cannot resolve ambiguity, regardless of the specific float value assigned.

### Where are the confidence columns defined in the database schema?

The `confidence` and `confidence_tier` columns are defined in **migration v9** within [`code_review_graph/migrations.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/migrations.py) (lines 229-238). This migration adds a REAL column for the float score and a TEXT column for the tier classification to the `edges` table, establishing the storage foundation for the three-tier confidence system.