name: kb-search description: Hybrid semantic+keyword search over the KB LanceDB index — returns ranked chunks with source, section, and status. version: 1.0.0
KB Search
You perform hybrid semantic and keyword search over the project KB's LanceDB index. Use this skill instead of loading all KB files when searching for a specific concept, term, or constraint.
Prerequisite: kb/.index/ must exist. Run /kb-reindex first if not.
Steps
Step 1 — Pre-condition check
[ -d kb/.index ] && echo "index: present" || echo "index: absent"
If absent:
⛔ No KB index found at
kb/.index/. Run/kb-reindexto build the index first.
Step 2 — Execute hybrid search
Accept:
query(string): the search querytop_k(int, default: 5): number of results to returninclude_all_statuses(bool, default: false): if false, filter outhistoricalandsupersededchunks
Hybrid search algorithm:
Vector search: embed
querywith the same model used for indexing. Compute cosine similarity against all chunks inkb_chunks. Retrieve toptop_k * 3candidates.Keyword search: tokenize
query. Score each candidate with BM25 against itscontentfield.Score fusion: combine vector score (weight 0.7) and BM25 score (weight 0.3). Re-rank by fused score.
Status filter: if
include_all_statuses = false, remove chunks wherestatusishistoricalorsuperseded. Apply this as a pre-filter on the vector query (not post-fusion) so thattop_k * 3candidates are drawn only from live-doctrine and derived chunks, ensuringtop_kresults are always available when they exist.Return top
top_kresults.
Step 3 — Format results
Return a ranked list:
KB Search Results for: "<query>"
Showing top N results (historical/superseded filtered)
1. [score: 0.92] kb/properties.md § "Invariants"
> "All database writes must be wrapped in explicit transactions..."
Status: live-doctrine
2. [score: 0.87] kb/spec.md § "API Contract"
> "The API must return errors in the format {error: string, code: int}..."
Status: live-doctrine
3. [score: 0.61] kb/architecture.md § "Storage Layer"
> "PostgreSQL is the primary storage backend..."
Status: live-doctrine
Low confidence notice: if the top result's fused score is below 0.3, or if fewer than top_k results were returned (can happen when most KB content is filtered out):
⚠️ Low confidence results — no strong match found for "
". Consider: broader query, running /kb-reindexto refresh stale embeddings, or checking if the concept is documented at all.
Step 4 — Follow-up
After returning results, offer:
"Open any of these files for full context? Or refine the query?"
Rules
- Never return
historicalorsupersededchunks as primary results (unlessinclude_all_statuses: true) - Never modify the KB index from this skill — read-only
- If the index is stale (kb files modified after last reindex), note: "Index may be stale — run
/kb-reindexfor fresh results" - Score threshold 0.3 is the default low-confidence floor — do not suppress results, just warn