Skip to main content

Context Fabric

Context-Fabric

A graph-based corpus engine for annotated text with efficient traversal and search.

Overview

Context-Fabric provides a powerful data model for working with annotated text corpora as graphs. It enables efficient navigation, feature lookup, and pattern-based search across large textual datasets.

Forked from Dirk Roorda's Text-Fabric.

Installation

pip install context-fabric

Quick Start

from cfabric.core import Fabric

# Load a dataset
CF = Fabric(locations='path/to/data')
api = CF.load('feature1 feature2')

# Navigate nodes
for node in api.N.walk():
    print(api.F.feature1.v(node))

# Use locality
embedders = api.L.u(node)
embedded = api.L.d(node)

Core API

  • N (Nodes) - Walk through nodes in canonical order
  • F (Features) - Access node feature values
  • E (Edges) - Access edge feature values
  • L (Locality) - Navigate between related nodes
  • T (Text) - Retrieve text representations
  • S (Search) - Search using templates

Performance

Context-Fabric uses memory-mapped numpy arrays for dramatically faster loading and reduced memory consumption compared to Text-Fabric's pickle-based caching.

Benchmarks (BHSA Hebrew Bible corpus — 1.4M nodes, 109 features)

Metric Text-Fabric Context-Fabric Improvement
Load Time 7.9s 0.7s 11x faster
Memory Usage 6.3 GB 305 MB 95% reduction
Compile Time 8s 91s one-time cost
Cache Size 138 MB 859 MB 6x larger

Performance Comparison

The key insight: compilation happens once, loading happens every session. Context-Fabric trades one-time compile cost for dramatic runtime efficiency:

  • Memory-mapped arrays: Data stays on disk, accessed on-demand
  • Efficient sparse iteration: Uses numpy vectorized operations instead of Python loops
  • Cached materialization: Dictionary views computed once per session

Parallel Worker Scaling

Memory-mapped arrays enable efficient parallel processing. Multiple workers share the same mmap'd data instead of each loading a full copy into RAM.

Spawn mode (cold start — each worker loads independently):

Metric Text-Fabric Context-Fabric Savings
Total (4 workers) 7.7 GB 1.3 GB 84% less
Per worker 1.9 GB 315 MB 6x less

Fork mode (API scenario — pre-load then fork workers):

Metric Text-Fabric Context-Fabric Savings
Total (4 workers) 6.3 GB 398 MB 94% less
Per worker 1.6 GB 99 MB 16x less

Memory measured as total RSS after loading from cache on BHSA corpus.

Run the benchmark yourself:

python benchmarks/compare_performance.py --source path/to/tf/data --workers 4

Testing

See TESTING.md for how to run tests.

Authors

  • Cody Kingham
  • Dirk Roorda

License

MIT License - see LICENSE for details.

Metadata

Release files for context-fabric 0.5.9

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

Source distribution (sdist)

Source distribution for context-fabric 0.5.9
File Size Uploaded Provenance Actions
context_fabric-0.5.9.tar.gz 143.9 kB Without provenance Details for context_fabric-0.5.9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for context-fabric 0.5.9
File Interpreter ABI Platform Actions
context_fabric-0.5.9-py3-none-any.whl Python 3 none any Details for context_fabric-0.5.9-py3-none-any.whl

Total release size: 305.9 kB

Release files / context_fabric-0.5.9.tar.gz

Download URL context_fabric-0.5.9.tar.gz
Size 143.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0f8b5732e2e419b809ad7b1d44c21bb27a76a89f48231c422619b5f2a4e339cb
BLAKE2b-256 checksum
How to use checksums
370780482075af10f2dc570ff9e35f7bad7d1542a60b73776bf2004e8f00cc37
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.5.9-py3-none-any.whl

Download URL context_fabric-0.5.9-py3-none-any.whl
Size 162.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79fdb95b9989119b5aed71506aec4903aa103f15466b6a95bd77e912f22e702c
BLAKE2b-256 checksum
How to use checksums
9b2d0558609b77c7b5fb5de08e6f27f61f9996ab8417916431807a88c7930649
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.5.9

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.

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