Skip to main content

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

Release files for ontograph 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ontograph 0.4.0
File Size Uploaded
ontograph-0.4.0.tar.gz 6.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for ontograph 0.4.0
File Interpreter ABI Platform
ontograph-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.3 MB

Release files / ontograph-0.4.0.tar.gz

Download URL ontograph-0.4.0.tar.gz
Size 6.3 MB
Tags Source
SHA-256 checksum
How to use checksums
3511e02ad328be675d7af3368bdb2917ae93c980f4a53d25d7b6aaf3aa0337e9
BLAKE2b-256 checksum
How to use checksums
96027f24e3223efa0448365408d6a9644c7f75e7823bed0be931533275071ffc
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / ontograph-0.4.0-py3-none-any.whl

Download URL ontograph-0.4.0-py3-none-any.whl
Size 44.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9246f63f8b6a159bef2a63b57b5ea6edec47a940698a2eefd0f3c861e26e1873
BLAKE2b-256 checksum
How to use checksums
e53327d27e6739cb54ddc13af9ef15e70a6bc010b5dc236420d0e9ac3b021d61
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page