Skip to content

Knowledge graph

shdata.knowledge(name, vector_dim=None) returns a KnowledgeGraph: a time-aware graph of entities, documents, claims and typed relationships on ordinary SharedData tables, so it is page-cache fast, synced to S3 and recoverable like any table. One writer per graph; any number of readers. A graph read is not a transactional snapshot across its five tables.

Table (under <user>/<db>/D1/<name>/) Key Holds
Hashs/.../KGNODES hash entities and concepts: type, name, payload
Text/.../KGDOCS date, hash text with valid, subject, doctype, source, payload, vector
Text/.../KGCLAIMS date, hash subject, predicate, scope, value, source, payload (the history)
Relationships/.../KGEDGES date, symbol, symbol1 symbol1 = '<TYP>:<to>'; the mirror row '~<TYP>:<from>' answers incoming edges
Hashs/.../KGCURRENT hash the winning claim per state key (subject, predicate, scope)
from SharedData.KnowledgeGraph import node_id
kg = shdata.knowledge('EARNINGS', vector_dim=4096)
co, sec = node_id('company', '0000320193'), node_id('sector', 'Technology')
kg.ingest(nodes=[dict(id=co, type='company', name='0000320193', ticker='AAPL')],
          edges=[dict(src=co, type='MEMBER_OF', dst=sec, valid='2026-10-30')],
          claims=[dict(subject=co, predicate='guidance:revenue', scope='fy2027|G', value=120.0,
                       valid='2026-10-30 20:30', known='2026-10-30 20:31', direction='raised')],
          docs=[dict(valid='2026-10-30 20:30', text='...', doctype='earnings', subject=co, vector=emb)])
kg.state(co)                                   # current value per predicate|scope
kg.state(co, as_of='2026-10-01')               # rebuilt from the claims known then
kg.neighbors(sec, 'MEMBER_OF', 'in')           # incoming edges through the mirror rows
kg.siblings(co)                                # sector peers
kg.search(query_vector, start='2026-10-01', subjects=[co])   # filters before ranking
kg.context([co], vector=query_vector)          # one dict for a prompt

Rules

  • Ids are deterministic 16-hex blake2b values: every write can be repeated. node_id and make_id ignore string case and surrounding spaces; automatic document/claim ids and state_key preserve the exact case and spaces of their stored fields. UTF-8 bytes and strings identify the same key. Explicit node, document and claim ids fit 32 UTF-8 bytes. Edge endpoints and claim subjects fit 27 bytes, allowing the ~TYP: mirror prefix in a 32-byte column. Predicates fit 48 bytes, scopes and sources 32, and doctypes 24. NUL is rejected. Predicates cannot contain |, the state result's predicate/scope separator; scopes can contain it. Display names are truncated at 64 UTF-8 bytes.
  • Two times. valid is when it is true or happened (exact); known (stored as mtime) is when it became known. The date key is the day bucket of valid. as_of keeps rows known at that time; state as of a past time is rebuilt from claims, never read from KGCURRENT. It does not also restrict valid to the cutoff. Times preserve nanoseconds and timezone-aware input is converted to UTC. Valid times must be in [1970-01-01, 2100-01-01). Missing known is filled once at ingest and retained on replay. Future known values beyond the native table's one-second clock tolerance are rejected before publication.
  • Windows are inclusive. Date-only end and as_of values include the whole UTC day, through 23:59:59.999999999; a timestamp, including an explicit midnight, is an exact cutoff. start is an exact lower bound (midnight for a date). D1 date-index candidates are filtered again by exact valid.
  • Current state. The winner per key is the newest by (valid, known, claim id), so equal times resolve the same way in any order. A newer claim with status='withdrawn' and no value clears it. A backfill never replaces a newer claim. Historical state uses the same rank and scope selection. state(subject) includes every state key, independently of the default neighbor limit. siblings also includes every matching peer.
  • Claim identity is fixed after publication: the same (day, id) must retain its subject, predicate, scope, source, exact valid time and known time (or omit known on replay). Changing these requires a new claim id; otherwise the write raises before changing claims or CURRENT. Payload/value updates replace the existing claim and are not versioned. Use a new claim id for a correction or withdrawal whose previous value must remain visible historically. Duplicate keys within a batch use its last row.
  • Edges are daily adjacency. Each typed pair/day retains the latest valid observation and its payload, with the earliest known time across duplicates, backfills and replay. Both mirror rows share these values, including when replay repairs a missing mirror. as_of controls visibility, not historical versions of an edge's intraday weight/payload. Evidence and counts belong in claims.
  • Not atomic across tables. A batch is written nodes, docs, claims (then current state), edges, and can be written again after a failure. Readers may briefly see a claim before its edge. Replay repairs missing HAS_STATE links even when CURRENT was already published. The single writer must serialize complete graph calls, including calls from different threads; table locks do not serialize the graph's read/modify/write sequences. A whole ingest batch can be partially applied on validation error.
  • Bounded reads. neighbors(limit=), walk(max_nodes=, fanout=); search filters by window, subject and doctype before ranking. neighbors(limit=None) disables its default limit. Automatic HAS_STATE links do not consume walk fanout. search(payload=False) returns ranked top-k integer row locations, excluding missing/zero vectors; claims_of(payload=False) returns oldest-first integer locations. Both return an empty integer array when there are no matches. Search filters accept one string/bytes value or an iterable. Only DOCS has the optional vector column; reopening with a different width raises.

Updating prerelease graphs

The earlier kernel lowercased parts of automatic document/claim ids and state keys. Graphs containing uppercase, surrounding spaces, backslashes or separator characters in those inputs can have different derived ids with this corrected kernel. Rebuild those prerelease graphs into a fresh graph name from the original ingest inputs; replay into the old graph does not migrate or remove its old ids. Existing explicit ids are unchanged; node_id changes only for parts containing backslashes or separator characters. No existing graph data is migrated automatically.

Measured (2026Q3 earnings, 714 issuers, one host)

Ingest (warm): 18-28k docs/s with 4096-d vectors, 35k claims/s, 53k edges/s. context() for one company with state, peers and 8 nearest documents: p50 1.0 ms. Sector view over all members: 6-62 ms. Text query over all documents: 3-15 ms.