Skip to content

[recipes] Wiki pipeline: OpenRouter + thought_edges + prompt safety#234

Open
AnkitClassicVision wants to merge 4 commits intoNateBJones-Projects:mainfrom
AnkitClassicVision:contrib/AnkitClassicVision/wiki-pipeline-improvements
Open

[recipes] Wiki pipeline: OpenRouter + thought_edges + prompt safety#234
AnkitClassicVision wants to merge 4 commits intoNateBJones-Projects:mainfrom
AnkitClassicVision:contrib/AnkitClassicVision/wiki-pipeline-improvements

Conversation

@AnkitClassicVision
Copy link
Copy Markdown

Summary

Three related wiki-pipeline improvements, packaged together because they land as a coherent upgrade after the typed-reasoning-edges feature (#208) merged.

1. typed-edge-classifier: OpenAI-compatible LLM path

Previously required ANTHROPIC_API_KEY direct to api.anthropic.com. Now also accepts LLM_BASE_URL + LLM_API_KEY (OpenRouter, LiteLLM, etc.) — the same pattern the sibling entity-wiki and wiki-synthesis recipes use. Direct Anthropic remains the fallback when the OpenAI-compat vars aren't set, so existing installs keep working.

Why: running all three recipes through one provider avoids maintaining a second API key just for the classifier.

2. entity-wiki: thought_edges integration

Entity wiki pages now include a Thought reasoning links subsection under Relationships, rendering supports / contradicts / evolved_into / supersedes / depends_on / related_to edges between the evidence thoughts the page already cites.

Graceful degradation: if schemas/typed-reasoning-edges/ isn't installed (table missing), the fetch returns [] and the subsection is omitted — no runtime error.

Why: closes the loop opened by #208 — the classifier produces thought_edges rows; now entity-wiki actually renders them.

3. wiki-synthesis: bounded-size prompt + schema tolerance

  • Autobiography builder caps each entry at 240 chars and each per-year sample at 25k chars (with a 25-entry floor so sparse years still synthesize). Prevents context blow-ups on long entries (meeting notes, code blocks in Obsidian captures).
  • fetchThoughts gracefully handles deployments whose thoughts table lacks a source_type column by falling back to metadata inference (metadata.source_type / source_system / source / kind). Preserves server-side filtering when the column exists.

Provenance note

These changes were in my working tree when picking up wiki-compiler install work this week. I believe they came from an earlier Claude/Codex session that didn't land a commit — the code style and comment density match the rest of the repo, and the changes are tested end-to-end against a real Open Brain (2000+ thoughts, 5000+ entities). Opening as a PR so the maintainer can decide whether to accept or discard.

Test plan

  • Classifier: run with OpenRouter credentials (LLM_BASE_URL=https://openrouter.ai/api/v1 LLM_MODEL=anthropic/claude-haiku-4-5) — 150 pairs processed, 4 edges inserted, $1.86 spent under $2 cap.
  • Entity-wiki: generated 690 pages against a brain with 8 thought_edges. Pages with linked thoughts that have reasoning edges between them render the new subsection; others omit it cleanly.
  • Wiki-synthesis: autobiography regenerated from 357 thoughts. Prompt size stayed under 25KB.
  • Verified back-compat: classifier still works without LLM_BASE_URL set (falls back to Anthropic direct).

🤖 Generated with Claude Code

AnkitClassicVision and others added 4 commits April 22, 2026 14:03
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove duplicated MyBCAT Universal Rules block from repo CLAUDE.md.
Rules are now inherited via /repos/.claude/CLAUDE.md (Claude Code walks
up the directory tree). Saves ~1,165 tokens per session.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…on + prompt safety

Three related improvements to the wiki-generation pipeline, packaged together
because they land as a coherent upgrade after the typed-reasoning-edges feature
(PR NateBJones-Projects#208) merged.

## typed-edge-classifier: OpenAI-compatible LLM path
Previously required ANTHROPIC_API_KEY direct to api.anthropic.com. Now accepts
LLM_BASE_URL + LLM_API_KEY (e.g. OpenRouter) in addition, which is what the
entity-wiki and wiki-synthesis recipes already use. Anthropic-direct remains
the fallback when LLM_BASE_URL/LLM_API_KEY aren't set, so existing installs
keep working unchanged.

Rationale: running all three recipes through one provider (OpenRouter) avoids
maintaining a second API key just for the classifier.

## entity-wiki: thought_edges integration
Entity wiki pages now include a "Thought reasoning links" subsection under
Relationships, rendering supports/contradicts/evolved_into/supersedes/depends_on
edges between the evidence thoughts the page already cites. Graceful degradation:
if schemas/typed-reasoning-edges/ isn't installed (table missing), the fetch
returns [] and the subsection is omitted — no runtime error.

This closes the loop opened by PR NateBJones-Projects#208: the typed-edge-classifier produces
thought_edges rows; now entity-wiki actually renders them.

## wiki-synthesis: bounded-size prompt + schema tolerance
- Autobiography builder now caps each entry at MAX_ENTRY_CHARS (240) and the
  per-year sample at MAX_SAMPLE_CHARS (25k), preventing model-context blow-ups
  on long entries (meeting notes, code blocks in Obsidian captures). Keeps at
  least 25 entries before applying the budget so sparse years still synthesize.
- fetchThoughts gracefully handles deployments whose `thoughts` table does not
  carry a `source_type` column by falling back to metadata inference
  (metadata.source_type / source_system / source / kind). Preserves server-side
  filtering when the column exists.

## Provenance
These changes were in my working tree when picking up wiki-compiler install
work; I believe they came from an earlier Claude/Codex session that didn't
land a commit. Code style and comment density match the rest of the repo, and
the changes are tested end-to-end against a real Open Brain (2000+ thoughts,
5000+ entities). Opening as a PR so the maintainer can decide whether to
accept or discard.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added documentation Improvements or additions to documentation recipe Contribution: step-by-step recipe labels Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation recipe Contribution: step-by-step recipe

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant