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 logo

ontograph

LLM-powered knowledge graph engine
Ontological entity resolution · Orbit-based proximity scoring · Hybrid semantic-graph retrieval

PyPI Python License


Install

pip install ontograph

Requires OPENAI_API_KEY environment variable (or set it in a .env file — loaded automatically).

Quick Start

from ontograph import OntoDB, Schema

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},
    ],
))

# 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 three primitives:

Primitive Description
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 four-signal composite score:

Signal Method Catches
Phonetic Metaphone Pronunciation-similar names
Spelling Jaro-Winkler Typos and minor variations
Semantic Embedding cosine Conceptual matches
Orbit Interaction frequency Context-aware disambiguation

Orbit

Your "orbit" is a proximity model. Entities you interact with frequently score higher — when "Sal" appears in a transcript, the system weights your manager "Sam" (who you interact with daily) over random "Sal"s elsewhere.

sam = db.get_entity("Sam")
db.add_alias(sam.id, "Sal", alias_type="transcript_error")

File References

Entities can reference external files — receipts, photos, PDFs, contracts — that live on disk. These references are surfaced during search and Q&A so the LLM knows where to find supporting material.

# Attach files to an entity
db.attach_files("kitchen renovation", [
    "/Users/me/photos/kitchen_before.jpg",
    "/Users/me/photos/kitchen_after.jpg",
])

# When you ask a question, the LLM sees the file references
answer = db.ask("What photos do we have of the kitchen?")
# Or via CLI
ontograph attach "kitchen renovation" /Users/me/photos/kitchen_before.jpg

Schemas

Ontology schemas define valid entity and relationship types for a domain. They constrain what the LLM can extract during ingestion.

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"])

Python API

Method Description
OntoDB(db_path, api_key, observer_id) Main entry point
.ingest(text, source_type, schema_name) Ingest unstructured text
.search(query, limit, graph_depth) Hybrid search
.ask(question) LLM-synthesized answer from graph context
.add_entity(name, type, attributes, file_refs) Manual entity creation
.add_relationship(source, target, type) Manual relationship creation
.attach_files(entity, file_paths) Attach file references
.detach_files(entity, file_paths) Remove file references
.resolve(name, entity_type, observer) Entity resolution
.orbit(observer, limit) Proximity-ranked entities
.stats() Graph statistics and resolution accuracy

CLI

ontograph --help                    # Full command list with examples
ontograph ingest --text "..."       # Ingest text (also accepts --file or stdin)
ontograph search "query"            # Hybrid search
ontograph ask "question"            # LLM-synthesized answer
ontograph entities [--type person]  # List entities
ontograph entity "name"             # Get single entity
ontograph relationships "name"      # Get relationships
ontograph neighbors "name"          # Graph traversal
ontograph resolve "name"            # Entity resolution
ontograph attach "entity" file.pdf  # Attach file references
ontograph detach "entity" file.pdf  # Remove file references
ontograph schema register --file s.json  # Register ontology schema
ontograph dashboard                 # Interactive graph visualization

Dashboard

ontograph dashboard                 # Opens browser at http://127.0.0.1:8484
ontograph dashboard --port 9000    # Custom port
ontograph --db project.db dashboard

Interactive force-directed graph visualization powered by D3.js. Starts with the most-connected entity as hub, showing its top 50 relationships. Click to select, double-click to expand connections on demand, drag to reposition, scroll to zoom.

License

MIT

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.4.0.tar.gz (6.3 MB view details)

Uploaded Source

Built Distribution

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

ontograph-0.4.0-py3-none-any.whl (44.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ontograph-0.4.0.tar.gz
  • Upload date:
  • Size: 6.3 MB
  • 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.4.0.tar.gz
Algorithm Hash digest
SHA256 3511e02ad328be675d7af3368bdb2917ae93c980f4a53d25d7b6aaf3aa0337e9
MD5 acb1738abb6ee287bb79d2c802325ab9
BLAKE2b-256 96027f24e3223efa0448365408d6a9644c7f75e7823bed0be931533275071ffc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ontograph-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 44.3 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9246f63f8b6a159bef2a63b57b5ea6edec47a940698a2eefd0f3c861e26e1873
MD5 1916164b589d814d1ab80ac3d0ff30eb
BLAKE2b-256 e53327d27e6739cb54ddc13af9ef15e70a6bc010b5dc236420d0e9ac3b021d61

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