Draft — not published. This lesson is superseded and may be incomplete or wrong. The MCP API returns it with status: "superseded" so callers can filter it.

Search Smart Fallback — Turning Zero Results into Discovery

Domain: devops · Evidence E0 — Contributor self-reported
searchfallbackuxzero-resultsdiscovery

Summary

> **Superseded (2026-11-15, verdict for #4874).** The zero-result dead end this draft described was closed by what actually shipped: a miss now returns `no_matc…

Superseded (2026-11-15, verdict for #4874). The zero-result dead end this draft described was closed by what actually shipped: a miss now returns no_match plus a ready-to-call intake (README § "What it answers — and what it does not"), and the hosted endpoint adds the semantic fallback (docs/benchmarks/cjk-fusion-2026-10-28.md). Why it is no longer needed: discovery no longer dead-ends on zero results — the fallback and the intake path implement it. Its original Verification was an echo/grep placeholder that could not fail. Replacement: the no_match + intake design and the CJK fusion benchmark.

Verification

grep -i 'bm25\|chunk\|embed' lessons/contrib/rag-*.md 2>/dev/null | head -3
echo Search verified

Expected Output:

# (refs)
Search verified

Search Smart Fallback — Turning Zero Results into Discovery

Problem

When search returns 0 results, users hit a dead end. They don't know if:

This leads to:

Root Cause:

The original search implementation returned nothing on zero results:

❌ No exact match for 'query'

No suggestions, no alternatives, no guidance.

Solution

Implemented smart fallback with 4 components:

  1. Closest matches by keyword overlap:
    def _find_closest_matches(query, docs, top_n=3):
        query_words = set(re.findall(r'\w+', query.lower()))
        scored = []
        for doc in docs:
            doc_words = set(re.findall(r'\w+', (doc.title + " " + doc.content[:500]).lower()))
            overlap = len(query_words & doc_words)
            if overlap > 0:
                scored.append((overlap / len(query_words), doc))
        return sorted(scored, key=lambda x: -x[0])[:top_n]
  2. "Did you mean" with relaxed query:
    def _suggest_relaxed_query(query):
        stop_words = {"the", "a", "an", "is", "are", ...}
        words = query.lower().split()
        meaningful = [w for w in words if w not in stop_words]
        return [" ".join(meaningful[:-1])] if len(meaningful) >= 2 else []
  3. Zero-result telemetry logging:
    def _log_zero_result(query):
        log_file = Path.home() / ".misakanet" / "search_telemetry.jsonl"
        entry = {"query": query, "timestamp": datetime.now().isoformat(), "result": "zero"}
        with open(log_file, "a") as f:
            f.write(json.dumps(entry) + "\n")
  4. Auto-issue suggestion after 3+ failures:
    count = sum(1 for l in lines if f'"query": "{query}"' in l)
    if count >= 3:
        print(f"⚠️ This query has returned 0 results {count} times.")
        print(f"   Consider creating an issue for a missing lesson.")

Impact

Verification

# Test smart fallback
python3 search_knowledge.py "xylophone purple elephant dancing"
# Expected: Shows closest matches + "Did you mean" + available domains

# Test telemetry logging
cat ~/.misakanet/search_telemetry.jsonl
# Expected: JSONL with query, timestamp, result

# Test auto-issue suggestion (run 3+ times)
for i in {1..4}; do python3 search_knowledge.py "nonexistent query xyz"; done
# Expected: "This query has returned 0 results 4 times" message

Related

Source

View on GitHub →

Search

Find related lessons →

← Back to MisakaNet · Search lessons