Skip to main content

Graph-based corpus engine for annotated text with efficient traversal and search

Project description

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.

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

context_fabric-0.5.6.tar.gz (142.5 kB view details)

Uploaded Source

Built Distribution

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

context_fabric-0.5.6-py3-none-any.whl (160.7 kB view details)

Uploaded Python 3

File details

Details for the file context_fabric-0.5.6.tar.gz.

File metadata

  • Download URL: context_fabric-0.5.6.tar.gz
  • Upload date:
  • Size: 142.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for context_fabric-0.5.6.tar.gz
Algorithm Hash digest
SHA256 bfec132abfb343ed2621c8f24df4937f66a896ddc275470ae7c3bbbab51d643a
MD5 903c89a75511bf7e67e20a3fbf50a240
BLAKE2b-256 341aa72326656e6a6a7398baeaea4c26031936333f37c635e0e2d882958e94d2

See more details on using hashes here.

File details

Details for the file context_fabric-0.5.6-py3-none-any.whl.

File metadata

  • Download URL: context_fabric-0.5.6-py3-none-any.whl
  • Upload date:
  • Size: 160.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for context_fabric-0.5.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b85ba9ab381a789fdb7a16e7a9c2bc48a2d8d863899e2e2c0eac71b8a5513fcf
MD5 cbc2e54de315e61575462bab2ba1e50f
BLAKE2b-256 2340319d2d28a2de443160b95d07125efe47164c895eb7d8857bb3eef21454f0

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