> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qwedai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Fact engine

> The Fact Engine verifies claims using TF-IDF similarity, keyword overlap, entity matching, and negation detection.

The Fact Engine verifies factual claims using **deterministic methods first**, without requiring LLM calls for most claims.

## Features

* **TF-IDF semantic similarity** - No LLM needed.
* **Keyword overlap analysis** - Fast and deterministic.
* **Entity matching** - Numbers, dates, names.
* **Citation extraction** - With relevance scoring.
* **Negation detection** - Catch contradictions.
* **LLM fallback** - Only when confidence is low.

## Usage

```python theme={null}
from qwed_sdk import QWEDClient

client = QWEDClient(api_key="qwed_...")

result = client.verify_fact(
    claim="The company was founded in 2020.",
    context="Acme Corp was founded in 2020 by John Smith in San Francisco."
)

print(result.verdict)       # "SUPPORTED"
print(result.confidence)    # 0.95
print(result.citations)     # [{"sentence": "...", "relevance": 0.98}]
print(result.methods_used)  # ["semantic_similarity", "entity_matching"]
```

## Scoring methods

| Method              | What it checks           | Weight |
| ------------------- | ------------------------ | ------ |
| Semantic similarity | TF-IDF cosine distance   | 0.25   |
| Keyword overlap     | Shared important words   | 0.20   |
| Entity match        | Numbers, dates, names    | 0.35   |
| Negation conflict   | Contradicting statements | 0.20   |

## Why deterministic?

```
BEFORE (v1): 
Claim → LLM → "I think this is supported" 😕

AFTER (v2):
Claim → TF-IDF + Entity Match → SUPPORTED ✅
       (LLM only if confidence < 0.7)
```

No more hallucinated fact checks!
