Context-Fabric
A graph-based corpus engine for annotated text with efficient traversal and search.
Overview
Context-Fabric works with annotated text corpora as graphs: nodes (words, phrases, verses, books, ...) carry feature values, edges relate nodes, and templates search for structural patterns. It reads Text-Fabric datasets and keeps the Text-Fabric API, on a Rust core that serves every query from a memory-mapped compiled cache.
Forked from Dirk Roorda's Text-Fabric.
Installation
pip install context-fabric
Requires Python 3.13 or later. Wheels are built for Linux (x86_64, aarch64), macOS (arm64, x86_64) and Windows (x86_64); other platforms build from the source distribution, which needs a Rust toolchain.
Optional extras:
| Extra | Adds |
|---|---|
context-fabric[numpy] |
NumPy, for F.<feature>.vs_array |
context-fabric[download] |
huggingface_hub, for cfabric.download |
context-fabric[mcp] |
the cfabric-mcp server for AI agents |
context-fabric[benchmarks] |
the cfabric-benchmarks suite |
Quick start
from cfabric import Fabric
CF = Fabric(locations="path/to/tf")
api = CF.loadAll() # or CF.load("sp lex") for selected features
F, L, T, S = api.F, api.L, api.T, api.S
for word in F.otype.s("word")[:5]:
clause = L.u(word, otype="clause")[0]
print(T.sectionFromNode(word), F.sp.v(word), T.text(clause))
for (phrase, word) in S.search("""
phrase function=Pred
word sp=verb
""", limit=5):
print(T.text(phrase))
The first load of a corpus compiles its .tf files into a .cfr cache in
<corpus>/.cfr/4/ (or, when that directory is read-only, under
cfabric.get_cache_dir(): $CFABRIC_CACHE, else the platform cache
directory). Later loads map the cache and are near-instant; the cache is
rebuilt when a .tf file changes or a release changes the cache format.
Core API
- N (Nodes): walk nodes in canonical order
- F (Features): node feature values
- E (Edges): edge feature values
- L (Locality): embedders, embeddees, neighbours of nodes
- T (Text): text formats, sections, structure
- S (Search): search templates
- C (Computed): precomputed data (levels, order, rank, levUp, levDown, ...)
Text-Fabric compatibility
Context-Fabric keeps the tf.core API: Fabric (also importable as
cfabric.fabric.Fabric), the api object with its aliases (Feature, Fs,
AllFeatures, TF, ...), and the F/E/C/L/N/T/S members keep Text-Fabric's
names, signatures, and return types; tests/python/test_tf_api_surface.py
checks this against Text-Fabric 13. Search templates parse as in Text-Fabric,
and .tf files written by TF.save load in Text-Fabric. On BHSA, the 34
reference ETCBC queries return Text-Fabric's result sets.
Differences from Text-Fabric
- Result order: search results come in a deterministic order that can differ from Text-Fabric's (which depends on its search strategy); results match as sets. Within a result tuple, nodes follow the template's atoms.
- Bad search templates raise
cfabric.SearchTemplateError(aValueError) carrying Text-Fabric's messages, where Text-Fabric prints them and returns no results;S.studyrecords them onS.exeas Text-Fabric does. Quantifier sub-templates are checked with the template rather than when the quantifier runs. Regular expressions follow Rust'sregexsyntax (no look-around or backreferences). S.search/S.fetchwithout a limit return a lazySearchResultIteratorwhere Text-Fabric returns a generator; results stop at Text-Fabric's fail limit (4 * maxNode) with its cut-off message as aUserWarning, and Ctrl-C interrupts a running search. A feature repeated within one atom applies every condition (Text-Fabric keeps the last).S.count()returns the count.- Node lists:
N.sortNodes,N.walk(nodes=...)and searchsets=raiseIndexErrorfor a number that is not a node (1tomaxNode). silentand progress options are accepted; only theTF.info/warning/errormessages honorsilent.C.levUp/C.levDownare lazy sequences indexed like Text-Fabric's tuples;row(n)reads one node's row.- Slot and level rows (
E.oslots.s,E.oslots.data,C.levDown.data,C.rank.data) are tuples where Text-Fabric hasarray('I'). T.nodeFromSectionmatches section values regardless of str/int type (Text-Fabric needs the feature's type);T.nodeFromHeadingis type-exact.TF.featuresentries describe the feature files but carry nodata; feature data is read throughF/E/C.- Additions:
F.otype.freqList,E.oslots.f/t/b,E.oslots.dataInv, and the batch callsF.<feature>.vs/vs_array,L.u_many/L.d_many,T.text_many. - Out of scope: volumes/works and MQL.
Performance
Measured on BHSA (Hebrew Bible, 1.4M nodes, 109 features) against Text-Fabric
13.0.19 on the same machine with cfabric_benchmarks.perf_gate
(libs/benchmarks/baselines/cf_0.6.0_record.json and bhsa_tf.json):
| Text-Fabric | Context-Fabric | |
|---|---|---|
| Load (compiled) | 4.3 s | 0.003 s |
| Memory added by loading | 6.1 GB | 8 MB |
| Peak memory after the gate workload | 6.3 GB | 262 MB |
| 12 gate queries, total | 2.36 s | 0.19 s |
| First load (compiles the cache) | ~38 s | ~30 s |
| Cache on disk | 138 MB | 614 MB |
Steady-state latency per call, µs:
| Call | Text-Fabric | Context-Fabric |
|---|---|---|
F.sp.v |
0.064 | 0.028 |
E.mother.f |
0.033 | 0.031 |
E.mother.t |
0.044 | 0.029 |
L.u |
0.115 | 0.144 |
L.d |
0.608 | 0.153 |
L.n / L.p |
0.250 / 0.212 | 0.113 / 0.099 |
L.i |
5.25 | 0.75 |
T.sectionFromNode |
5.68 | 0.51 |
T.text (verse) |
9.35 | 1.64 |
T.nodeFromSection |
0.223 | 0.202 |
L.u and a full N.walk() (17 ms vs 11 ms) build fresh Python ints where
Text-Fabric returns pre-built tuples. Because the corpus stays memory-mapped,
worker processes share its pages instead of each holding a copy, which suits
multi-worker API deployments.
Run the gate (from outside the repository root):
pip install "context-fabric[benchmarks]"
python -m cfabric_benchmarks.perf_gate --engine cf --assert --strict
Versioning
Cargo.toml is the single source of truth for the release version (SemVer, e.g.
0.6.0-rc.1). Maturin publishes the wheel under its PEP 440 rendering (0.6.0rc1;
pyproject.toml declares version as dynamic), and build.rs exports the same
rendering to the Rust core, so cfabric.VERSION, cfabric.__version__, and the
banner always equal importlib.metadata.version("context-fabric"). Bump the
version in Cargo.toml only.
Development
See TESTING.md for building and testing, and the changelog.
Authors
- Cody Kingham
- Dirk Roorda
License
MIT License - see LICENSE for details.
Metadata
Release files for context-fabric 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| context_fabric-0.6.0.tar.gz | 298.0 kB | Without provenance | Details for context_fabric-0.6.0.tar.gz |
Built distributions (wheels)
Total release size: 11.5 MB
Release files / context_fabric-0.6.0.tar.gz
| Download URL | context_fabric-0.6.0.tar.gz |
|---|---|
| Size | 298.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c9d84b7f2180d7418ecb1204b3e6e29c152aa9323e47790a8552ab0a06caf192
|
|
BLAKE2b-256 checksum How to use checksums |
7f147613d2f6acebdd31a2d5109e0c1b40af2188c2fe70ca132fc3a3c7e12a4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.18
|
Release files / context_fabric-0.6.0-cp313-abi3-win_amd64.whl
| Download URL | context_fabric-0.6.0-cp313-abi3-win_amd64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.13 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
fc3cfc7de61056a2cab1686ea3e852db762fb3ef41b1516fd97c36a03c935672
|
|
BLAKE2b-256 checksum How to use checksums |
4961a5d3c42c6cb56caa55760f99b22a15dcc4b90408d85fd3f91bd8e6bc2446
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.18
|
Release files / context_fabric-0.6.0-cp313-abi3-win32.whl
| Download URL | context_fabric-0.6.0-cp313-abi3-win32.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.13 Windows x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
e3702d74452ee8d4d2ab9ef13eb36803631f0be014c8700b4a9be52725c0b879
|
|
BLAKE2b-256 checksum How to use checksums |
c253a1c3c7607d84a46156a93d0bf1f557c5e0caa6ae2c33eddcbf5b2de4930f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.18
|
Release files / context_fabric-0.6.0-cp313-abi3-manylinux_2_28_x86_64.whl
| Download URL | context_fabric-0.6.0-cp313-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 2.0 MB |
| Tags | CPython 3.13 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
ad4cd7dd1a9f30d15146006e436c3146a23cace141a166e78f84c0b8a905eca1
|
|
BLAKE2b-256 checksum How to use checksums |
c92e5ed4f6e29566eb9937718eed896ba8ad98bd35c1afc5ade434aaeb90dfa9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.18
|
Release files / context_fabric-0.6.0-cp313-abi3-manylinux_2_28_aarch64.whl
| Download URL | context_fabric-0.6.0-cp313-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 2.0 MB |
| Tags | CPython 3.13 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
ae124fbe0db8b375593e1723551c130abf3e485ba804138dbbba32a9173deb5e
|
|
BLAKE2b-256 checksum How to use checksums |
3b9275f0a28474af1126d062b9a9b8f9b59e6631d46d5bc2f380ca099dba8746
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.18
|
Release files / context_fabric-0.6.0-cp313-abi3-macosx_11_0_x86_64.whl
| Download URL | context_fabric-0.6.0-cp313-abi3-macosx_11_0_x86_64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.13 abi3 macOS 11.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
909dc98099f3e28addce55590fee7d99584c98edfccc5a4277d64232946648b9
|
|
BLAKE2b-256 checksum How to use checksums |
c8b5e419cf9af7d422fb4bb3382fbcf0be877b143114a4405a7dd3f486785caa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.18
|
Release files / context_fabric-0.6.0-cp313-abi3-macosx_11_0_arm64.whl
| Download URL | context_fabric-0.6.0-cp313-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.13 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ed2706b7e322963b48ffc5cf4b5e0f907d20a8ff746debe36c707d55723115bb
|
|
BLAKE2b-256 checksum How to use checksums |
2a3fc7c8323ebd5a4e17cc771764f93ee6f876d57254f8fb4eb0142858039d9d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.18
|
Security for context-fabric 0.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.