@cachly-dev/mcp-server 0.9.17 → 0.9.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,101 @@
1
+ import { Redis } from 'ioredis';
2
+ /**
3
+ * Stopwords — filtered out during tokenization.
4
+ * Covers: English, German, French, Spanish, Italian, Portuguese,
5
+ * Chinese (Simplified + Traditional), Japanese, Korean.
6
+ * Keeps the index small and scores meaningful.
7
+ */
8
+ declare const STOPWORDS: Set<string>;
9
+ /**
10
+ * Convert a katakana string to Hepburn romaji.
11
+ * Handles digraphs, geminate consonants (ッ), and long vowel marks (ー).
12
+ */
13
+ declare function katakanaToRomaji(kata: string): string;
14
+ /**
15
+ * Arabic light stemmer — strips definite article and common prefix particles.
16
+ * Handles: ال (al-), و (wa-), ب (bi-), ل (li-), ف (fa-), ك (ka-).
17
+ * Runs iteratively (max 3 passes) so compound prefixes like فال- are fully
18
+ * resolved: فالخطأ → الخطأ → خطأ.
19
+ * Only strips when the result is still ≥ 3 chars to avoid over-stemming.
20
+ */
21
+ declare function arabicLightStem(word: string): string;
22
+ declare const CROSS_LINGUAL_MAP: Map<string, string[]>;
23
+ /**
24
+ * Expand a token to its cross-lingual synonyms.
25
+ * Returns synonyms to be added to the token stream (pre-tokenized).
26
+ * CJK synonyms are NOT pre-bigram'd here — caller handles that.
27
+ */
28
+ declare function expandCrossLingual(token: string): string[];
29
+ /**
30
+ * Tokenize text into meaningful keywords.
31
+ * Handles accented Latin, RTL (Arabic, Hebrew), and CJK (Chinese, Japanese, Korean).
32
+ *
33
+ * Features:
34
+ * • CJK → character bigrams
35
+ * • Katakana → additionally emits Hepburn romaji tokens (enables romaji queries)
36
+ * • Arabic → word tokenization + iterative prefix stemming (ال/و/ب/ل/ف/ك)
37
+ * • Hebrew → word tokenization + iterative prefix stemming (ה/ו/ב/ל/מ/כ)
38
+ * • Farsi → word tokenization + suffix/prefix stemming (ها/های plural, می prefix)
39
+ * • Hindi → Devanagari word tokenization + light suffix stemming
40
+ * • All scripts → cross-lingual synonym expansion (EN↔JA↔ZH↔KO↔AR↔HE↔FA↔HI↔DE↔FR↔ES↔IT↔PT)
41
+ */
42
+ declare function tokenize(text: string): string[];
43
+ /**
44
+ * Split a multi-topic query into sub-queries.
45
+ * Detects numbered lists, semicolons, "and also", line breaks, etc.
46
+ *
47
+ * Example: "deploy API fix routing and also check auth" →
48
+ * ["deploy API fix routing", "check auth"]
49
+ *
50
+ * Example: "1. deploy 2. fix routing 3. auth" →
51
+ * ["deploy", "fix routing", "auth"]
52
+ */
53
+ declare function splitMultiQuery(query: string): string[];
54
+ /**
55
+ * Zero-results query log — in-memory FIFO ring (max 500 entries).
56
+ * Exposed via /health for observability. Never persisted.
57
+ */
58
+ interface ZeroResultEntry {
59
+ query: string;
60
+ ts: number;
61
+ }
62
+ declare const ZERO_RESULTS_LOG: ZeroResultEntry[];
63
+ declare let zeroResultsTotal: number;
64
+ declare function logZeroResult(query: string): void;
65
+ /** Global index vocabulary — rebuilt on each keywordSearch call from the doc set. */
66
+ declare let _indexVocab: Set<string>;
67
+ interface KeywordMatch {
68
+ key: string;
69
+ content: string;
70
+ score: number;
71
+ matchedWords: string[];
72
+ subQuery?: string;
73
+ }
74
+ /**
75
+ * Levenshtein distance — edit distance between two strings.
76
+ * Used for typo-tolerant fuzzy matching (distance ≤ 2 = match).
77
+ * O(n*m) but strings are short (tokens), so this is fast.
78
+ */
79
+ declare function levenshtein(a: string, b: string): number;
80
+ /** Extract a timestamp from JSON content (looks for "ts" or "created" fields). */
81
+ declare function extractTimestamp(content: string): number | undefined;
82
+ /** Recency multiplier: 1.0 for now, 0.5 after half-life days, exponential decay. */
83
+ declare function recencyBoost(timestampMs: number | undefined): number;
84
+ /**
85
+ * BM25+ with Bigram Proximity, Recency Boost, and Fuzzy Matching.
86
+ *
87
+ * Architecture:
88
+ * ┌─────────────────────────────────────────────────────────────────┐
89
+ * │ Query: "deploy API fix routing; check auth" │
90
+ * │ ↓ splitMultiQuery │
91
+ * │ Sub-queries: ["deploy API fix routing", "check auth"] │
92
+ * │ ↓ for each sub-query │
93
+ * │ Tokenize → BM25+ score per doc → Bigram boost → Fuzzy match │
94
+ * │ ↓ merge & deduplicate │
95
+ * │ Recency boost → Sort → Top-K │
96
+ * └─────────────────────────────────────────────────────────────────┘
97
+ */
98
+ declare function keywordSearch(redis: Redis, patterns: string[], query: string, topK?: number): Promise<KeywordMatch[]>;
99
+ export { tokenize, splitMultiQuery, levenshtein, recencyBoost, extractTimestamp, STOPWORDS, katakanaToRomaji, arabicLightStem, expandCrossLingual, CROSS_LINGUAL_MAP };
100
+ export type { KeywordMatch };
101
+ export { keywordSearch, ZERO_RESULTS_LOG, logZeroResult, _indexVocab as indexVocab, zeroResultsTotal };