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
TF = Fabric(locations='path/to/data')
api = TF.load('feature1 feature2')

# Navigate nodes
for node in api.N():
    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.0s 2.4s 2.9x faster
Memory Usage 6.1 GB 1.6 GB 74% reduction
Compile Time 7s 91s 13x slower
Cache Size 138 MB 859 MB 6.2x larger

Performance Comparison

The key insight: compilation happens once, loading happens every session. Context-Fabric optimizes for the common case with:

  • 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) 9.8 GB 3.3 GB 66% less
Per worker 2.5 GB 821 MB 3x less

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

Metric Text-Fabric Context-Fabric Savings
Total (4 workers) 5.8 GB 440 MB 92% less
Per worker 1.5 GB 110 MB 13x less

Measured with USS (Unique Set Size) which correctly excludes shared mmap pages.

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.1.0.tar.gz (119.3 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.1.0-py3-none-any.whl (130.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: context_fabric-0.1.0.tar.gz
  • Upload date:
  • Size: 119.3 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.1.0.tar.gz
Algorithm Hash digest
SHA256 4bd1ef3e5f67a1b89739d014a4335482690704c819d639dcdef1c41f7a4f39bd
MD5 7d0c22ec6cae5db7221e406a14bb8f17
BLAKE2b-256 38b40bb5282cace55862a5ff3d4b531864f7ed8ec3fd3f76bfac77d25119e07d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: context_fabric-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 130.5 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 46c2cdadd8b75a870368155908a44a59b8dbbbb36d575f86c6d40d6efcb64931
MD5 f6bc0bdf0c25bd79339d2f732ae8aec1
BLAKE2b-256 b0ee353623616702689907a52397aacfc4be054f711020f4d0693eefcf93c23a

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