Skip to content

API Index

contextgrid.__all__ holds 171 names. Every one of them is listed below, grouped by the part of the tool it belongs to, so you can find any symbol from this one page.

import contextgrid as cg
print(len(cg.__all__))
171

Anything not on this list is not part of the public interface, even if you can technically import it from a submodule — importing straight from contextgrid (rather than contextgrid.chunk.recursive or similar) is the one guarantee that survives a version bump.

Core text model — spans, documents, chunks

NamePurpose
SpanA half-open character range [start, end) in one document.
DocumentA body of text that character offsets refer to.
SourceFileOne input file, before anything has been extracted from it.
MediaTypeThe input formats the pipeline knows about.
ParsedDocumentOne parser’s reading of one source file.
BlockA structural region of a parsed document, with its position in the text.
BlockKindWhat a parser thinks a region of the document is.
ChunkA unit of retrievable text, and where it came from.
ChunkSetEvery chunk one chunker produced from one parse, with its provenance.
merge_spansCollapse overlapping and touching spans into a minimal disjoint set.
total_lengthCharacters covered by a set of spans, counting shared characters once.
covered_lengthCharacters of one span that appear anywhere in a set of others.
coverage_fractioncovered_length as a fraction of the target span, in [0, 1].
intersection_lengthCharacters covered by both of two span sets, counting each once.
collapse_whitespaceCollapse runs of whitespace to one space, mapping each result character back.

See Spans and Offsets.

Corpus

NamePurpose
CorpusA named set of source files, before anything has been extracted from them.
CorpusFingerprintWhat a corpus is made of: size, format mix, table density.
fingerprintProfile a corpus, using a parse for content statistics when one is available.
fingerprint_sourcesProfile a corpus from its bytes alone. Instant, and enough to catch duplicates.

See Corpus.

Configuration and the built pipeline

NamePurpose
ConfigOne point in the grid: one value per axis.
buildRun one configuration’s indexing side: parse, chunk, embed, index.
BuiltPipelineA configuration that has read the corpus and is ready to answer queries.
TimingsWall-clock time per stage, in milliseconds.

See Build.

Plugin registries and resolution

NamePurpose
RegistryA named collection of plugins of one family.
UnknownPluginErrorRaised when a spec string names a plugin nothing is registered under.
CHUNKERSThe chunker registry.
PARSERSThe parser registry.
EMBEDDERSThe embedder registry.
INDEXESThe index registry.
RERANKERSThe reranker registry.
TRANSFORMSThe query-transform registry.
TOKENIZERSThe tokenizer registry.
get_chunkerResolve a chunker from a spec like recursive:512,overlap=64, or pass one through.
get_parserResolve a parser from a spec string, or pass an instance through.
get_embedderResolve an embedder from a spec like hash:512, or pass an instance through.
get_indexResolve an index from a spec like hybrid:weighted,alpha=0.7, or pass one through.
get_rerankerResolve a reranker from a spec, or pass one through. None means no reranking.
get_transformResolve a query transform, supplying the model to the ones that need one.
get_tokenizerResolve a tokenizer from a name, a spec string, or an instance.
ChunkerProtocol: cuts a parsed document into retrievable units.
ParserProtocol: turns a source file into text with structure.
EmbedderProtocol: turns text into vectors, queries and documents handled separately.
IndexProtocol: holds chunks and finds the ones most like a query.
RerankerProtocol: reorders a candidate list using the query and passage together.
QueryTransformProtocol: rewrites a question into one or more search queries.
GeneratorProtocol: turns a question and its context into an answer.
TokenizerProtocol: turns text into token boundaries.

See Axes Overview.

Chunkers

NamePurpose
SemanticChunkerCut where consecutive sentences stop being about the same thing.

See Chunkers.

Embedders

NamePurpose
AdaptedEmbedderAn embedder with an adapter on its query side.
LinearAdapterOne matrix applied to query vectors. Documents are left alone.
TripletOne training example: a question, the passage that answers it, and near misses.
fit_adapterEmbed a set of triplets and fit an adapter to them.
mine_tripletsTurn a completed run into adapter training data.
split_tripletsSplit triplets into a training half and a held-out half.

See Embedders.

Indexes

NamePurpose
QuantizationHow a QuantizedDenseIndex compresses its vectors.
QuantizedDenseIndexExact dense search over compressed vectors, with an optional rescoring pass.
recall_against_exactWhat fraction of exact search’s top k an approximate index also found.

See Indexes.

Query transforms

NamePurpose
DecomposeBreak a question into the sub-questions it actually contains.
ExpandAcronymsSpell out acronyms and abbreviations. No model required.
HyDESearch with a hypothetical answer rather than the question.
MultiQueryAsk the same thing several ways and fuse the results.
NoTransformSearch with the question as asked. The arm every transform has to beat.
StepBackAsk the more general question alongside the specific one.
TransformedQueryOne question, and the queries actually sent to the index.

See Transforms.

NamePurpose
RetrievedChunkA chunk a configuration returned for a query, with its position and score.

See Search.

Assembling and answering

NamePurpose
AssembledContextWhat the generator will see, and what it cost to put together.
ContextAssemblerAssembles retrieved chunks into a prompt’s context block.
OrderingWhere in the context the best evidence goes.
tokens_sentWhat one retrieval will cost the generator, per query, in tokens.
AnswerWhat a generator said, and what it cost.
AnswerScoreHow good one answer was, judged against the context and the gold evidence.
GenerationReportAnswer quality across an eval set, and whether retrieval gains reached the answer.
liftWhether a retrieval gain survived through to the answer.
score_answerJudge an answer without a second model.

See Answer.

Generators

NamePurpose
ExtractiveGeneratorReturns the highest-ranked passage verbatim. No model required.
LLMGeneratorAnswers with a model, using a prompt template that is itself a sweepable axis.

See Generation.

Loading and writing eval sets

NamePurpose
EvalSetA versioned collection of questions with span-level ground truth.
EvalItemOne question and the source text that answers it.
GoldSpanA stretch of source text that answers a question, and how well it does so.
GoldAnchorParser-independent evidence: the text that answers the question, quoted.
QuestionTypeThe question categories the tool slices metrics by.
read_jsonlRead an eval set written by write_jsonl, or a bare list of items.
write_jsonlWrite an eval set, one item per line, with a header line carrying its identity.
read_csvRead questions from a spreadsheet export.
write_csvWrite an eval set back out as a spreadsheet, for hand editing.
read_beirRead a BEIR-format dataset: queries.jsonl plus a TSV of judgements.
read_legalbench_ragRead LegalBench-RAG, whose ground truth is character spans.

See Loading Eval Sets.

Generating and filtering eval sets

NamePurpose
ClassifierLabels questions, by heuristic or by model.
KeywordProbeGeneratorBuilds keyword probes from a passage’s most distinctive terms. No model required.
LLMQuestionGeneratorAsks a model for questions answerable only from one passage.
RecordingLLMA model that returns scripted replies and remembers what it was asked.

See Generating Eval Sets.

Eval set quality

NamePurpose
EvalSetQualityWhat this eval set can and cannot support.
assessScore an eval set, using a baseline run to judge discriminating power where available.
FilterChainRuns filters in order, keeping a record of everything dropped.
FilterResultWhat survived, what did not, and anything worth knowing about the filtering.
default_filtersThe filters worth running on any auto-generated eval set, cheapest first.
ReviewQueueQuestions awaiting judgement, and the decisions made so far.
VerdictWhat a reviewer decided about one question.

See Eval Set Quality.

Scoring: metrics and resolution

NamePurpose
METRICSThe metric registry.
MetricProtocol: scores one query — relevance judgements in, a ranked list in, one float out.
get_metricResolve a metric from a spec string, e.g. recall.
DEFAULT_KSThe cut-offs metrics are computed at by default: (1, 3, 5, 10, 20).
available_metricsEvery metric name that can be requested.
evaluateScore a whole run, averaged over queries.
per_queryOne metric, for every query separately.
character_f1Harmonic mean of character precision and recall.
character_precisionFraction of the retrieved characters that are gold.
character_recallFraction of the question’s gold characters present anywhere in retrieved chunks.
gold_coverage_by_chunkPer chunk, the fraction of one question’s gold characters it holds.
retrieved_character_countCharacters sent downstream, counting overlapping chunks once.
RelevanceLabelA resolved judgement: for this question, this chunk is relevant at this grade.
SpanResolverTurns span-level ground truth into chunk-level relevance judgements.
ResolutionPolicyHow to decide that a chunk counts as relevant to a gold span.
ResolutionThe resolved relevance judgements for one question, with diagnostics.
GoldResolutionWhat happened to one gold span under one chunk set.
AnchorResolverFinds quoted evidence in a parse.
AnchorMatchWhere one anchor ended up in one parse, and how sure we are about it.
MatchStrategyHow an anchor was located, in decreasing order of confidence.
ValidationResultWhat was scored, what a benchmark’s paper reported, and whether that is close enough.
load_benchmarkLoad a LegalBench-RAG benchmark file and the documents its spans point into.
self_checkCheck the span resolver against a benchmark’s own annotations, with no retrieval.
validateScore a benchmark with this package’s chain and compare against its published numbers.

See Metrics.

Scoring: significance

NamePurpose
ComparisonWhether two configurations actually differ, and how sure we can be.
IntervalAn estimate and the range it could plausibly sit in.
bootstrap_intervalA confidence interval for a mean score, by resampling the questions.
paired_bootstrapA confidence interval for the difference between two configurations.
randomisation_testA two-sided p-value from a paired randomisation test.

See Significance.

Scoring: diagnostics

NamePurpose
DiagnosisWhy one question failed, and what would help.
FailurePointThe stage a question’s failure traces back to.
FailureReportEvery question’s diagnosis, and what the pattern across them suggests.
diagnoseSort every question into a failure point, from retrieval data alone.

See Diagnostics.

The Lab

NamePurpose
LabA corpus, a matrix over it, and the runs that came out.

See Lab Overview.

The grid

NamePurpose
MatrixThe axes of an experiment, and the baseline OFAT and staged sweeps vary from.
SweepModefactorial, ofat, or staged — the three ways to walk a matrix.
matrixBuild a Matrix, accepting a single value or a list on any axis.
estimate_costWhat a sweep will cost before it runs. Full detail in Cost.

See The Grid.

Running a sweep

NamePurpose
RunnerRuns configurations against a corpus and an eval set.

See Running.

Results and warnings

NamePurpose
ResultsEvery configuration a sweep ran, and the ways to read them.
RunResultEverything one configuration produced.
format_leaderboardA fixed-width leaderboard for a terminal.
WarningLogAn ordered, mergeable collection of warnings.
GridWarningOne thing that happened which could change how a result should be read.
WarningCodeMachine-readable warning kinds.
SeverityHow much a warning should change what you believe.

See Results.

Exporting and reproducing runs

NamePurpose
ManifestEverything needed to reproduce one run, and nothing that changes between runs.
build_manifestRecord everything about a run that could change its numbers.
explain_diffThe difference between two runs, in plain English.
config_to_yamlThe configuration as YAML, hand-written rather than via a dependency.
config_to_pythonRunnable Python that rebuilds one configuration.
winning_config_to_yamlThe winning configuration as an experiment file you can hand back to the tool.
results_to_jsonEvery configuration and every number, for offline analysis.
results_to_markdownA one-page report to paste into a decision doc.
write_bundleWrite everything: the report, the raw results, the winning config and the manifest.

See Exporting Runs.

Cost

NamePurpose
CostModelTurns tokens and seconds into dollars.
CostBreakdownWhat one configuration costs, itemised.
PricingWhat one model charges, in dollars per million tokens.
PRICESThe published price list CostModel starts from.

See Cost.

Caching

NamePurpose
CacheProtocol: somewhere to put a stage’s output and find it again.
CacheStatsHits, misses and what they saved.
MemoryCacheIn-process cache. The default, and enough for a single sweep.
DiskCacheCache that survives the process, for re-running a sweep after changing one axis.
NullCacheCaches nothing. For measuring what a stage really costs.

See Caching.

Errors

NamePurpose
ContextGridErrorBase class for everything this package raises on purpose.
MissingExtraErrorAn optional dependency is needed and is not installed.
CorpusErrorA corpus could not be loaded, or is not usable as given.
SpanErrorA span is malformed, or two spans were compared in a way that makes no sense.
DocumentErrorA document or a reference into one is inconsistent.
EvalSetErrorAn eval set, an item, or a gold span is malformed.
ResolutionErrorGold spans could not be resolved to chunks.
ChunkerErrorA chunker was configured in a way that cannot produce sensible chunks.

UnknownPluginError is also an exception, listed above under Plugin registries and resolution since that is where you will actually catch it. See Errors for the full hierarchy, including exceptions raised deeper in the package that are not re-exported at the top level.

Package

NamePurpose
__version__The installed context-grid version, as a string.
import contextgrid as cg
print(cg.__version__)
0.9.5