Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/exegia/corpora-py/llms.txt

Use this file to discover all available pages before exploring further.

CorpusManager manages a collection of named Text-Fabric (Context-Fabric) corpora. It holds (Fabric, api) pairs keyed by name, giving you a single object that controls which corpus is active and how to access its API. The module-level singleton corpus_manager is pre-instantiated at import time and is used internally by all 11 MCP tools — you can also use it directly in scripts.

Import

from exegia.mcp import corpus_manager
# or
from exegia.mcp.corpus import corpus_manager

Methods

load(path, name=None, features=None)

corpus_manager.load(
    path: str,
    name: str | None = None,
    features: list[str] | None = None,
) -> str
Loads a Text-Fabric corpus from a local directory. Wraps cfabric.Fabric and calls either tf.load(features) or tf.loadAll() depending on whether features is supplied. Sets the loaded corpus as current if it is the first corpus loaded into this manager instance.
path
str
required
Path to the directory containing .tf files. Expanded with Path.expanduser() and resolved to an absolute path before use.
name
str | None
Human-readable name to register the corpus under. Defaults to the basename of path.
features
list[str] | None
Explicit list of feature names to load (e.g. ["otype", "lex", "g_word"]). When omitted, all features are loaded via loadAll().
returns
str
The corpus name used to register it (either the value passed as name or the directory basename).
Raises
ExceptionCondition
FileNotFoundErrorpath does not exist on disk
RuntimeErrorcfabric.Fabric.load() returns False
ImportErrorcontext-fabric is not installed

get_api(name=None)

corpus_manager.get_api(name: str | None = None) -> Any
Returns the Text-Fabric API object for the named corpus. When name is omitted, the currently active corpus is used. The returned object exposes the standard TF API surfaces: api.S (search), api.F (features), api.T (text), api.L (locality), and others.
name
str | None
Name of the corpus to retrieve. Defaults to corpus_manager.current.
returns
Any
The Text-Fabric API object for the requested corpus.
Raises
ExceptionCondition
RuntimeErrorNo corpus has been loaded yet
KeyErrorA named corpus was requested but is not registered

list_corpora()

corpus_manager.list_corpora() -> list[str]
Returns a list of all corpus names that are currently loaded in the manager, in insertion order.
returns
list[str]
Ordered list of loaded corpus names.

select(name)

corpus_manager.select(name: str) -> None
Sets the named corpus as the active default for all subsequent calls that do not specify a name. Does not reload or modify the corpus data.
name
str
required
Name of a corpus that is already loaded.
Raises
ExceptionCondition
KeyErrorThe corpus has not been loaded

unload(name)

corpus_manager.unload(name: str) -> None
Removes a corpus from the manager and frees the reference to its (Fabric, api) tuple. If the removed corpus was the active current, resets current to the next corpus in the registration order, or None if nothing remains.
name
str
required
Name of the corpus to remove.
Raises
ExceptionCondition
KeyErrorThe corpus has not been loaded

Property

current

corpus_manager.current  # str | None
Read-only property. Returns the name of the currently active corpus, or None when no corpus has been loaded. The active corpus is used as the default target by get_api() and all MCP tools.

Full example

from exegia.mcp import mcp, corpus_manager

# Load multiple corpora
corpus_manager.load("~/.exegia/datasets/bibles/BHSA", name="BHSA")
corpus_manager.load("~/.exegia/datasets/bibles/GNT",  name="GNT")

# Switch active corpus
corpus_manager.select("GNT")
print(corpus_manager.current)  # "GNT"

# Get TF API and use it directly
api = corpus_manager.get_api("BHSA")
print(api.F.otype.freqList()[:5])

# Unload a corpus from memory
corpus_manager.unload("GNT")
print(corpus_manager.list_corpora())  # ["BHSA"]

Build docs developers (and LLMs) love