hermes - 💡(How to fix) Fix Feature: Semantic Skill Retrieval with SQLite FTS5 — Replace 4500-token broadcast with on-demand search [1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#17649Fetched 2026-04-30 06:46:13
View on GitHub
Comments
1
Participants
1
Timeline
5
Reactions
0
Author
Participants
Timeline (top)
labeled ×4commented ×1

Code Example

Every turn injects ALL skills into system prompt:
- 167 skills indexed
- 17,943 characters
- ~4,485 tokens per turn
- Cost: ~$40/month at 3k turns
- Relevant skills per turn: 0-3 (98% waste)

---

# ~/.hermes/skills.db

CREATE TABLE skills (
    name TEXT PRIMARY KEY,
    description TEXT,
    category TEXT,
    tags TEXT,  -- JSON
    path TEXT,
    use_count INTEGER DEFAULT 0,
    last_used INTEGER
);

CREATE VIRTUAL TABLE skills_fts USING fts5(
    name, description, tags, content='skills'
);

---

# On skill sync: populate DB (one-time cost)
sync_skills_to_db(~/.hermes/skills/, db)

# Per turn: build compact skill index
def build_skills_system_prompt(user_message=""):
    # Top 10 by usage (proven useful)
    pinned = db.get_top_by_usage(limit=10)
    
    # Top 5 by FTS5 match to current message
    candidates = db.search(user_message, limit=5) if user_message else []
    
    # Result: ~15 skills max
    return format_index(pinned + candidates)

---

skills:
  retrieval: semantic  # new: use DB search (default)
  # retrieval: broadcast  # old: inject all skills
  top_k: 15  # max skills per turn
RAW_BUFFERClick to expand / collapse

Feature: Semantic Skill Retrieval with SQLite FTS5

Problem: Skills system doesn't scale — 167 skills × 4500 tokens/turn = massive waste

Current State

Every turn injects ALL skills into system prompt:
- 167 skills indexed
- 17,943 characters
- ~4,485 tokens per turn
- Cost: ~$40/month at 3k turns
- Relevant skills per turn: 0-3 (98% waste)

Memory system has strict caps (MEMORY.md: 3000 chars, USER.md: 2500 chars) to control token cost, but skills get broadcast unfiltered every turn.

Architectural Inconsistency

The codebase ALREADY does semantic retrieval for:

  • session_search() — FTS5 across past conversations
  • mem0_search() — vector search for facts
  • Issue #13332 proposes hybrid search for tools (BM25 + embeddings)

But skills still use batch broadcast from when there were 20 skills, not 167.

Proposed Solution

SQLite-backed skill index with FTS5 semantic search (same pattern as SessionDB):

# ~/.hermes/skills.db

CREATE TABLE skills (
    name TEXT PRIMARY KEY,
    description TEXT,
    category TEXT,
    tags TEXT,  -- JSON
    path TEXT,
    use_count INTEGER DEFAULT 0,
    last_used INTEGER
);

CREATE VIRTUAL TABLE skills_fts USING fts5(
    name, description, tags, content='skills'
);

Workflow

# On skill sync: populate DB (one-time cost)
sync_skills_to_db(~/.hermes/skills/, db)

# Per turn: build compact skill index
def build_skills_system_prompt(user_message=""):
    # Top 10 by usage (proven useful)
    pinned = db.get_top_by_usage(limit=10)
    
    # Top 5 by FTS5 match to current message
    candidates = db.search(user_message, limit=5) if user_message else []
    
    # Result: ~15 skills max
    return format_index(pinned + candidates)

Impact

MetricBeforeAfterSavings
Skills injected1671591%
Tokens/turn4,485~20095%
Cost/month (3k turns)$40.50$1.80$38.70

Implementation Notes

Infrastructure already exists:

  • SQLite + FTS5 experience (SessionDB)
  • Skill sync mechanism (tools/skills_sync.py)
  • Usage tracking (Skill Topography telemetry)

Code changes needed:

  1. skill_db.py — new module with SkillDB class
  2. agent/prompt_builder.py — replace build_skills_system_prompt() with semantic retrieval
  3. tools/skills_sync.py — call db.upsert_skill() during sync
  4. tools/skills_tool.py — call db.record_usage() on skill_view()

Config:

skills:
  retrieval: semantic  # new: use DB search (default)
  # retrieval: broadcast  # old: inject all skills
  top_k: 15  # max skills per turn

Related

  • #13332 — Hybrid tool pre-selection (same problem, different namespace)
  • Skill Topography system already tracks usage stats (can feed use_count)

Priority

P2 (High) — Real cost impact. Memory is capped at 2500 chars to save tokens, but skills waste 4500 tokens/turn. Architectural debt at scale.

extent analysis

TL;DR

Implement a SQLite-backed skill index with FTS5 semantic search to reduce the number of skills injected into the system prompt.

Guidance

  • Review the proposed solution and workflow to understand how the skill index will be populated and used to build a compact skill index.
  • Implement the necessary code changes, including creating a new skill_db.py module, updating agent/prompt_builder.py, and modifying tools/skills_sync.py and tools/skills_tool.py.
  • Configure the system to use the new semantic retrieval method by setting retrieval: semantic in the config file.
  • Test the new implementation to ensure it correctly reduces the number of skills injected into the system prompt and achieves the expected cost savings.

Example

# Example of how to create the skills table and virtual table
CREATE TABLE skills (
    name TEXT PRIMARY KEY,
    description TEXT,
    category TEXT,
    tags TEXT,  -- JSON
    path TEXT,
    use_count INTEGER DEFAULT 0,
    last_used INTEGER
);

CREATE VIRTUAL TABLE skills_fts USING fts5(
    name, description, tags, content='skills'
);

Notes

The implementation relies on existing infrastructure, including SQLite and FTS5 experience, as well as the skill sync mechanism and usage tracking. The code changes needed are outlined in the implementation notes, and the config file needs to be updated to use the new semantic retrieval method.

Recommendation

Apply the proposed workaround by implementing the SQLite-backed skill index with FTS5 semantic search, as it is expected to reduce the number of skills injected into the system prompt by 91% and achieve significant cost savings.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - 💡(How to fix) Fix Feature: Semantic Skill Retrieval with SQLite FTS5 — Replace 4500-token broadcast with on-demand search [1 comments, 1 participants]