factblock 1.0.0a1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. factblock-1.0.0a1/.github/ISSUE_TEMPLATE/bug.md +18 -0
  2. factblock-1.0.0a1/.github/ISSUE_TEMPLATE/config.yml +5 -0
  3. factblock-1.0.0a1/.github/ISSUE_TEMPLATE/writer.md +15 -0
  4. factblock-1.0.0a1/.github/social-preview.html +22 -0
  5. factblock-1.0.0a1/.github/social-preview.png +0 -0
  6. factblock-1.0.0a1/.github/workflows/release.yml +18 -0
  7. factblock-1.0.0a1/.github/workflows/test.yml +20 -0
  8. factblock-1.0.0a1/.gitignore +5 -0
  9. factblock-1.0.0a1/CHANGELOG.md +33 -0
  10. factblock-1.0.0a1/CODE_OF_CONDUCT.md +13 -0
  11. factblock-1.0.0a1/CONTRIBUTING.md +48 -0
  12. factblock-1.0.0a1/LICENSE +202 -0
  13. factblock-1.0.0a1/PKG-INFO +184 -0
  14. factblock-1.0.0a1/README.md +154 -0
  15. factblock-1.0.0a1/RELEASING.md +50 -0
  16. factblock-1.0.0a1/SPEC.md +223 -0
  17. factblock-1.0.0a1/bench/streamingqa/.gitignore +1 -0
  18. factblock-1.0.0a1/bench/streamingqa/README.md +65 -0
  19. factblock-1.0.0a1/bench/streamingqa/run.py +117 -0
  20. factblock-1.0.0a1/duckdb/factblock.sql +50 -0
  21. factblock-1.0.0a1/factblock/__init__.py +30 -0
  22. factblock-1.0.0a1/factblock/__main__.py +237 -0
  23. factblock-1.0.0a1/factblock/adapters/__init__.py +2 -0
  24. factblock-1.0.0a1/factblock/adapters/factcheck.py +106 -0
  25. factblock-1.0.0a1/factblock/adapters/graphiti.py +110 -0
  26. factblock-1.0.0a1/factblock/bundle.py +89 -0
  27. factblock-1.0.0a1/factblock/claimreview.py +64 -0
  28. factblock-1.0.0a1/factblock/extract.py +174 -0
  29. factblock-1.0.0a1/factblock/leak.py +37 -0
  30. factblock-1.0.0a1/factblock/okf.py +91 -0
  31. factblock-1.0.0a1/factblock/parquet.py +84 -0
  32. factblock-1.0.0a1/factblock/profiles/claims/edge-types.json +10 -0
  33. factblock-1.0.0a1/factblock/profiles/claims/instructions.md +16 -0
  34. factblock-1.0.0a1/factblock/profiles/claims/output.schema.json +51 -0
  35. factblock-1.0.0a1/factblock/recall.py +57 -0
  36. factblock-1.0.0a1/factblock/resolve.py +78 -0
  37. factblock-1.0.0a1/factblock/scan.py +74 -0
  38. factblock-1.0.0a1/factblock/sync.py +146 -0
  39. factblock-1.0.0a1/factblock/validate.py +98 -0
  40. factblock-1.0.0a1/factblock/why.py +57 -0
  41. factblock-1.0.0a1/pyproject.toml +49 -0
  42. factblock-1.0.0a1/samples/cramer/README.md +23 -0
  43. factblock-1.0.0a1/samples/cramer/edges.jsonl +1169 -0
  44. factblock-1.0.0a1/samples/cramer/factblock.json +2629 -0
  45. factblock-1.0.0a1/samples/cramer/nodes.jsonl +2091 -0
  46. factblock-1.0.0a1/samples/cramer/resolutions.jsonl +779 -0
  47. factblock-1.0.0a1/samples/demo.gif +0 -0
  48. factblock-1.0.0a1/samples/demo.tape +33 -0
  49. factblock-1.0.0a1/samples/rates/edges.jsonl +3 -0
  50. factblock-1.0.0a1/samples/rates/factblock.json +65 -0
  51. factblock-1.0.0a1/samples/rates/nodes.jsonl +6 -0
  52. factblock-1.0.0a1/samples/rates/resolutions.jsonl +3 -0
  53. factblock-1.0.0a1/samples/rates-questions.jsonl +3 -0
  54. factblock-1.0.0a1/tests/fixtures/factcheck-sample.json +19 -0
  55. factblock-1.0.0a1/tests/test_claimreview.py +33 -0
  56. factblock-1.0.0a1/tests/test_duckdb.py +31 -0
  57. factblock-1.0.0a1/tests/test_extract.py +53 -0
  58. factblock-1.0.0a1/tests/test_factcheck.py +41 -0
  59. factblock-1.0.0a1/tests/test_graphiti_adapter.py +45 -0
  60. factblock-1.0.0a1/tests/test_leak.py +28 -0
  61. factblock-1.0.0a1/tests/test_okf.py +30 -0
  62. factblock-1.0.0a1/tests/test_rates.py +95 -0
  63. factblock-1.0.0a1/tests/test_recall.py +26 -0
  64. factblock-1.0.0a1/tests/test_sync.py +84 -0
  65. factblock-1.0.0a1/tests/test_why.py +37 -0
  66. factblock-1.0.0a1/uv.lock +1045 -0
@@ -0,0 +1,18 @@
1
+ ---
2
+ name: Bug
3
+ about: Something reads, writes or validates differently from what SPEC.md says
4
+ title: ""
5
+ labels: bug
6
+ ---
7
+
8
+ **What you ran**
9
+
10
+ ```
11
+ factblock ...
12
+ ```
13
+
14
+ **What came out, and what you expected**
15
+
16
+ **A bundle that shows it** (a few JSONL lines are enough; `factblock sample` plus one edit is ideal)
17
+
18
+ **Version**: `pip show factblock` or the commit, and Python version.
@@ -0,0 +1,5 @@
1
+ blank_issues_enabled: true
2
+ contact_links:
3
+ - name: Question
4
+ url: https://github.com/factagora/factblock/discussions
5
+ about: How to use it, what a field means, whether something fits the format
@@ -0,0 +1,15 @@
1
+ ---
2
+ name: New writer, reader or projection
3
+ about: Propose an adapter for a store or feed, or a projection to another standard
4
+ title: ""
5
+ labels: proposal
6
+ ---
7
+
8
+ **What it reads or writes** (the store, feed or standard, with a link to its format)
9
+
10
+ **How its clocks map**: where `asserted_at`, `valid_from`/`valid_to` and `known_at` come from, and what is
11
+ self-reported (self-reported knowledge time becomes a declared backfill batch, SPEC.md section 6).
12
+
13
+ **What the projection loses**, if it is a projection.
14
+
15
+ **Will you maintain it?** A writer or reader maintained outside this repository is what takes the format to 1.0.0.
@@ -0,0 +1,22 @@
1
+ <!doctype html><html><head><meta charset="utf-8"><style>
2
+ *{margin:0;padding:0;box-sizing:border-box}
3
+ body{width:1280px;height:640px;background:#1e1e2e;color:#cdd6f4;font-family:"DejaVu Sans Mono",Menlo,monospace;padding:64px 72px 56px;display:flex;flex-direction:column;justify-content:space-between}
4
+ h1{font-size:76px;font-weight:700;letter-spacing:-1px;color:#cdd6f4}
5
+ h1 span{color:#89b4fa}
6
+ .tag{margin-top:14px;font-size:30px;color:#bac2de;line-height:1.35}
7
+ .tag b{color:#f9e2af;font-weight:700}
8
+ .term{border:1px solid #45475a;border-radius:8px;padding:22px 26px;font-size:19px;line-height:1.55;background:#181825}
9
+ .p{color:#a6e3a1}.d{color:#6c7086}.r{color:#f5c2e7}.c{color:#89dceb}
10
+ .foot{display:flex;justify-content:space-between;font-size:20px;color:#7f849c}
11
+ </style></head><body>
12
+ <div><h1>Fact<span>Block</span></h1>
13
+ <div class="tag">Agent memory for decisions. A temporal causal knowledge graph<br>that remembers <b>when</b> and <b>why</b> for your AI.</div></div>
14
+ <div class="term">
15
+ <div><span class="p">$</span> factblock why samples/cramer 1b77a1a8 --as-of 2026-09-10</div>
16
+ <div><span class="r">subject</span>: <span class="d">2025-07-17</span> The data center buildout is the largest construction boom since WWII.</div>
17
+ <div>&nbsp;&nbsp;&nbsp;&nbsp;<span class="r">effect (CAUSES)</span>: <span class="d">2025-07-17</span> Lead contractors are receiving strong data center orders.</div>
18
+ <div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="r">effect (CAUSES)</span>: <span class="d">2025-07-17</span> Eaton is a good stock to own.</div>
19
+ <div><span class="c">as of 2025-01-01: not_yet</span> <span class="d">hidden: 1790 blocks learned later</span></div>
20
+ </div>
21
+ <div class="foot"><span>github.com/factagora/factblock</span><span>pip install factblock · Apache-2.0</span></div>
22
+ </body></html>
@@ -0,0 +1,18 @@
1
+ name: release
2
+ on:
3
+ push:
4
+ tags: ["v*"]
5
+ jobs:
6
+ pypi:
7
+ runs-on: ubuntu-latest
8
+ environment: pypi
9
+ permissions:
10
+ id-token: write
11
+ contents: read
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - uses: astral-sh/setup-uv@v5
15
+ - run: uv sync
16
+ - run: for t in tests/test_*.py; do uv run python $t; done
17
+ - run: uv build
18
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,20 @@
1
+ name: test
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ runs-on: ubuntu-latest
6
+ steps:
7
+ - uses: actions/checkout@v4
8
+ - uses: astral-sh/setup-uv@v5
9
+ - run: uv sync
10
+ - run: uv run python tests/test_rates.py
11
+ - run: uv run python tests/test_graphiti_adapter.py
12
+ - run: uv run python tests/test_duckdb.py
13
+ - run: uv run python tests/test_extract.py
14
+ - run: uv run python tests/test_why.py
15
+ - run: uv run python tests/test_leak.py
16
+ - run: uv run python tests/test_recall.py
17
+ - run: uv run python tests/test_sync.py
18
+ - run: uv run python tests/test_claimreview.py
19
+ - run: uv run python tests/test_okf.py
20
+ - run: uv run python tests/test_factcheck.py
@@ -0,0 +1,5 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ dist/
5
+ .DS_Store
@@ -0,0 +1,33 @@
1
+ # Changelog
2
+
3
+ ## 1.0-draft.1 (2026-10-04)
4
+
5
+ First public draft of the format and the reference library.
6
+
7
+ - Five invariants (three clocks, attested knowledge time, append-only, typed edges, declared facts) with one validator check id each.
8
+ - Logical model: node, edge, resolution, declarations (facts, backfill batches, edge types, embedding model).
9
+ - JSONL and Parquet profiles; Parquet files sorted by `known_at`, unknown fields kept in `extra`.
10
+ - Read semantics: as-of with certificate, `valid_at` defaulting to `as_of`, supersession, `resolve` by declared policy, expansion.
11
+ - Readers: the Python library (`scan`, `validate`, `resolve`, `write_parquet`) and the DuckDB macro pack.
12
+ - Writers: the tckg ledger (`GET /v1/export`) and the Graphiti adapter.
13
+
14
+ ### Added (2026-10-05)
15
+ - `factblock extract`: text in, a batch of blocks out, through a model you choose (`gemini`, `openai`, or `fake` for offline runs). The claims profile lives in `factblock/profiles/claims/` as three files (instructions, output schema, edge types) so other languages run the same extraction. Every extract declares one backfill batch (SPEC 6: a non-ledger writer never invents `known_at`).
16
+ - `write_bundle(result, out, append=True)` in `factblock.bundle`: a folder grows one batch at a time and stays valid; entities are reused across batches.
17
+ - README rewritten as the project's front door: agent memory for decisions.
18
+ - `factblock why <bundle> <node_id> --as-of T [--valid-at T] [--depth N]` and `factblock.why()`: the chain behind one block on files, mirroring tckg's `why`. Both directions over causal, argumentative and temporal edges, a role at every hop, `not_yet` or `absent` when the root is not visible yet (SPEC 4.5).
19
+ - `factblock leak <bundle> <questions.jsonl>` and `factblock.leak()`: for a question set with `asked_at` and the block ids each answer rests on, which answers depend on blocks learned after the question was asked (`known_later`) or not in force then (`not_in_force`), per question and as a rate. Exit code 1 on any leak. Sample set: `samples/rates-questions.jsonl`.
20
+ - `factblock sync <bundle> <url> --space S [--token T] [--as-of T] [--push-only | --pull-only]` and `factblock.sync(bundle, store)`: a folder and a store, both ways, by identity. Rows only the folder has go up under the folder's batches; rows only the store has come down with the store's `known_at`; a second run is a no-op; `--pull-only` into a new folder clones a space. `Store` is a two-method protocol (`pull`, `push`); `TckgStore` speaks tckg's HTTP API with no dependency beyond the standard library. SPEC 6.1 states the import rule (declare the bundle's batches, never adopt a row as learned now).
21
+ - `write_bundle` writes a `resolutions` table when given one and serialises datetimes.
22
+ - `factblock to-claimreview <bundle> --as-of T [--base-url U]` and `factblock.to_claimreview()`: the verdicts visible as of an instant as schema.org ClaimReview JSON-LD (SPEC 9.2). Latest verdict per block, ratings from the new recommended `outcome` vocabulary (SPEC 3.6), the rest under `factblock:` keys.
23
+ - SPEC 3.1 names the payload conventions `extract` already writes (`speaker`, `quote`, `source`); SPEC 3.6 adds the recommended verdict vocabulary and the evidence element shape; SPEC 9 becomes two projections (OKF, ClaimReview) with the reverse-direction rule for fact-check feeds.
24
+ - `samples/rates` gains a `resolutions` table: two verdicts and one re-resolution, ledger-stamped, so as-of reads hide verdicts learned later.
25
+ - `factblock to-okf <bundle> <out> --as-of T` and `factblock.to_okf()`: one OKF v0.2 concept document per visible node, relations as links with the relation in prose, `index.md` with the certificate, `log.md` in `known_at` order (SPEC 9.1). No YAML dependency: JSON is YAML.
26
+ - `factblock from-factcheck -o <bundle> (--query Q | --from-json FILE)` and `factblock.adapters.factcheck`: fact-checks in the Fact Check Tools API shape become claim nodes and verdict rows, each under a batch declared at its review date; `textualRating` is normalised to the recommended vocabulary where it fits and kept verbatim as `value`; re-import adds nothing. Live search needs `$FACTCHECK_API_KEY`.
27
+ - SPEC 3.5 adds the `org:<id>` actor shape for publishers and institutions.
28
+ - CLI: `factblock sample <dir>` copies the sample bundle (shipped in the wheel); `scan`, `why` and `resolve` print for people by default and take `--json`; every subcommand has help text and they are listed in the order you meet them. `extract` writes 8-character ids you can type.
29
+ - Repository: CONTRIBUTING (DCO), RELEASING, CODE_OF_CONDUCT, issue templates.
30
+ - `factblock recall <bundle> "<query>" --as-of T [--limit N] [--all-kinds]` and `factblock.recall()` / `factblock.context()`: the blocks about something as of an instant, ranked by query hits then recency, with the certificate. Keyword matching only; no embeddings yet.
31
+ - `samples/cramer`: a real bundle. Jim Cramer on CNBC, 2024-09 to 2026-09: 2,091 blocks under one backfill batch per recording, 1,169 typed links, 779 calls settled at their horizon as resolution rows. README's "What comes out" shows it. The reader test reads it at three instants.
32
+ - CLI exits quietly when its output pipe closes (`| head`).
33
+ - `bench/streamingqa`: the hindsight number. StreamingQA's 36,378 dated questions as dated blocks; a time-ignorant top-5 recall leaks on 79.7% of questions (41.8% of picks), the as-of recall on none. `factblock.scan` now wraps a table-free `visible()` and `recall` keeps per-node word sets; a recall over 36,378 blocks takes under a second
@@ -0,0 +1,13 @@
1
+ # Code of conduct
2
+
3
+ This project is a place to work on a format and a library. Everyone is welcome to report, ask, propose and
4
+ contribute, whoever they are and wherever they come from.
5
+
6
+ **Expected**: be direct and be kind. Disagree with the idea, not the person. Assume the other side has a reason
7
+ you have not heard yet. Say what you need; answer what was asked.
8
+
9
+ **Not accepted**: harassment, personal attacks, discriminatory remarks, publishing someone's private information,
10
+ and sustained disruption of a thread after being asked to stop.
11
+
12
+ Maintainers may edit or remove comments, close threads and, for repeated or severe cases, block an account from
13
+ the repository. Report a problem to randy@factagora.com; reports are read by a person and handled in private.
@@ -0,0 +1,48 @@
1
+ # Contributing
2
+
3
+ FactBlock is a format first and a library second. The spec ([SPEC.md](./SPEC.md)) is normative; the
4
+ Python package is the reference implementation. A change to one usually means a change to the other.
5
+
6
+ ## Before you open a pull request
7
+
8
+ ```bash
9
+ uv sync
10
+ for t in tests/test_*.py; do uv run python $t; done # the same checks CI runs
11
+ uv run python -m factblock validate samples/rates
12
+ ```
13
+
14
+ Every test file is one script that prints `PASS ...` or raises. Add a check to the file that covers
15
+ what you changed, or a new `tests/test_<thing>.py` and a line in `.github/workflows/test.yml`.
16
+
17
+ ## What goes where
18
+
19
+ - **A new field or rule**: SPEC.md first (section 3 or 4), with its validator check id in section 2 or 8,
20
+ then `factblock/validate.py` and a case in `tests/test_rates.py`. Minor versions add fields; they never
21
+ change the meaning of an existing one (section 7).
22
+ - **A new writer or reader** (an adapter for another store or feed): `factblock/adapters/<name>.py`,
23
+ one test with a synthetic fixture under `tests/fixtures/`, a line in SPEC.md section 10. The one rule
24
+ every writer keeps is section 6: never invent `known_at`; declare a backfill batch instead.
25
+ - **A new projection** (another standard a bundle should speak): `factblock/<name>.py`, a subsection
26
+ under SPEC.md section 9 with the mapping table and what the projection loses.
27
+ - **Extraction rules** live in `factblock/profiles/claims/` as three files, not in code, so that other
28
+ languages run the same extraction. Change the files; keep `extract.py` thin.
29
+
30
+ No new runtime dependencies without a reason in the pull request. The core depends on `pyarrow` only;
31
+ model SDKs are optional extras.
32
+
33
+ ## Developer Certificate of Origin
34
+
35
+ Contributions are accepted under the [Developer Certificate of Origin 1.1](https://developercertificate.org/):
36
+ by signing off a commit you state that you wrote the change or have the right to submit it under the
37
+ project's license (Apache-2.0). Sign off with `git commit -s`, which adds
38
+
39
+ ```
40
+ Signed-off-by: Your Name <you@example.com>
41
+ ```
42
+
43
+ There is no separate contributor agreement.
44
+
45
+ ## Style
46
+
47
+ Short files, plain functions, no abstractions for one caller. Prose in English, sentence case, no em
48
+ dashes. A module docstring says what the file does and which SPEC section it implements.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,184 @@
1
+ Metadata-Version: 2.5
2
+ Name: factblock
3
+ Version: 1.0.0a1
4
+ Summary: Agent memory for decisions: extract dated claims and their causal links into a temporal causal knowledge graph you can read as of any instant
5
+ Project-URL: Homepage, https://github.com/factagora/factblock
6
+ Project-URL: Specification, https://github.com/factagora/factblock/blob/main/SPEC.md
7
+ Project-URL: Changelog, https://github.com/factagora/factblock/blob/main/CHANGELOG.md
8
+ Project-URL: Issues, https://github.com/factagora/factblock/issues
9
+ Project-URL: Hosted, https://docs.tckg.factagora.com
10
+ Author-email: Factagora <randy@factagora.com>
11
+ License-Expression: Apache-2.0
12
+ License-File: LICENSE
13
+ Keywords: agent-memory,arrow,as-of,bitemporal,knowledge-graph,parquet
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Database
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Requires-Python: >=3.11
24
+ Requires-Dist: pyarrow>=17
25
+ Provides-Extra: gemini
26
+ Requires-Dist: google-genai>=1.62; extra == 'gemini'
27
+ Provides-Extra: openai
28
+ Requires-Dist: openai>=1.50; extra == 'openai'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # FactBlock: agent memory for decisions
32
+
33
+ [![test](https://github.com/factagora/factblock/actions/workflows/test.yml/badge.svg)](https://github.com/factagora/factblock/actions/workflows/test.yml) [![PyPI](https://img.shields.io/pypi/v/factblock)](https://pypi.org/project/factblock/) [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue)](./LICENSE)
34
+
35
+ **A temporal causal knowledge graph that remembers *when* and *why* for your AI.**
36
+
37
+ ![factblock: scan, recall and why over two years of Jim Cramer's calls, read as of different days](./samples/demo.gif)
38
+
39
+ Your data is full of claims: facts, opinions, predictions, promises. FactBlock extracts them, keeps when they were said and when you learned them, links what caused what, and never overwrites what changed. Your agent recalls them as of any moment, so it decides on what was knowable then, not on hindsight.
40
+
41
+ ```bash
42
+ pip install factblock
43
+ factblock sample brain/ # six dated claims, a reversal, three verdicts
44
+ factblock scan brain/ --as-of 2024-05-01 # what was known that day, and what was hidden
45
+ factblock recall brain/ "interest rates" --as-of 2024-05-01 # the blocks about something, as of that day
46
+ factblock why brain/ c3 --as-of 2024-10-01 # the causal chain behind a block
47
+ factblock resolve brain/ belief:fed:direction --as-of 2024-10-01
48
+ factblock extract transcript.txt --observed-at 2024-03-20 --speaker "Jim Cramer" --backfill -o brain/ # your model key, or --provider fake
49
+ ```
50
+
51
+ ```
52
+ $ factblock why brain/ c3 --as-of 2024-10-01
53
+ subject: c3 2024-06-20 Housing demand falls as mortgages track yields
54
+ cause (CAUSES): c2 2024-04-10 Bond yields rise after the rate hike
55
+ cause (CAUSES): c1 2024-03-20 The Fed raises interest rates
56
+ successor (SUPERSEDES): c4 2024-09-18 The Fed cuts interest rates
57
+ as of 2024-10-01 hidden: 1 resolution backfilled: 9 rows in 3 batches
58
+ ```
59
+
60
+ Run the same command `--as-of 2024-05-01` and the chain stops at `c2`, because `c3` was not known yet. Add `--json` to any read for the machine form.
61
+
62
+ ```python
63
+ import factblock
64
+ print(factblock.context("brain/", "interest rates", as_of="2024-05-01"))
65
+ # - 2024-03-20: The Fed raises interest rates
66
+ # - 2024-04-10: Bond yields rise after the rate hike
67
+ # (as of 2024-05-01; 9 later blocks hidden)
68
+ ```
69
+
70
+ That string goes into your agent's prompt. `factblock.recall(...)` returns the same blocks as dicts with a certificate, and `factblock.scan(...)` returns everything visible as pyarrow tables.
71
+
72
+ `brain/` is a folder of plain files. Commit it to git, query it with DuckDB, hand it to another agent, or [sync it with a hosted ledger](#same-files-hosted). Nothing here needs a server.
73
+
74
+ ## What comes out
75
+
76
+ Two years of one public figure's statements, as files. [`samples/cramer`](./samples/cramer) is Jim Cramer on CNBC, 2024-09 to 2026-09: 2,091 blocks, 1,169 links he drew between them, 779 priced calls scored at their horizon. Every block links to the recording and the timestamp.
77
+
78
+ ```
79
+ $ factblock scan samples/cramer --as-of 2025-01-01 | head -1
80
+ as of 2025-01-01 hidden: 1790 nodes, 1025 edges, 753 resolutions backfilled: 471 rows in 52 batches
81
+
82
+ $ factblock why samples/cramer 1b77a1a885470207 --as-of 2026-09-10
83
+ subject: 1b77a1a885470207 2025-07-17 The current data center buildout is the largest construction boom since World War II.
84
+ effect (CAUSES): c43aac6a842836bf 2025-07-17 Lead contractors such as ABB and Legrand are receiving strong data center orders.
85
+ effect (CAUSES): 041ef1dfd5dbb6df 2025-07-17 Companies involved in the data center buildout, such as Eaton and Parker-Hannifin, are receiving a large number of new orders.
86
+ effect (CAUSES): 2751ba237ecd5415 2025-07-17 Parker-Hannifin is a good stock to own.
87
+ effect (CAUSES): 7d3af08ba4f4f027 2025-07-17 Eaton is a good stock to own.
88
+ ```
89
+
90
+ A call and its verdict carry separate clocks, so the same read gives different answers on different days:
91
+
92
+ ```
93
+ 66027d5985bf9605 prediction 2024-09-11 Nvidia's business is currently growing, not slowing down. NVDA, up
94
+ verdict: came_true decided 2024-12-10 NVDA +23.3% over 90 days known 2024-12-10
95
+ ```
96
+
97
+ As of 2024-11-01 the call is open. As of 2024-12-10 it came true. As of 2024-09-10 it does not exist yet. `to-claimreview samples/cramer --as-of 2025-06-01` writes the 197 verdicts known by then as schema.org JSON-LD.
98
+
99
+ Every block carries two clocks: **asserted_at**, when it was said (`--observed-at` for `extract`), and **known_at**, when your system learned it. By default that is now, so a 2024 transcript extracted today is hidden from a 2024 read; `--backfill` declares it known when it was said, which is what you want for material from the past. `--provider fake` splits sentences without a model, enough to see the files; `gemini` and `openai` do the real extraction with your key. Every edge carries a type with a family (causal, argumentative, temporal) and the speaker's own confidence. Nothing is a chunk, nothing is a bare triple; the unit is a dated statement someone made.
100
+
101
+ ## When
102
+
103
+ Memory that cannot answer "what did I know on that date" leaks the future into every evaluation and every backtest. FactBlock reads are always **as of** an instant:
104
+
105
+ ```python
106
+ import factblock
107
+ r = factblock.scan("brain/", as_of="2024-05-01")
108
+ r.nodes # pyarrow.Table: only blocks known by 2024-05-01
109
+ r.certificate # {'as_of': ..., 'masked': {'node': 4, 'edge': 2}, 'backfill': {'batches': 1, 'rows': 3}}
110
+ ```
111
+
112
+ The certificate says how many rows were hidden because they were learned later, and which rows were backfilled from the past under a declared batch. An answer with masking is a correct answer for that instant, and it says so.
113
+
114
+ A statement that gets corrected or reversed is not overwritten. The new block points at the old one with `SUPERSEDES`, both keep their intervals, and a read as of a date in between still sees the old one. That is how "when did they change their mind" stays answerable.
115
+
116
+ ## Why
117
+
118
+ Edges are the speaker's reasoning, not co-occurrence: `CAUSES`, `CONTRIBUTING_FACTOR`, `TRIGGERS`, `PREVENTS`, `SUPPORTS`, `CONTRADICTS`, `CONCURRENT_SIGNAL`, `SUPERSEDES`. `why` walks them from a block to the given depth, as of an instant, and names the role at every hop (`cause`, `effect`, `successor`, `contradiction`), so the chain never includes a reason that was not yet known.
119
+
120
+ Declared facts make conflicts explicit. Declare `belief:fed:direction` with a policy (`latest_valid`, `latest_observed`, `source_priority`, `strict`) and `resolve` returns one value or the reason there is none: `no_data`, `not_yet`, `no_value_at`, `unresolved_conflict`. It never guesses.
121
+
122
+ ## Claims it is good at
123
+
124
+ | Kind | Example | What you can ask that other memories cannot |
125
+ |---|---|---|
126
+ | **Prediction** | "Yields keep climbing this year" (podcast, 2024-03-20) | What did this person believe on 2024-03-20? Did it come true? When did they say the opposite? |
127
+ | **Stance** | CEO: "No price increase this year" (Jan), "An increase is unavoidable" (Jul) | How did the company's position move? What did we know in May? |
128
+ | **Fact that gets corrected** | "Q2 revenue was $4.1B", restated to $3.9B six weeks later | `resolve` as of August gives $4.1B, as of October $3.9B, as of July `no_data` |
129
+ | **Commitment** | Sales: "We ship SSO by end of Q3" (to customer A) | Which promises to A are past due and unresolved? Recall them before the support agent answers |
130
+ | **Your AI's own assertions** | Assistant: "Your plan includes 10 seats" (to user B) | Which of last month's assertions are now false? Where did each one come from? |
131
+
132
+ The common thread: a claim has a speaker, a time, a reason, and a later verdict. RAG keeps chunks, entity graphs keep triples, chat memories keep summaries. None of them keep that.
133
+
134
+ ## Use it with your AI
135
+
136
+ **Recall as context.** `recall` ranks the visible blocks about a query (keywords over statement, quote and speaker) and `context` turns them into prompt lines, with `as_of` set to the decision time (now, or a past instant for a backtest). `scan` returns everything visible as Arrow tables when you want to build your own.
137
+
138
+ **Analytics.** `to-parquet` writes the Parquet profile. DuckDB reads it with no Python through [`duckdb/factblock.sql`](./duckdb/factblock.sql): `factblock_nodes(bundle, as_of)`, `factblock_edges`, `factblock_certificate`. Spark and Databricks read the same files.
139
+
140
+ **From an existing graph.** [`factblock/adapters/graphiti.py`](./factblock/adapters/graphiti.py) turns a Graphiti graph into a bundle; the store's own timestamps become declared backfill batches, because a store that stamped time itself is a witness.
141
+
142
+ **Speak the standards.** `to-claimreview` writes the verdicts visible as of an instant as schema.org ClaimReview JSON-LD; `to-okf` writes the blocks as an Open Knowledge Format bundle (markdown with frontmatter) that catalogs and agents read; `from-factcheck` brings published fact-checks in (Google's Fact Check Tools API shape) as dated claims with dated verdicts, every row under a batch declared at its review date. None of them is the storage format; they are doors.
143
+
144
+ **Check your evals.** `leak` takes a question set with dates (`{asked_at, evidence: [block ids]}` per line) and reports how many answers depend on blocks learned after the question's date, naming each block and when it became known. It exits non-zero on a leak, so it fits in CI. On [StreamingQA](./bench/streamingqa) (36,378 dated questions about dated news), a recall that ignores time rests on a block learned after the question for **80% of questions**; the same recall as of the question date leaks nothing and says how much it hid. If your memory benchmark never reports this number, it is measuring hindsight.
145
+
146
+ ## Same files, hosted
147
+
148
+ A folder is one writer's memory. [factagora.ai](https://factagora.ai) is where a `brain/` meets other people's. Upload it and it comes back with **more rows, never changed rows**: verdicts on predictions whose horizon has passed (mechanical ones from prices and published figures, judgment calls from the community, each with evidence), links to what other people claimed about the same thing (`SUPPORTS`, `CONTRADICTS`), entities resolved across worldviews. Every added row carries its own `known_at`, stamped by the server rather than by you, so a verdict is as replayable as the claim it judges: as of last June, the prediction was still open.
149
+
150
+ It also gives what a folder cannot: one ledger shared by many agents and users, natural-language writes at scale, and an MCP address per worldview, so a user plugs one into Claude or Cursor and reaches nothing else. Browse public worldviews there, or ask one a question as of a date. `GET /v1/export` hands the folder back at any instant. The format is the contract; you can leave with your files.
151
+
152
+ `factblock sync brain/ <url> --space <space>` moves rows both ways by identity: what only the folder has goes up, what only the ledger has comes down, nothing is changed in place. A row's `known_at` travels as the batch that attests it, so the ledger learns a 2024 transcript as known in 2024, not today, and the folder learns a verdict at the instant the ledger stamped it. Run it again and it is a no-op. `--pull-only` into a folder that does not exist yet clones a space. The token is `$TCKG_TOKEN` or `--token`.
153
+
154
+ **Bring your own store.** `sync` talks to a store through two methods, `pull(as_of)` and `push(manifest, nodes, edges)` ([`factblock/sync.py`](./factblock/sync.py), the `Store` protocol). `TckgStore` is the one for tckg over HTTP; [`tests/test_sync.py`](./tests/test_sync.py) has a forty-line in-memory one that shows the single rule a store has to keep: declare the bundle's batches as your own backfill batches, never adopt an imported row as learned now. A SQLite, Neo4j, or warehouse store is the same two methods.
155
+
156
+ The same ledger runs closed for companies at [app.factagora.com](https://app.factagora.com): your support logs, your sales promises, your own assistant's assertions, as claims with verdicts, inside your tenant.
157
+
158
+ ## The format
159
+
160
+ [`SPEC.md`](./SPEC.md) is short. Five invariants (present, attested, unique, typed, declared), a JSONL profile and a Parquet profile, read semantics, and the conformance checks `validate` runs (eleven of them). Projections to OKF and ClaimReview are described, and `to-claimreview` writes the verdicts visible as of an instant as schema.org JSON-LD, so a bundle can feed systems that speak those.
161
+
162
+ Format, not platform. Apache-2.0. tckg is one writer of this format; nothing here requires it. Contributions are welcome under the DCO: see [CONTRIBUTING.md](./CONTRIBUTING.md).
163
+
164
+ ## Status
165
+
166
+ `1.0-draft.1`. Works today: `extract` (providers `gemini`, `openai`, and `fake` for offline runs; the claims profile is three files under [`factblock/profiles/claims`](./factblock/profiles/claims) that any language can run), `validate`, `scan`, `recall`, `why`, `leak`, `resolve`, `to-parquet`, `sync` with a tckg ledger or a store of your own, `to-claimreview`, `to-okf`, `from-factcheck`, the DuckDB macros, the Graphiti adapter, and the tckg export. Extraction quality on real transcripts is being measured separately; the rules are the ones a dated-claims pipeline has run on hundreds of videos. Next: a PyPI release. The format reaches 1.0.0 when a reader or writer maintained outside this repository exists; until then minor versions may change fields and the manifest's `factblock_version` says which one a bundle speaks.
167
+
168
+ ```bash
169
+ uv sync --extra gemini # or --extra openai; the fake provider needs nothing
170
+ export GEMINI_API_KEY=... # or GOOGLE_GENAI_USE_VERTEXAI=1 GOOGLE_CLOUD_PROJECT=... for Vertex
171
+ echo "The Fed will keep raising rates this year. That means bond yields keep climbing." \
172
+ | uv run python -m factblock extract - --observed-at 2024-03-20 --speaker "Jim Cramer" --backfill -o brain/
173
+ uv run python -m factblock scan brain/ --as-of 2024-05-01
174
+ ```
175
+
176
+ ```bash
177
+ uv sync
178
+ uv run python -m factblock validate samples/rates
179
+ uv run python -m factblock scan samples/rates --as-of 2024-08-01
180
+ uv run python -m factblock why samples/rates c3 --as-of 2024-10-01 --json
181
+ uv run python -m factblock leak samples/rates samples/rates-questions.jsonl
182
+ uv run python -m factblock resolve samples/rates belief:fed:direction --as-of 2024-10-01
183
+ uv run python tests/test_rates.py && uv run python tests/test_why.py && uv run python tests/test_recall.py && uv run python tests/test_leak.py && uv run python tests/test_sync.py && uv run python tests/test_claimreview.py && uv run python tests/test_okf.py && uv run python tests/test_factcheck.py && uv run python tests/test_graphiti_adapter.py && uv run python tests/test_duckdb.py
184
+ ```