Гибридный примитив поиска для Compound Vault: контекстный префикс + BM25 + косинусный реранкинг вместо статического порядка чтения hot→index→drill.

Звёзды16 581
Авторagricidaniel
Установок338

Установка

SKILL.md

wiki-retrieve: Hybrid Retrieval over the Vault

The v1.6 query path was Read(hot.md) → Read(index.md) → Read(3-5 pages) → synthesize. It worked, but page-level granularity loses to chunk-level granularity any time the answer lives in a specific passage rather than a whole page. The v1.7 wiki-retrieve skill is the chunk-level upgrade — opt-in, feature-gated, and replaces nothing if you don't run the setup.

Origin: This skill is original to claude-obsidian. There is no upstream kepano equivalent. The technique is from Anthropic's Sept 2024 Contextual Retrieval research — we implement it as agent-skill plumbing.


Data privacy (v1.7.1+)

Tier 1 (Anthropic API) and tier 2 (claude CLI subprocess) of the contextual-prefix generator send wiki page bodies off-machine. As of v1.7.1, both tiers are GATED behind explicit user consent at two layers:

  • scripts/contextual-prefix.py --allow-egress (default off). Without the flag, pick_prefix_tier() returns "synthetic" regardless of ANTHROPIC_API_KEY or claude binary presence.
  • bin/setup-retrieve.sh prompts before any non-synthetic Stage 1 run; default is abort.

To run fully on-machine (tier 3 synthetic prefix + local ollama rerank), use bash bin/setup-retrieve.sh --no-llm. This is also the effective behavior if you decline the consent prompt or omit --allow-egress.

The guard mirrors scripts/tiling-check.py:351 --allow-remote-ollama. v1.6 vaults that never provisioned this skill see zero behavior change.


Architecture

INGEST (one-time, then incremental):

  wiki/<page>.md
       │
       ▼
  scripts/contextual-prefix.py
       │   ├─ chunk on paragraph boundaries (~500 token target, 200 char overlap)
       │   ├─ generate 1-2 sentence prefix per chunk
       │   │     tier 1: ANTHROPIC_API_KEY → Anthropic API (Haiku, prompt-cached
       │   │                                 when body ≥ ~16 KB / Haiku 4.5 floor)
       │   │     tier 2: `claude` on PATH  → claude -p subprocess
       │   │     tier 3: synthetic         → frontmatter title + first paragraph
       │   └─ write .vault-meta/chunks/<address>/chunk-NNN.json
       │
       ▼
  scripts/bm25-index.py build
       └─ inverted index over chunks' contextualized_text → .vault-meta/bm25/index.json

QUERY:

  query string
       │
       ▼
  scripts/retrieve.py "<query>" --top 5
       ├─ bm25-index.py query "<query>" --top 20    (sparse candidate set)
       ├─ rerank.py "<query>" --candidates -        (dense rerank via ollama cosine)
       │     cosine(query_embedding, chunk_embedding)
       │     embeddings cached in .vault-meta/embed-cache.json keyed by body_hash
       └─ dedupe by page-address, return top-N candidates with absolute_path
       │
       ▼
  caller (wiki-query / autoresearch) reads the cited pages and synthesizes

Feature gating

Other skills must detect this skill before using it. The canonical detection:

[ -x scripts/retrieve.py ] && [ -d .vault-meta/chunks ] && \
  [ -f .vault-meta/bm25/index.json ] && \
  echo "wiki-retrieve installed" || echo "fallback: legacy hot→index→drill"

If detection fails, callers MUST fall back to the v1.6 read order. This skill never breaks the base plugin.


Setup

bash bin/setup-retrieve.sh

What it does, in order:

  1. Sanity-checks the 4 scripts are present and executable.
  2. Creates .vault-meta/chunks/ and .vault-meta/bm25/.
  3. Probes ollama at http://127.0.0.1:11434 for nomic-embed-text (rerank prerequisite). Reports status; does not install.
  4. Reports which contextual-prefix tier will be used (Anthropic API / claude CLI / synthetic).
  5. Runs contextual-prefix.py --all to chunk + contextualize every wiki page.
  6. Runs bm25-index.py build.
  7. Smoke-tests retrieve.py against the query "wiki".

Flags:

  • --check — diagnostics only, no provisioning.
  • --no-llm — force tier-3 synthetic prefix (cheapest, zero LLM dependency).
  • --rebuild — re-chunk every page even if body_hash matches.

Cost ceiling

Per Anthropic's published research, contextual-prefix generation costs approximately $12 per 1,000 documents with Haiku + prompt caching. For a 100-page vault with ~3 chunks per page, that's ~$3.60 one-time, with incremental updates much cheaper (only changed pages re-process).

If you want to validate cost before running on a large vault:

bash bin/setup-retrieve.sh --no-llm   # provision with tier-3 synthetic prefix
# inspect retrieval quality manually; if insufficient, re-run without --no-llm

The claude-cli subprocess tier (no API key) is free in $ terms but slower (~3-10s per chunk depending on Haiku availability).


Skill commands (recipe)

These are the commands wiki-query and autoresearch will execute when wiki-retrieve is feature-detected. Other skills should mirror this pattern.

Standard retrieve

python3 scripts/retrieve.py "your question here" --top 5

Output: JSON with candidates array. Each candidate has absolute_path to the source page; caller reads that page (using the v1.7 transport selector) and synthesizes.

BM25-only (skip rerank)

python3 scripts/retrieve.py "query" --top 5 --no-rerank

Faster (no ollama call); lower quality.

Explain mode (debugging)

python3 scripts/retrieve.py "query" --top 5 --explain

Adds an explain block with per-stage diagnostics (BM25 candidate count, dedupe size, etc.).

Direct BM25 inspection

python3 scripts/bm25-index.py query "query" --top 10
python3 scripts/bm25-index.py stats

Rerank strategy probe

python3 scripts/rerank.py "query" --peek

Reports which strategy will run (cosine via ollama / no-op).


Integration with wiki-query

After this skill is installed, skills/wiki-query/SKILL.md standard and deep modes will:

  1. Read wiki/hot.md (always — quick context).
  2. Call python3 scripts/retrieve.py "<query>" --top 5.
  3. Read the candidate pages from the result's absolute_path field (using the v1.7 transport selector — obsidian-cli read or Read tool).
  4. Synthesize with chunk-level citation.

Quick mode is unchanged (hot.md only — never invokes retrieval).

If retrieve.py exits 10 (feature not provisioned), wiki-query falls back to the legacy v1.6 Read(index.md) → Read(N pages) order. No user-visible breakage.


Index maintenance

The index is NOT auto-refreshed when wiki pages change. Re-run after substantive ingest sessions:

python3 scripts/contextual-prefix.py --all      # incremental: only re-processes changed pages
python3 scripts/bm25-index.py build             # always full rebuild (cheap; pure Python)

A future v1.7.x patch will add an opt-in PostToolUse hook that triggers contextual-prefix + BM25 rebuild after every N writes. For v1.7.0, refresh is manual.

To wipe and start over:

rm -rf .vault-meta/chunks/ .vault-meta/bm25/ .vault-meta/embed-cache.json
bash bin/setup-retrieve.sh

Future tiers (v1.7.x roadmap)

Documented for transparency; not implemented in v1.7.0:

Stagev1.7.0v1.7.x target
Contextual prefixAPI / claude-cli / synthetic+ Voyage embed-based pseudo-prefix
Sparse retrievalBM25+ SPLADE learned-sparse
Dense retrieval(none — rerank-only)Separate vector candidate set fused with BM25 (true hybrid)
Reranknomic cosine / no-op+ sentence-transformers BGE-base, Cohere Rerank, Voyage Rerank
Multi-vault(single-vault)Federation via wiki-federate (backlog #15)

Cross-reference

  • Decision tree for transports: wiki/references/transport-fallback.md
  • Concurrency policy: skills/wiki-ingest/SKILL.md §Concurrency
  • DragonScale Memory: wiki/concepts/DragonScale Memory.md
  • Anthropic Contextual Retrieval research: https://www.anthropic.com/news/contextual-retrieval

How to think (10-principle mapping)

When working on this skill, apply the 10-principle loop. See skills/think/SKILL.md for the canonical framework.

#PrincipleApplication here
1OBSERVE (ext)Read the BM25 index state + embed cache state before issuing a query. Stale caches produce wrong answers.
2OBSERVE (int)Am I trusting the cache when it should have been invalidated by recent ingests? Check mtime against last ingest.
3LISTENThe user's query — what does it actually ask? Decompose into intent and terms before matching.
4THINKWhich retrieval strategy fits this query? BM25-only / BM25 + rerank / contextual-prefix + BM25 + rerank.
5CONNECT (lat)How does this hybrid compare to v1.6 baseline? +32pp top-1 / +41% error reduction is the published delta.
6CONNECT (sys)--allow-egress consent gate for Anthropic API; ollama runs local-only; rerank caches under .vault-meta/.
7FEELWhen not provisioned, exit 10 with a friendly "run bash bin/setup-retrieve.sh first" message — not a stack trace.
8ACCEPTWhen retrieval returns empty, say so honestly. Don't fabricate. Don't pad with low-confidence guesses.
9CREATEA ranked candidate list with --explain traceability for every score component.
10GROWQueries that consistently fail → content gaps in the wiki. Track those as autoresearch inputs.

Вставить в README

Ссылка на карточку для вашего README — без картинок и счётчиков.

[DarkPlay: wiki-retrieve](https://darkplay.ru/ai/skills/agricidaniel-claude-obsidian-wiki-retrieve)

Похожие скиллы и другие разделы каталога

Популярное в разделе «Скиллы»

Самые востребованные скиллов раздела по установкам и звёздам.

find-skillsvercel-labs · Помогает находить и устанавливать навыки агентов по запросам вроде «как сделать X»…
4 400 000 устан.
grill-memattpocock · Настойчивое интервью для доработки плана или дизайна.
1 600 000 устан.
hyperframesheygen-com · Обязательная точка входа для любых задач по видео, анимации и motion-графике в…
1 600 000 устан.
hyperframes-cliheygen-com · Цикл разработки HyperFrames CLI: init, add, render, preview, publish и другие команды.
1 600 000 устан.
agent-browservercel-labs · CLI для автоматизации браузера для ИИ-агентов: навигация по страницам, заполнение форм…
1 600 000 устан.
media-useheygen-com · Agent Media OS: единый навык для медиа в HyperFrames — BGM, SFX, изображения, голос, LUT.
1 500 000 устан.
hyperframes-registryheygen-com · Установка и подключение блоков реестра в композиции HyperFrames через add и catalog.
1 400 000 устан.
grill-with-docsmattpocock · Настойчивое интервью для доработки плана или дизайна, попутно создающее документацию (ADR…
1 300 000 устан.
improve-codebase-architecturemattpocock · Поиск в кодовой базе возможностей для углубления, визуальный HTML-отчёт о них и детальный…
1 300 000 устан.
tddmattpocock · Разработка через тестирование (TDD): red-green-refactor и интеграционные тесты.
1 300 000 устан.
Похожее в других разделах каталога

Соседние разделы каталога: возможно, нужный инструмент живёт там.

humanizerblader · Убирает из текста признаки ИИ-генерации, делая его более естественным и человечным…
70 489 ★
gitlabanthropics · Интеграция с DevOps-платформой GitLab. Управление репозиториями, merge request…
100 комп.
enterprise-searchanthropics · Ищите по всем инструментам компании в одном месте. Находите нужное в почте, чатах…
233 комп.
zoom-pluginanthropics · Планирование, разработка и отладка интеграций Zoom через REST API, Meeting SDK, Video…
233 комп.
Scientific Paper Researchgithub · Исследовательский агент: ищет научные статьи и извлекает структурированные данные из…
36 140 ★
qmdtobi · Поиск и извлечение документов из локальных markdown-файлов.
1 комп.
llm-wikialirezarezvani · «Второй мозг» для Claude Code и Obsidian по мотивам LLM Wiki Karpathy. Превращает любой…
510 комп.
agent-archiveanthropics · Agent Archive подключает Claude к базе знаний сообщества об эксплуатации агентов…
38 комп.
anamnese-coreanthropics · Безопасная переносимая память в облаке для всех разговоров: хранит и возвращает личные…
38 комп.
bleuanthropics · Плагин Bleu: превращает идеи в markdown-вики с видением, архитектурой и ADR, переживающую…
38 комп.

Лучшие ИИ-инструменты для генерации текста и копирайтинга

Генерация текста и копирайтинг

Подборка нейросетей для генерации текстов и копирайтинга. Сервисы, которые помогают создавать статьи, посты и рекламные объявления с нуля или по черновику, экономя часы рутинной ра

NeuroscribeNeuroscribe
Есть бесплатный тариф
5.0
GoGPTGogpt
По запросу
5.0
ChatsonicChatsonic
По запросу
4.9
НейроТекстерNeuro-texter
По запросу
4.9
ChatGPTOpenAI
По подписке
4.9
Редактум
Есть бесплатный тариф
4.8
ChadGPTChadgpt
По запросу
4.8
Cosmo ScribeCosmoscribe
Есть бесплатный тариф
4.8
Memo HelperCopilot33
По запросу
4.8
LibraChatLibrachat
Есть бесплатный тариф
4.8

Лучшие ИИ-инструменты для генерации видео

Генерация видео

Подборка нейросетей для генерации и монтажа видео. Инструменты, которые превращают текст в готовые ролики, экономят часы на съемках и постпродакшне. Подходит для SMM-специалистов,

VEED.IOVeed
По запросу
5.0
MootionMootion
По запросу
5.0
FlyviFlyvi
Есть бесплатный тариф
4.9
Google Veo 3.1Google
Платно
4.9
Sora (OpenAI)OpenAI
Платно
4.9
PikaPika
Платно
4.9
captions space
Есть бесплатный тариф
4.8
Клайп
Есть бесплатный тариф
4.8
viralpulse.appViralpulse
По запросу
4.8
Viral Maker AIViral-maker
Есть бесплатный тариф
4.8

Лучшие ИИ-инструменты для генерации изображений

Генерация изображений

Подборка нейросетей для генерации изображений от фотореализма до концепт-арта. Сервисы, которые экономят часы ручной работы, создавая визуал для блогов, рекламы и дизайна за минуты

MagviMagvi
По запросу
5.0
DALL-E 3OpenAI
По подписке
5.0
SupaLabSupalab
По запросу
5.0
Freestyling.aiFreestyling
Есть бесплатный тариф
4.9
ArtGeneration.meArtgeneration
Есть бесплатный тариф
4.9
BigjpgBigjpg
По запросу
4.9
Художник от VKVK
Бесплатно
4.9
Wonderink — ИИ-книги
Есть бесплатный тариф
4.8
Avato AI12ai
По запросу
4.8
Virton AIVirton
По запросу
4.8