Skip to main content

A typed knowledge-graph interface for reified-infon (hyperedge) facts: ingest, store, retrieve over a pluggable data layer. Embedded SQLite default; bring-your-own backend via one protocol.

Project description

hyper-kg

A small, typed knowledge-graph interface for reified-infon facts — ingest a pile of infons, store them as a property graph, and retrieve with typed primitives. Dependency-free core (stdlib SQLite), with a bring-your-own data layer via one protocol.

An infon is a reified hyperedge: a fact promoted to a first-class, addressable node binding typed role-participants (subject, object, …), carrying polarity, an evidence-mass triple, and provenance — so other facts can point at it.

from hyper_kg import KG

kg = KG.open("sqlite:///world.db")            # or "sqlite://:memory:", or a custom scheme

# write a pile of infons (the {subject,predicate,object,polarity,mass,...} dict shape)
kg.write_infons("doc1", pile)                 # dedup → fan out → one transaction → idempotent

# typed retrieval
kg.find(predicate="supplies", polarity="affirmed")
kg.neighbors("Samsung SDI", hops=2)

# optional: extract straight from text (needs `pip install hyper-kg[extract]`)
kg.ingest("Samsung SDI supplies cells to BMW.", doc_id="doc2")

What it does

  • write_infons(doc_id, pile) — each infon fans out into an :Infon node + canonical :Entity nodes + HAS_INFON/S_OF/O_OF edges, batched in one transaction. Idempotent by content-hash id (re-ingest is a no-op). Deduped by (subject, predicate, object, polarity).
  • Typed retrievalfind(...) (indexed by subject/predicate/object/polarity), neighbors(node, hops=...) (graph walk), get_infon(id), anchors().
  • Bring your own backend — implement the KGStore protocol and register it:
    KG.register_backend("mydb", MyStoreClass)
    kg = KG.open("mydb://...")
    

Design

  • Entities arrive canonical. Subject/object are expected to be already-normalized canonical ids (e.g. resolved at extraction time), so there is no entity-resolution pass — the graph stays connected by construction. Un-anchored novel entities can be flagged provisional.
  • Generic property graph. nodes(id, labels, props_json + virtual indexed columns) and edges(src, dst, type, props_json) — no per-fact schema migration.
  • Typed ops, not query strings. The interface is a small typed method API every backend implements natively, so SQL and custom backends are first-class. A graph-native backend may expose an optional query escape hatch.

License

Apache-2.0.

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

hyper_kg-0.1.2.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

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

hyper_kg-0.1.2-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file hyper_kg-0.1.2.tar.gz.

File metadata

  • Download URL: hyper_kg-0.1.2.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for hyper_kg-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3918844d2a610dea4bfbebce644c8e425b2cdd81cd19cffad49bd6d52a6f1b33
MD5 9bb708342dbf69ddd7ea87e5adcb5a21
BLAKE2b-256 cb7d0b4cd8b283e5d185dcffd1cd00d2d44deb0be485ded95fabaf69da4f03a4

See more details on using hashes here.

File details

Details for the file hyper_kg-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: hyper_kg-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for hyper_kg-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dd32a5d4542db7a3da840ffc64ff90caf6368d7a90bc499101abf2b4f7fd3a5d
MD5 3c153d5868c1f6d97dfab220429cf7ab
BLAKE2b-256 6a030a06cc2598f8e1b56f59cfc460f11af3e4eac913e4f8e25a441f844e8f57

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