Skip to content

Ctx Recursive

ctx_recursive — mvp.ctx_recursive

Cluster: Context & Retrieval | Type: component | MCP Tools: 28

Overview

Hierarchical extractive summariser that compresses large texts to a target length without an LLM. At each depth level it splits the text into sentence-boundary chunks, scores sentences by TF-IDF word frequency, and selects the highest-scoring sentences up to a per-chunk budget. The process repeats recursively until the output fits in target_length or max_depth is exhausted. A simpler truncate strategy is also available.

When to use:

  • Summarising long documents to fit within an LLM context window with no API cost
  • Reducing agent working memory size before storing in a token-limited context block
  • Building a quick extractive summary layer in a RAG or grounding pipeline

Example:

from mvp.ctx_recursive import CtxRecursiveBlock, RecursiveInput

block = CtxRecursiveBlock(name="recursive")
result = block.infer(RecursiveInput(
    text="<long article text>",
    target_length=500,
    max_depth=3,
    strategy="extractive",
))
# result.value.summary → compressed text ≤ 500 chars; result.value.depth → levels used

Works well with: ctx_ace, ctx_claude_context, ctx_markitdown

Public API

SummaryRerankDecision

Validated advisory rerank verdict over a returned summary set.

Field Type Default
ordered_indices tuple[int, ...] required
dropped_indices tuple[int, ...] ()
rationale str ''
eligible_fingerprint str ''
confidence float 0.0
degraded bool False
raw_response str ''

LLMRecursiveRerankRuntime

Provider-neutral summary-rerank runtime backed by G6's LLM caller.

Constructor:

Parameter Type Default
llm LLMCaller \| None None

Methods:

rerank(query: str, summaries: list[Any]) -> SummaryRerankDecision

CtxRecursiveRerankPatternRuntime

Stateless, load-bearing returned-set-ceiling enforcement.

Methods:

enforce_eligibility(decision: SummaryRerankDecision, summaries: list[Any]) -> tuple[list[Any], bool, bool]

CtxRecursivePlanner

Runtime-first advisory summary-rerank facade with returned-order fallback.

Constructor:

Parameter Type Default
runtime SummaryRerankRuntime \| None None
pattern_runtime CtxRecursiveRerankPatternRuntime \| None None

Methods:

rerank(query: str, summaries: list[Any]) -> list[Any]

CtxRecursiveBlock(AIBlock[RecursiveInput, RecursiveOutput, None])

Hierarchical extractive summariser.

Field Type Default
name str 'ctx_recursive'
resource_bounds ResourceBounds \| None None
usage ResourceUsage field(default_factory=ResourceUsage)

Methods:

infer(data: RecursiveInput) -> Result[RecursiveOutput]

RecursiveInput(BaseModel)

Input to CtxRecursiveBlock.

Field Type Default
text str required
chunk_size int 1024
max_depth int 3
strategy Literal['extractive', 'truncate'] 'extractive'
target_length int 512
run_mode Literal['beta', 'production'] 'beta'
reviewer_signature str ''

RecursiveOutput(BaseModel)

Output from CtxRecursiveBlock.

Field Type Default
summary str required
depth int required
chunks_processed int required
strategy str required
degraded bool False
degradation_reason str \| None None
completion_state Literal['verified', 'qualified-draft', 'blocked-escalated'] 'qualified-draft'
warning_card dict[str, Any] \| None None
evidence dict[str, Any] Field(default_factory=dict)
request_id str ''
task_id str ''
run_id str ''
sentence_offsets list[tuple[int, int]] Field(default_factory=list)
quality_score float \| None None

CtxRecursiveSkillCatalog

Maps each applied pattern slug to a ctx_recursive rerank skill record.

Methods:

list_skills() -> list[CtxRecursiveSkill]

executable_skills() -> list[CtxRecursiveSkill]

get(slug: str) -> CtxRecursiveSkill | None

CtxRecursiveMCPBlock(AIBlock[MCPRecursiveInput, MCPRecursiveOutput, dict])

Full-featured recursive summarisation block with SQLite persistence.

Field Type Default
name str 'ctx_recursive_mcp'
state dict \| None None
db_path str ':memory:'
resource_bounds ResourceBounds \| None None
usage ResourceUsage field(default_factory=ResourceUsage)
agentic_planner CtxRecursivePlanner \| None None

Methods:

infer(data: MCPRecursiveInput) -> Result[MCPRecursiveOutput]

MCPRecursiveRecord(BaseModel)

Field Type Default
id str required
record_type str required
key str required
value str required
tags list[str] Field(default_factory=list)
timestamp str required
metadata dict[str, Any] Field(default_factory=dict)

MCPRecursiveInput(BaseModel)

Field Type Default
op Literal['summarise', 'analyse_chunks', 'compare_strategies', 'estimate_complexity', 'system_status', 'save_session', 'load_session', 'list_sessions', 'delete_session', 'store_summary', 'get_summary', 'search_summaries', 'delete_summary', 'store_chunk_analysis', 'get_chunk_analysis', 'list_chunk_analyses', 'create_template', 'get_template', 'list_templates', 'store_context', 'get_context', 'list_contexts', 'rlm_summarise', 'rlm_status', 'info', 'list_patterns'] required
text str ''
strategy Literal['extractive', 'truncate'] 'extractive'
target_length int Field(default=512, gt=0, le=1000000)
chunk_size int Field(default=1024, gt=0, le=1000000)
max_depth int Field(default=3, gt=0, le=20)
key str ''
name str ''
description str ''
tags list[str] Field(default_factory=list)
query str ''
limit int Field(default=50, gt=0, le=500)
top_k int Field(default=5, gt=0, le=100)
template_name str ''
agentic_rerank bool \| None None
run_mode Literal['beta', 'production'] 'beta'
reviewer_signature str ''

MCPRecursiveOutput(BaseModel)

Field Type Default
op str required
key str ''
value str ''
found bool False
count int 0
records list[MCPRecursiveRecord] Field(default_factory=list)
summary str ''
message str ''
metadata dict[str, Any] Field(default_factory=dict)
degraded bool False
degradation_reason str ''
completion_state Literal['verified', 'qualified-draft', 'blocked-escalated'] 'qualified-draft'
warning_card dict[str, Any] \| None None
evidence dict[str, Any] Field(default_factory=dict)
request_id str ''
task_id str ''
run_id str ''
agentic_evidence dict[str, Any] Field(default_factory=dict)

RecursiveStore

Sync SQLite recursive store with 6 tables.

Constructor:

Parameter Type Default
db_path str ':memory:'

Methods:

save_session(name: str, description: str, input_text: str, summary_text: str, strategy: str, target_length: int, chunk_size: int, max_depth: int, depth_used: int, chunks_processed: int, compression_ratio: float, tags: list[str]) -> str

load_session(name: str) -> dict[str, Any] | None

list_sessions(limit: int = 50) -> list[dict[str, Any]]

delete_session(name: str) -> bool

store_summary(key: str, original_text: str, summary_text: str, strategy: str, depth: int, chunks_processed: int, compression_ratio: float, original_length: int, summary_length: int, tags: list[str]) -> str

get_summary(key: str) -> dict[str, Any] | None

search_summaries(query: str, top_k: int = 5) -> list[dict[str, Any]]

delete_summary(key: str) -> bool

store_chunk_analysis(key: str, original_text: str, chunk_count: int, chunk_lengths_json: str, avg_chunk_length: float, total_chars: int, chunk_size_param: int, tags: list[str]) -> str

get_chunk_analysis(key: str) -> dict[str, Any] | None

list_chunk_analyses(limit: int = 50) -> list[dict[str, Any]]

create_template(name: str, description: str, strategy: str, target_length: int, chunk_size: int, max_depth: int, tags: list[str]) -> str

get_template(name: str) -> dict[str, Any] | None

list_templates(limit: int = 50) -> list[dict[str, Any]]

increment_template_use(name: str) -> None

store_context(name: str, text: str, description: str, tags: list[str]) -> str

get_context(name: str) -> dict[str, Any] | None

list_contexts(limit: int = 50) -> list[dict[str, Any]]

add_job(session_id: str, strategy: str, status: str, llm_calls: int, iterations: int, depth_used: int, error_message: str) -> str

get_recent_jobs(limit: int = 10) -> list[dict[str, Any]]

count_all() -> dict[str, int]

Functions

summarize_ctx_recursive_agentic_evidence(decisions: list[dict[str, Any]]) -> dict[str, Any]

Summarise runtime-vs-fallback ctx_recursive rerank decisions with redaction.

agentic_planner_enabled(default_enabled: bool) -> bool

Decide whether the agentic summary-rerank planner should be used.

validate_summary_rerank_decision(decision: SummaryRerankDecision, n_eligible: int, expected_fingerprint: str) -> None

Returned-set / anti-injection guard for a summary-rerank decision.

planner_is_llm_trusted(planner: Any) -> bool

Whether the BLOCK may report llm_used=True for planner.

applied_agentic_patterns() -> list[dict[str, Any]]

Return compact metadata for ctx_recursive-applied vendored patterns.

get_skill_catalog() -> CtxRecursiveSkillCatalog

MCP Tools

Operation Source
summarise recursive_mcp
analyse_chunks recursive_mcp
compare_strategies recursive_mcp
estimate_complexity recursive_mcp
system_status recursive_mcp
save_session recursive_mcp
load_session recursive_mcp
list_sessions recursive_mcp
delete_session recursive_mcp
store_summary recursive_mcp
get_summary recursive_mcp
search_summaries recursive_mcp
delete_summary recursive_mcp
store_chunk_analysis recursive_mcp
get_chunk_analysis recursive_mcp
list_chunk_analyses recursive_mcp
create_template recursive_mcp
get_template recursive_mcp
list_templates recursive_mcp
store_context recursive_mcp
get_context recursive_mcp
list_contexts recursive_mcp
rlm_summarise recursive_mcp
rlm_status recursive_mcp
info recursive_mcp
list_patterns recursive_mcp
extractive recursive_mcp
truncate recursive_mcp