# Understanding the 4-Signal Knowledge Graph Relevance Model in LLM Wiki

> Explore the 4-signal knowledge graph relevance model used in LLM Wiki. Discover how title similarity, full-text overlap, wikilink similarity, and backlink strength determine contextual relevance.

- Repository: [nash_su/llm_wiki](https://github.com/nashsu/llm_wiki)
- Tags: deep-dive
- Published: 2026-09-13

---

**The 4-signal knowledge graph relevance model scores candidate pages using a weighted combination of title similarity (40%), full-text overlap (30%), wikilink similarity (20%), and backlink strength (10%) to determine contextual relevance.**

The LLM Wiki repository implements a sophisticated graph-aware ranking system that balances textual similarity with topological connectivity. This 4-signal knowledge graph relevance model, defined in [`src/lib/wiki-graph-analysis.ts`](https://github.com/nashsu/llm_wiki/blob/main/src/lib/wiki-graph-analysis.ts), calculates relevance by combining four independent signals into a normalized composite score. Each signal targets a specific aspect of page relevance, from exact title matches to graph-based authority metrics.

## The Four Signals That Power the Relevance Algorithm

### 1. Title Similarity (Weight: 0.4)

The strongest signal measures how closely a candidate page's title matches the query terms. Implemented in the `titleScore` helper function within [`src/lib/wiki-graph-analysis.ts`](https://github.com/nashsu/llm_wiki/blob/main/src/lib/wiki-graph-analysis.ts), this signal uses case-insensitive string matching and fuzzy scoring to identify exact or near-exact title correspondences. With a default coefficient of **0.4**, it contributes the largest share to the final relevance calculation.

### 2. Full-Text Overlap (Weight: 0.3)

The second signal evaluates term frequency overlap between the query text and the candidate page body. The `contentScore` routine calculates a TF-IDF style similarity metric, rewarding pages with substantial topical content matching the search terms. This signal carries a weight of **0.3**, making it the second-most influential factor in the ranking.

### 3. Wikilink Similarity (Weight: 0.2)

Structural proximity in the knowledge graph is measured through shared outbound links. The `outboundLinkScore` function computes the proportion of wikilinks shared between the query context and candidate page, capturing semantic relationships defined by the graph topology. This structural signal receives a **0.2** weight, ensuring connectivity influences ranking without overwhelming textual signals.

### 4. Backlink Strength (Weight: 0.1)

The final signal measures graph authority through inbound connections. The `backlinkScore` routine counts how many other pages link to the candidate, serving as a popularity or authority cue similar to PageRank principles. With a **0.1** weight, this signal provides a modest boost to well-connected nodes while preserving the primacy of content relevance.

## How the Composite Relevance Score Is Calculated

The `rankPages` function in [`src/lib/wiki-graph-analysis.ts`](https://github.com/nashsu/llm_wiki/blob/main/src/lib/wiki-graph-analysis.ts) normalizes and combines these signals using the weighted formula:

```typescript
relevanceScore =
  0.4 * titleScore(query, p.title) +
  0.3 * contentScore(query, p.body) +
  0.2 * outboundLinkScore(query, p.wikilinks) +
  0.1 * backlinkScore(p.incomingLinks)

```

This linear combination ensures that pages ranking highest are both textually relevant and well-positioned within the knowledge graph structure.

## Implementation Architecture and Key Files

According to the LLM Wiki source code, the relevance model spans three primary files:

- **[`src/lib/wiki-graph-analysis.ts`](https://github.com/nashsu/llm_wiki/blob/main/src/lib/wiki-graph-analysis.ts)**: Core implementation containing `rankPages`, `titleScore`, `contentScore`, `outboundLinkScore`, and `backlinkScore`
- **[`src/lib/wiki-graph.ts`](https://github.com/nashsu/llm_wiki/blob/main/src/lib/wiki-graph.ts)**: Graph data structure definitions (`Page`, `Link`) that provide the schema for incoming links and wikilinks
- **[`src/lib/wiki-graph-analysis.test.ts`](https://github.com/nashsu/llm_wiki/blob/main/src/lib/wiki-graph-analysis.test.ts)**: Unit test suite verifying that each signal contributes correctly to composite rankings

## Using the 4-Signal Model in Your Application

To leverage this ranking system, import the `rankPages` function and pass your query along with candidate page objects:

```typescript
import { rankPages } from '@/lib/wiki-graph-analysis';

const query = 'neural network fundamentals';
const candidates = await getAllPages();        // Array of Page objects
const ranked = rankPages(query, candidates);  // Returns pages with relevanceScore

console.log(ranked.slice(0, 5).map(p => ({
  title: p.title,
  score: p.relevanceScore,
})));

```

The function returns the candidate array sorted by descending relevance score, with each page object decorated with a `relevanceScore` property containing the weighted composite value.

## Summary

- The 4-signal knowledge graph relevance model combines **title similarity** (40%), **full-text overlap** (30%), **wikilink similarity** (20%), and **backlink strength** (10%)
- All four signals are implemented in [`src/lib/wiki-graph-analysis.ts`](https://github.com/nashsu/llm_wiki/blob/main/src/lib/wiki-graph-analysis.ts) as discrete scoring functions
- The `rankPages` function normalizes and weights these signals to produce a final relevance score
- This architecture balances textual similarity with graph topology to surface contextually appropriate pages

## Frequently Asked Questions

### How are the weights determined in the 4-signal model?

The default weights (0.4, 0.3, 0.2, 0.1) are hand-tuned coefficients hardcoded in the `rankPages` function. These values prioritize exact title matches while ensuring structural connectivity still influences ranking. Developers can modify these coefficients in [`src/lib/wiki-graph-analysis.ts`](https://github.com/nashsu/llm_wiki/blob/main/src/lib/wiki-graph-analysis.ts) to adjust the ranking behavior for specific use cases.

### Can I use individual signals without the composite score?

Yes. The source code exposes each signal as an independent function (`titleScore`, `contentScore`, `outboundLinkScore`, `backlinkScore`), allowing you to import and use them separately. However, the `rankPages` function remains the recommended entry point as it handles normalization and ensures consistent weighting across signals.

### What data structures does the model require?

The model expects Page objects containing `title`, `body`, `wikilinks` (array of outbound links), and `incomingLinks` (array of backlink references). These structures are defined in [`src/lib/wiki-graph.ts`](https://github.com/nashsu/llm_wiki/blob/main/src/lib/wiki-graph.ts), which establishes the TypeScript interfaces used throughout the relevance calculation pipeline.

### How does this differ from traditional TF-IDF ranking?

While the model incorporates TF-IDF style analysis through the `contentScore` signal, it extends beyond pure text matching by incorporating graph topology via wikilink and backlink analysis. This dual approach ensures that highly connected, authoritative pages receive appropriate ranking boosts even when their textual similarity is moderate.