Skip to content

Context & Retrieval

Sixteen components that find, fetch, parse, and rank information -- giving G6 agents grounded access to documents, the web, code repositories, and structured knowledge.

Overview

G6 agents are only as good as the context they operate on. This cluster provides a full retrieval stack: sparse retrieval (TF-IDF via ctx_rag), dense retrieval (ctx_colbert), optional Elasticsearch-backed search (ctx_elastic), and knowledge-graph extraction (ctx_cognee). On the ingestion side, ctx_markitdown converts PDFs, DOCX, and other formats to Markdown, while ctx_scrapling and ctx_search fetch web content.

Specialized context components handle git repositories (ctx_git), visual inputs (ctx_vision), structured entity extraction (ctx_langextract), and recursive summarization (ctx_recursive). The context_engine component orchestrates these sources, deciding which retrievers to query and how to merge their results.

All retrieval components return ranked results with confidence scores, enabling downstream consumers (goal engine, agents) to make informed decisions about context quality. Components degrade gracefully -- if Elasticsearch is unavailable, ctx_elastic returns a clear error via Result.fail() rather than crashing. It does not provide a local fallback; use ctx_rag for small local corpora or onboarding flows that should work without external services.

Full ColBERT requires an opt-in install

ctx_colbert works in the default install, but full ColBERT retrieval requires ragatouille==0.0.9.post2. Without that package, it reports degraded mode and uses configured embedding retrieval or local TF-IDF. Install the context extension package pip install g6-context --index-url https://packages.g6solver.com/simple/ (which bundles the full ColBERT backend), or build the self-hosted MCP image with --build-arg G6_FULL_RETRIEVAL=true. Before advertising a deployment as full ColBERT, run G6_RUN_RAGATOUILLE_SMOKE=1 python -m pytest tests/mvp/ctx_colbert/test_ragatouille_real_smoke.py -m heavy -q in the target environment.

External memory worker licensing

ctx_claude_mem depends on the upstream claude-mem worker. G6 vendors a pinned source snapshot for testing and source availability, but the snapshot is not automatically cleared for paid end-user redistribution: upstream root is AGPL-3.0, and its ragtime/ subtree is PolyForm Noncommercial 1.0.0. Treat bundled distribution as a separate packaging/legal decision.

Components

Component Description MCP Tools
ctx_rag TF-IDF retrieval with sentence-boundary chunking --
ctx_colbert ColBERT-style retrieval (RAGatouille or TF-IDF fallback) --
ctx_elastic Optional Elasticsearch integration for large indexed datasets with known mappings --
ctx_cognee Entity extraction and knowledge graph queries --
ctx_langextract Field-name heuristic extraction (email, URL, date, phone) --
ctx_recursive Recursive summarization (extractive TF-IDF + truncate) --
ctx_scrapling Web scraping (Scrapling / httpx + regex fallback) --
ctx_search Web search (DuckDuckGo, SerpAPI, mock) --
ctx_markitdown Document-to-Markdown conversion --
ctx_ace Agent Cognition Engine working memory and adaptive playbooks 25
ctx_claude_mem Adapter for upstream claude-mem persistent session memory 25
ctx_claude_context Claude-specific context management --
ctx_fenic FENIC context extraction --
ctx_git Git repository context and history analysis --
ctx_mnm MNM context processing --
ctx_vision Visual input processing and OCR --
context_engine Multi-source context orchestration --

Architecture

graph TD
    CE[context_engine] --> RAG[ctx_rag]
    CE --> COL[ctx_colbert]
    CE --> EL[ctx_elastic]
    CE --> COG[ctx_cognee]
    CE --> SEARCH[ctx_search]

    SEARCH --> SCRAP[ctx_scrapling]
    RAG --> MD[ctx_markitdown]
    COL --> MD
    COG --> LANG[ctx_langextract]
    RAG --> REC[ctx_recursive]

    GIT[ctx_git] --> CE
    VIS[ctx_vision] --> CE
    ACE[ctx_ace] --> CE
    CLAUDE[ctx_claude_context] --> CE

Key Patterns

Graceful Degradation. External dependencies (Elasticsearch, RAGatouille, Scrapling) are imported at module level inside try/except blocks. Components either fail with a diagnostic message or return output with degraded=True and a degradation_reason. ctx_colbert is explicit about whether it used retriever="colbert", retriever="embedding", or retriever="tfidf".

Elasticsearch Scope. ctx_elastic is useful when a deployment already operates Elasticsearch or needs large-corpus full-text indexing. The default search path matches the content field, so production indices must expose that field or use the MCP tools/custom query path suited to their mappings. It should be documented as optional advanced infrastructure, not as the default first-run retrieval path.

Sentence-Boundary Chunking. ctx_rag splits documents on sentence boundaries rather than fixed token windows. This preserves semantic coherence in each chunk and improves retrieval precision for question-answering workloads.

Confidence Scoring. Every retrieval result includes a numeric confidence score (typically TF-IDF cosine similarity or BM25 score). Downstream consumers use these scores to weight context in prompts or to discard low-quality results entirely.