agentleFS
JaimeParkerJaimeParker/stable-jarvis/skills/mao-semantic-search/SKILL.md

mao-semantic-search

Skill19 starsChanged 5 months agoMITView on GitHub

Search Mao Zedong Selected Works by conceptual meaning using vector embeddings. Builds a local embedding index over all 230 articles across 5 volumes, then performs cosine similarity search at query time. Before any search, the agent MUST check the index state: Decision logic: The index is static — articles don't change, so rebuild is only needed once. With optional provider override: The scripts locate the Mao works automatically via MAO_WORKS_DIR env var or the default path assets/mao-selected-works/. If the works…

  • Reads credentials

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Search Mao Zedong Selected Works by conceptual meaning using vector embeddings.

    line 3
  2. Distinctive:

    Before any search, the agent MUST check the index state:

    line 28
  3. Very specific:

    After getting results, use the Read tool with the path field to read full content:

    line 74
  4. Very specific:

    All settings via environment variables (loaded from .env):

    line 104
  5. Distinctive:

    Rebuild: Only needed if the source .md files are regenerated or updated

    line 119

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Mao Semantic Search

Search Mao Zedong Selected Works by conceptual meaning using vector embeddings. Builds a local embedding index over all 230 articles across 5 volumes, then performs cosine similarity search at query time.

When to Use

  • User asks a thematic/conceptual question about Mao's works ("What did Mao say about guerrilla warfare?")
  • Keyword search over the .md files is insufficient
  • User wants to find passages related to a concept without knowing exact terminology
  • As a pre-retrieval step before deep-reading specific articles

Architecture

assets/mao-selected-works/  ──build_index.py──>  temp/mao/embeddings.json  <──search.py──  User Query
(.md files, 5 vols)                             │
                                                 └── JSON index, 230 entries
  • Index: Flat JSON, one embedding per article (full body text, frontmatter excluded), stored at temp/mao/embeddings.json
  • Embeddings: Reuses stable_jarvis.llm.embed() — same provider stack as obsidian-semantic-search (local / qwen / openai)
  • Search: Brute-force cosine similarity, O(n) over all articles

Workflow

Phase 0: Check Index Freshness (Always First)

Before any search, the agent MUST check the index state:

python skills/mao-semantic-search/scripts/build_index.py --stats

Decision logic:

StateAction
Index existsSkip build, proceed to Phase 2 directly
Index does NOT existRun build_index.py (full build, ~230 articles)

The index is static — articles don't change, so rebuild is only needed once.

Phase 1: Build Index (If Needed)

python skills/mao-semantic-search/scripts/build_index.py

With optional provider override:

python skills/mao-semantic-search/scripts/build_index.py --provider qwen

The scripts locate the Mao works automatically via MAO_WORKS_DIR env var or the default path assets/mao-selected-works/. If the works are at a non-standard location, set it first:

export MAO_WORKS_DIR="/path/to/mao-selected-works"

Phase 2: Semantic Search

python skills/mao-semantic-search/scripts/search.py "query text" --top-k 5

Returns JSON array of results, each with:

  • title — Article title
  • volume — Volume number (1–5)
  • path — Relative path in mao-selected-works/ (for reading full text)
  • score — Cosine similarity (0–1, higher = more relevant)
  • text_snippet — First 200 chars of the article body

Phase 3: Read Full Articles

After getting results, use the Read tool with the path field to read full content:

Read(assets/mao-selected-works/vol-01/001-中国社会各阶级的分析.md)

Phase 4: Present Results

Format search results for the user with:

  • Article title and volume
  • Relevance score
  • Brief excerpt from text_snippet
  • Direct path for further reading

Commands

CommandPurpose
build_index.pyBuild embedding index (full build)
build_index.py --provider qwenBuild with specific embedding provider
build_index.py --statsShow index statistics
build_index.py --clearRemove index file
search.py "query"Semantic search (top 5)
search.py "query" --top-k 10More results
search.py "query" --min-score 0.4Filter low-relevance results
search.py "query" --provider qwenUse specific embedding provider
search.py "query" --volume 1Search only within a specific volume

Configuration

All settings via environment variables (loaded from .env):

VariableDefaultDescription
MAO_WORKS_DIRassets/mao-selected-works/Path to Mao Selected Works .md files
EMBEDDING_PROVIDERlocallocal / qwen / openai
EMBEDDING_MODELProvider-dependentModel override
EMBEDDING_API_KEYFrom {PROVIDER}_API_KEYAPI key for cloud embeddings

The local provider uses sentence-transformers (paraphrase-multilingual-MiniLM-L12-v2) and requires no API key.

Index Management

  • Static index: Articles don't change, so the index is built once and reused indefinitely
  • Index size: ~230 embeddings, ~4MB total article text, resulting index ~200–400KB
  • Rebuild: Only needed if the source .md files are regenerated or updated

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.