一键导入
encyclopedia
Knowledge retrieval from multiple sources. Search docs, web, and code with intelligent routing, RRF fusion, circuit breakers, and semantic caching.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Knowledge retrieval from multiple sources. Search docs, web, and code with intelligent routing, RRF fusion, circuit breakers, and semantic caching.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Persistent codebase intelligence. Learns patterns, conventions, and architecture from your codebase via tree-sitter AST parsing (12 languages) and remembers across sessions. MCP server with 13 tools for semantic search, pattern prediction, file routing, and project blueprints.
Agency and execution. Edit code semantically, invoke LLMs, search the web, and query security services.
Toulmin argumentation engine — symbolic validation of argument structure, inferential integrity, and audience-calibrated delivery.
Subconscious memory layer. Absorbs observations, surfaces associative memories as hypotheses, and builds context across sessions. Commands: remember, consult, surface, forget, stats.
| name | encyclopedia |
| description | Knowledge retrieval from multiple sources. Search docs, web, and code with intelligent routing, RRF fusion, circuit breakers, and semantic caching. |
| license | MIT |
| metadata | {"version":"3.0.0","dependencies":"python>=3.10"} |
"A billion pages, a billion facts. The Encyclopedia knows all."
Encyclopedia is the knowledge skill of the Cognitive Construct. It aggregates multiple information sources into a unified, reliable interface: library documentation via Context7, web search via Exa, Perplexity, and (optionally) Kagi, code analysis via repository inspection, and optional advanced sources like SearXNG and CodeGraphContext.
The retrieval pipeline processes every query through six phases:
Each phase degrades gracefully via import guards — if a dependency is missing, the phase is skipped and the pipeline continues with reduced capability.
search "<query>"Perform a knowledge search across all available sources. Include repo:owner/name anywhere in the query to automatically pull repository context from mcp-git-ingest (and CodeGraphContext when enabled).
python3 scripts/encyclopedia.py search "repo:anthropics/anthology describe auth middleware"
python3 scripts/encyclopedia.py search "kubernetes auth middleware" --verbose
python3 scripts/encyclopedia.py search "k8s auth" --dry-run
Options:
--sources <list>: Comma-separated list of sources to query (context7, exa, perplexity, kagi, searxng, codegraph, mcp_git_ingest)--limit <n>: Maximum results to return (default: 5)--verbose: Show query analysis, source routing, fusion breakdown, cache status, and health diagnostics--dry-run: Show preprocessing and routing decisions without executing queriesOutput:
{
"status": "success",
"results": [...],
"sources_used": ["context7", "exa", "mcp_git_ingest"],
"degraded": false,
"degradation": {"missing": [], "errors": []},
"cached": false
}
When --verbose is enabled, the response includes additional diagnostics:
{
"verbose": {
"query_analysis": {
"raw_query": "k8s auth middleware",
"classified_type": "library_docs",
"corrections": ["k8s → kubernetes"],
"expansions": [["auth", "authentication", "authorization"]]
},
"source_routing": {
"target_sources": ["context7", "exa"],
"health_filtered": [],
"fallback_used": false
},
"fusion": {
"weights": {"context7": 0.52, "exa": 0.48},
"per_source_results": {"context7": 3, "exa": 4}
},
"cache": {"status": "miss"},
"profiler": {"adaptive_enabled": false}
}
}
When --dry-run is enabled, the pipeline stops after preprocessing and routing — no queries are dispatched:
{
"status": "dry_run",
"query_analysis": {...},
"target_sources": ["context7", "exa"],
"source_health": {"context7": "healthy", "exa": "healthy"},
"cache_status": "miss"
}
lookup "<topic>"Look up documentation for a specific library, API, or topic.
python3 scripts/encyclopedia.py lookup "fastapi" --version latest
Options:
--version <ver>: Specific version to look up (default: latest)Output:
{"status": "success", "topic": "fastapi", "version": "0.115.0", "content": "..."}
code "<repo_path>" "<query>"Analyze a code repository and answer questions about it.
python3 scripts/encyclopedia.py code "github.com/owner/repo" "how does authentication work"
Options:
--depth <shallow|deep>: Analysis depth (default: shallow)Output:
{"status": "success", "repository": "owner/repo", "analysis": "..."}
Raw queries are transformed before dispatch:
Synonym expansion is additive: it never removes or replaces the original query terms (Constitution Rule 7).
When multiple sources return results, Reciprocal Rank Fusion merges them:
shared.fusion.get_source_weights()fused_from lists all contributing sources for each result (Constitution Rule 5)Circuit breakers track per-source reliability:
ENCYCLOPEDIA_SOURCE_DEGRADED, ENCYCLOPEDIA_SOURCE_RESTOREDWhen all primary sources for a query type are circuit-broken, cross-type fallback routing attempts sources from adjacent types (e.g., library_docs falls back to general search sources).
Near-duplicate queries hit the cache instead of re-querying backends:
ENCYCLOPEDIA_CACHE_THRESHOLD)ENCYCLOPEDIA_CACHE_TTL)library_docs cache entry is never returned for a general_search query (Constitution Rule 4)~/.encyclopedia/cache/semantic_cache.jsonlRolling window metrics (last 200 queries per source) track performance:
ENCYCLOPEDIA_ADAPTIVE_WEIGHTS (default: disabled)When enabled, the profiler adjusts fusion weights based on measured performance. When disabled, metrics are still recorded for observability but weights remain static.
Encyclopedia classifies queries and routes to appropriate sources:
| Query Type | Primary Sources | Fallback Sources |
|---|---|---|
library_docs | context7 | exa, perplexity |
general_search | exa, perplexity | kagi (flagged), searxng |
code_context | mcp-git-ingest (requires repo: hint) | exa, context7, CodeGraphContext (optional) |
repository | mcp-git-ingest | exa |
Classification Strategy:
"doc: React" or "code: auth.py" override routing.repo:owner/name automatically trigger code_context.def/class/function → code_context."latest", "current", any 4-digit year → general_search.Set in .env.local:
# Required (at least one)
EXA_API_KEY=... # Exa web search
PERPLEXITY_API_KEY=... # Perplexity AI search
# Optional (enhanced capabilities)
CONTEXT7_API_KEY=... # Higher rate limits for library docs
KAGI_API_KEY=... # Kagi search (closed beta)
SEARXNG_URL=... # Self-hosted SearXNG instance
CGCLI_DB_URL=... # cgcli SurrealDB (default: surrealkv://~/.local/share/cgcli/codegraph)
# Search providers (via ENCYCLOPEDIA_ENABLE_<NAME>=1)
ENCYCLOPEDIA_ENABLE_CONTEXT7=1 # Context7 library docs (default: on)
ENCYCLOPEDIA_ENABLE_KAGI=0 # Kagi search (default: off)
ENCYCLOPEDIA_ENABLE_SEARXNG=0 # SearXNG (default: off)
ENCYCLOPEDIA_ENABLE_CODEGRAPH=0 # SurrealDB code graph (default: off)
# Adaptive features
ENCYCLOPEDIA_ADAPTIVE_WEIGHTS=0 # Source quality profiling (default: off)
# Cache tuning (direct env vars, not feature flags)
ENCYCLOPEDIA_CACHE_THRESHOLD=0.92 # Cosine similarity threshold for cache hits
ENCYCLOPEDIA_CACHE_TTL=3600 # Cache entry TTL in seconds
Encyclopedia invokes CLI tools for each backend. Override paths via environment:
CONTEXT7_CLI=context7 # context7 resolve/docs commands
EXA_CLI=exa-mcp-server # preferred; avoids collision with system `exa` (the `ls` replacement)
KAGI_CLI=kagi # kagi search/summarize commands
PERPLEXITY_CLI=perplexity # perplexity query command
SEARXNG_CLI=searxng # searxng search command
GIT_INGEST_CLI=mcp-git-ingest # mcp-git-ingest tree/read commands
CGC_CLI=cgcli # cgcli find/analyze commands
Note: if exa on your machine is the ls replacement (often at /usr/bin/exa), install exa-mcp-server and/or set EXA_CLI=exa-mcp-server.
Encyclopedia validates credentials at startup and returns clear errors:
"EXA_API_KEY not found""cli_not_found"The degradation hierarchy (Constitution Rule 6):
preprocessed query + RRF fusion
→ preprocessed query + priority dedup
→ raw query + priority dedup
→ raw query + single source
→ error
Each fallback layer loses quality but preserves availability.
When any provider is unavailable, the CLI reports:
degraded (bool): true if the request fell back to reduced capabilitydegradation.missing: structured entries {source, reason, optional} describing skipped providersdegradation.errors: runtime failures (timeouts, HTTP errors) with optionality indicatorsThis metadata makes it clear when optional backends were unavailable and why.
Encyclopedia returns structured errors without exposing internal details:
{"status": "error", "code": 2, "message": "No results found for query"}
Error codes:
1: Configuration error (missing credentials, CLI not found)2: No results / resource not found3: Backend unavailable (will use fallback)4: Internal errorEncyclopedia integrates with other Cognitive Construct skills via the synergy bus:
ENCYCLOPEDIA_CACHE_SYNERGY)rhetoric_request_context() (RHETORIC_ENCYCLOPEDIA_SYNERGY)Synergies are enabled by default and controlled by feature flags in shared/feature_flags.py.
Encyclopedia's 7 inviolable rules are defined in constitution.md:
scripts/encyclopedia.py: Main orchestrator (query pipeline, fusion, dispatch)scripts/source_health.py: Circuit breaker and health registryscripts/semantic_cache.py: Embedding similarity cache with LRU evictionscripts/source_profiler.py: Rolling window metrics and adaptive weightsscripts/cgcli/: Vendored code graph client (SurrealDB)scripts/anime-mori/: Vendored persistent codebase intelligence (TS+Rust)constitution.md: Inviolable rules governing the knowledge substrateSPEC.md: Technical specification (design rationale and phase details)~/.encyclopedia/cache/semantic_cache.jsonl: Persisted cache entries~/.encyclopedia/sessions/: Query session history