Skip to main content

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

ontograph-0.2.0.tar.gz (132.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ontograph-0.2.0-py3-none-any.whl (39.4 kB view details)

Uploaded Python 3

File details

Details for the file ontograph-0.2.0.tar.gz.

File metadata

  • Download URL: ontograph-0.2.0.tar.gz
  • Upload date:
  • Size: 132.6 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

Hashes for ontograph-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d6e8920ce70178c098d9618486a150a1f19015a221f7b5a0f0bb22e6710e9467
MD5 e0c226f90613e9ddeeda4123205edc3c
BLAKE2b-256 b85384862c40ac106cae2eaad1221a07f0f24293bc5bd86c7782b7082a1d5234

See more details on using hashes here.

File details

Details for the file ontograph-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: ontograph-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 39.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

Hashes for ontograph-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3d6e4285ebe1448f3a4a217fd1794be5880e2931a44d9f963fe71504cafd7f9f
MD5 2a34aab3a4525b658026578514cb4421
BLAKE2b-256 f091c23cdcf58b0fd716a9c0b5c536d9346b29bc54b14c3f269df04bbbbbd9ce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page