LLM-powered knowledge graph engine with ontological entity resolution, orbit-based proximity scoring, and hybrid semantic-graph retrieval.
Project description
ontograph
LLM-powered knowledge graph engine with ontological entity resolution, orbit-based proximity scoring, and hybrid semantic-graph retrieval.
Install
pip install ontograph
# or from source:
uv add .
Requires OPENAI_API_KEY environment variable.
Quick Start
from ontograph import OntoDB, Schema
# Initialize — creates a local SQLite database
db = OntoDB("my_knowledge.db")
# Define an ontology schema (constrains what the LLM extracts)
db.register_schema(Schema(
name="workplace",
entity_types=["person", "project", "team", "meeting", "topic"],
relationship_types=[
{"name": "works_on", "directed": True},
{"name": "manages", "directed": True},
{"name": "colleague", "directed": False},
{"name": "discussed", "directed": True},
{"name": "member_of", "directed": True},
],
))
# Ingest unstructured text — entities and relationships extracted automatically
db.ingest(
"Meeting with Nara and Marco about Project Neptune. "
"Nara is leading the backend rewrite. Marco raised concerns about the launch deadline.",
source_type="transcript",
schema_name="workplace",
)
# Search the graph (semantic + keyword + graph traversal)
results = db.search("What is Nara working on?")
# Ask a question — LLM synthesizes answer from graph context
answer = db.ask("Who is concerned about the launch deadline?")
print(answer)
Core Concepts
Entities, Relationships, Attributes
Everything decomposes into these three primitives:
- Entities: nodes — people, projects, topics, anything nameable
- Relationships: edges — directed (
A → B) or bidirectional (A ↔ B) - Attributes: key-value metadata on entities and relationships
Entity Resolution
When ingesting text, names are fuzzy-matched against existing entities using a composite score:
- Phonetic similarity (Metaphone) — catches pronunciation-similar names
- Spelling similarity (Jaro-Winkler) — catches typos
- Semantic similarity (embedding cosine) — catches conceptual matches
- Orbit proximity — weights by interaction frequency
Orbit
Your "orbit" is a proximity model. Entities you interact with frequently score higher. This powers entity resolution — when "Sal" appears in a transcript, the system weights your manager "Sam" (who you interact with daily) over random "Sal"s elsewhere.
# Add a known transcription error alias
sam = db.get_entity("Sam")
db.add_alias(sam.id, "Sal", alias_type="transcript_error")
Schemas
Ontology schemas define valid entity and relationship types for a domain. They constrain what the LLM extracts.
Self-Improving Feedback Loop
Every entity resolution is logged. Mark resolutions as correct/incorrect to track accuracy over time:
db.mark_resolution("log_id", correct=True)
print(db.stats()["resolution_accuracy"])
API
OntoDB(db_path, api_key=None, observer_id=None)— Main entry point.ingest(text, source_type, schema_name, observer_id, metadata) → dict— Ingest unstructured text.search(query, limit, graph_depth) → list[dict]— Hybrid search.ask(question) → str— LLM-synthesized answer from graph context.add_entity(name, entity_type, attributes, aliases) → Entity— Manual entity creation.add_relationship(source, target, type, directed) → Relationship— Manual relationship creation.resolve(name, entity_type, observer) → (Entity | None, float)— Entity resolution.orbit(observer, limit) → list[dict]— Proximity-ranked entities.stats() → dict— Graph statistics and resolution accuracy
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ontograph-0.1.1.tar.gz.
File metadata
- Download URL: ontograph-0.1.1.tar.gz
- Upload date:
- Size: 123.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b991ba1dfcb8503e8588e09262d6cedd715af9cacdc369953c2fb901c2e0a49e
|
|
| MD5 |
b0146bcc103a39bf864ba4824ff30c04
|
|
| BLAKE2b-256 |
16c98f6ef0af1265d8fe550d0c918bed7d1e90baf0c3b0ff2bf932ccacc8f2a6
|
File details
Details for the file ontograph-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ontograph-0.1.1-py3-none-any.whl
- Upload date:
- Size: 31.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32903d2e44faeda1cd84585e66d6f911d42f413b3602484797c204de6cba3939
|
|
| MD5 |
f4a7ea2d8336bf6f13b3a3e15b34ddf1
|
|
| BLAKE2b-256 |
69527464c75eaf3d80f1e548bd8e52fc16f7137e9a09669d4ceb99ca4d2add4e
|