Metadata-Version: 2.4
Name: kgeval
Version: 0.1.1
Summary: An evaluation framework for knowledge graphs.
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: knowledge-graph,neo4j,evaluation,graphrag,rag,retrieval,data-quality,llm-as-a-judge
Author: iamzices
Author-email: hello@zices.com
Requires-Python: >=3.11
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Database
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Typing :: Typed
Requires-Dist: neo4j (>=5.0)
Requires-Dist: openai (>=1.92)
Requires-Dist: pydantic (>=2.10)
Requires-Dist: pyyaml (>=6.0)
Requires-Dist: rich (>=13)
Requires-Dist: typer (>=0.15.4)
Project-URL: Documentation, https://kgeval.github.io/kgeval/
Project-URL: Issues, https://github.com/kgeval/kgeval/issues
Project-URL: Repository, https://github.com/kgeval/kgeval
Description-Content-Type: text/markdown

# kgeval

[![PyPI](https://img.shields.io/pypi/v/kgeval)](https://pypi.org/project/kgeval/)
[![Python](https://img.shields.io/pypi/pyversions/kgeval)](https://pypi.org/project/kgeval/)
[![CI](https://github.com/kgeval/kgeval/actions/workflows/ci.yml/badge.svg)](https://github.com/kgeval/kgeval/actions/workflows/ci.yml)
[![License](https://img.shields.io/github/license/kgeval/kgeval)](https://github.com/kgeval/kgeval/blob/main/LICENSE)

kgeval is an evaluation framework for knowledge graphs.

It scores a graph on 29 metrics, covering duplicate entities, conformance to a graph
schema, agreement with a ground truth, and whether each fact is supported by the text it
was extracted from, and reports every defect with the nodes and relationships involved.
Comparing the reports of two versions of a graph shows which metrics improved or
regressed.

## Features

- Score a graph on 29 built-in metrics
- Trace every finding to the nodes and relationships involved
- Run reference-free and reference-based evaluation
- Compare evaluation runs over time

## Requirements

- Python 3.11+
- Neo4j 5.10+ or Aura

## Installation

```console
pip install kgeval
```

## Usage

kgeval runs from the command line or from Python. Both read the graph from Neo4j through a
read-only session, evaluate it in memory, and produce a report of scores and findings.

### CLI

```console
kgeval run
```

### Python

```python
import kgeval
from neo4j import GraphDatabase

with GraphDatabase.driver("<uri>", auth=("<username>", "<password>")) as driver:
    graph = kgeval.Neo4jSource(driver).load()

report = kgeval.evaluate(graph)
print(report.to_markdown())
```

## Report

The report gives each metric a score, the share of units such as entities or facts that
pass, so 100% is perfect. Each finding describes one defect and lists the IDs of the nodes
and relationships involved, so you can inspect them in Neo4j:

```text
### entity_uniqueness: 1 of 10 entities with a name failed

- 2 entities share the normalized name 'lee kuan yew': "Lee Kuan Yew" (Person), "lee kuan yew" (Person)
  - nodes: `4:9e643a2e-be5f-4bd0-8757-2f90968f1f8a:4`, `4:9e643a2e-be5f-4bd0-8757-2f90968f1f8a:9`
```

## Metrics

kgeval has 29 metrics in five categories: intrinsic, schema, reference, judged, and
retrieval. The metrics that need only the graph run by default, and the others run when you
provide their input, such as a schema or ground truth:

| Input          | Evaluates                                                               |
| -------------- | ----------------------------------------------------------------------- |
| Graph only     | Uniqueness, connectivity, naming, provenance, consistency, and coverage |
| Graph schema   | Conformance and completeness                                            |
| Ground truth   | Graph precision, recall, and F1                                         |
| Test questions | Answerability                                                           |
| Retrievals     | Retriever precision and recall                                          |
| LLM judge      | Accuracy, resolution, disambiguation, and extraction completeness       |

See the [metrics guide](https://kgeval.github.io/kgeval/guide/metrics/) for the full list.

## Documentation

For the full guide, see the [documentation](https://kgeval.github.io/kgeval/). For a
complete walkthrough, see the [example notebook](https://github.com/kgeval/kgeval/blob/main/examples/singapore/evaluate.ipynb).

