@yamo/memory-mesh 2.3.2 → 3.0.1
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.
- package/README.md +8 -2
- package/bin/memory_mesh.js +1 -1
- package/lib/llm/client.d.ts +86 -0
- package/lib/llm/client.js +300 -357
- package/lib/llm/client.ts +334 -0
- package/lib/llm/index.d.ts +17 -0
- package/lib/llm/index.js +16 -8
- package/lib/llm/index.ts +18 -0
- package/lib/memory/adapters/client.d.ts +120 -0
- package/lib/memory/adapters/client.js +519 -0
- package/lib/memory/adapters/client.ts +519 -0
- package/lib/memory/adapters/config.d.ts +130 -0
- package/lib/memory/adapters/config.js +190 -0
- package/lib/memory/adapters/config.ts +190 -0
- package/lib/memory/adapters/errors.d.ts +84 -0
- package/lib/memory/adapters/errors.js +129 -0
- package/lib/memory/adapters/errors.ts +129 -0
- package/lib/memory/context-manager.d.ts +41 -0
- package/lib/memory/context-manager.js +345 -0
- package/lib/memory/context-manager.ts +345 -0
- package/lib/memory/embeddings/factory.d.ts +57 -0
- package/lib/memory/embeddings/factory.js +149 -0
- package/lib/memory/embeddings/factory.ts +149 -0
- package/lib/memory/embeddings/index.d.ts +2 -0
- package/lib/memory/embeddings/index.js +3 -0
- package/lib/memory/embeddings/index.ts +3 -0
- package/lib/memory/embeddings/service.d.ts +134 -0
- package/lib/memory/embeddings/service.js +516 -0
- package/lib/memory/embeddings/service.ts +516 -0
- package/lib/memory/index.d.ts +9 -0
- package/lib/memory/index.js +10 -1
- package/lib/memory/index.ts +10 -0
- package/lib/memory/memory-mesh.d.ts +332 -0
- package/lib/memory/memory-mesh.js +1470 -678
- package/lib/memory/memory-mesh.ts +1517 -0
- package/lib/memory/memory-translator.d.ts +14 -0
- package/lib/memory/memory-translator.js +126 -0
- package/lib/memory/memory-translator.ts +126 -0
- package/lib/memory/schema.d.ts +130 -0
- package/lib/memory/schema.js +184 -0
- package/lib/memory/schema.ts +184 -0
- package/lib/memory/scorer.d.ts +25 -0
- package/lib/memory/scorer.js +78 -0
- package/lib/memory/scorer.ts +78 -0
- package/lib/memory/search/index.d.ts +1 -0
- package/lib/memory/search/index.js +2 -0
- package/lib/memory/search/index.ts +2 -0
- package/lib/memory/search/keyword-search.d.ts +46 -0
- package/lib/memory/search/keyword-search.js +136 -0
- package/lib/memory/search/keyword-search.ts +136 -0
- package/lib/scrubber/config/defaults.d.ts +46 -0
- package/lib/scrubber/config/defaults.js +50 -57
- package/lib/scrubber/config/defaults.ts +55 -0
- package/lib/scrubber/errors/scrubber-error.d.ts +22 -0
- package/lib/scrubber/errors/scrubber-error.js +28 -32
- package/lib/scrubber/errors/scrubber-error.ts +44 -0
- package/lib/scrubber/index.d.ts +5 -0
- package/lib/scrubber/index.js +4 -23
- package/lib/scrubber/index.ts +6 -0
- package/lib/scrubber/scrubber.d.ts +44 -0
- package/lib/scrubber/scrubber.js +100 -121
- package/lib/scrubber/scrubber.ts +109 -0
- package/lib/scrubber/stages/chunker.d.ts +25 -0
- package/lib/scrubber/stages/chunker.js +74 -91
- package/lib/scrubber/stages/chunker.ts +104 -0
- package/lib/scrubber/stages/metadata-annotator.d.ts +17 -0
- package/lib/scrubber/stages/metadata-annotator.js +55 -65
- package/lib/scrubber/stages/metadata-annotator.ts +75 -0
- package/lib/scrubber/stages/normalizer.d.ts +16 -0
- package/lib/scrubber/stages/normalizer.js +42 -50
- package/lib/scrubber/stages/normalizer.ts +60 -0
- package/lib/scrubber/stages/semantic-filter.d.ts +16 -0
- package/lib/scrubber/stages/semantic-filter.js +42 -52
- package/lib/scrubber/stages/semantic-filter.ts +62 -0
- package/lib/scrubber/stages/structural-cleaner.d.ts +18 -0
- package/lib/scrubber/stages/structural-cleaner.js +66 -75
- package/lib/scrubber/stages/structural-cleaner.ts +83 -0
- package/lib/scrubber/stages/validator.d.ts +17 -0
- package/lib/scrubber/stages/validator.js +46 -56
- package/lib/scrubber/stages/validator.ts +67 -0
- package/lib/scrubber/telemetry.d.ts +29 -0
- package/lib/scrubber/telemetry.js +54 -58
- package/lib/scrubber/telemetry.ts +62 -0
- package/lib/scrubber/utils/hash.d.ts +14 -0
- package/lib/scrubber/utils/hash.js +30 -32
- package/lib/scrubber/utils/hash.ts +40 -0
- package/lib/scrubber/utils/html-parser.d.ts +14 -0
- package/lib/scrubber/utils/html-parser.js +32 -39
- package/lib/scrubber/utils/html-parser.ts +46 -0
- package/lib/scrubber/utils/pattern-matcher.d.ts +12 -0
- package/lib/scrubber/utils/pattern-matcher.js +48 -57
- package/lib/scrubber/utils/pattern-matcher.ts +64 -0
- package/lib/scrubber/utils/token-counter.d.ts +18 -0
- package/lib/scrubber/utils/token-counter.js +24 -25
- package/lib/scrubber/utils/token-counter.ts +32 -0
- package/lib/utils/logger.d.ts +19 -0
- package/lib/utils/logger.js +65 -0
- package/lib/utils/logger.ts +65 -0
- package/lib/utils/skill-metadata.d.ts +24 -0
- package/lib/utils/skill-metadata.js +133 -0
- package/lib/utils/skill-metadata.ts +133 -0
- package/lib/yamo/emitter.d.ts +46 -0
- package/lib/yamo/emitter.js +79 -143
- package/lib/yamo/emitter.ts +171 -0
- package/lib/yamo/index.d.ts +14 -0
- package/lib/yamo/index.js +6 -7
- package/lib/yamo/index.ts +16 -0
- package/lib/yamo/schema.d.ts +56 -0
- package/lib/yamo/schema.js +82 -108
- package/lib/yamo/schema.ts +133 -0
- package/package.json +13 -8
- package/index.d.ts +0 -111
- package/lib/embeddings/factory.js +0 -151
- package/lib/embeddings/index.js +0 -2
- package/lib/embeddings/service.js +0 -586
- package/lib/index.js +0 -6
- package/lib/lancedb/client.js +0 -633
- package/lib/lancedb/config.js +0 -215
- package/lib/lancedb/errors.js +0 -144
- package/lib/lancedb/index.js +0 -4
- package/lib/lancedb/schema.js +0 -217
- package/lib/search/index.js +0 -1
- package/lib/search/keyword-search.js +0 -144
- package/lib/utils/index.js +0 -1
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Simple Keyword Search Engine (In-Memory)
|
|
3
|
-
* Provides basic TF-IDF style retrieval to complement vector search
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export class KeywordSearch {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.index = new Map(); // token -> Map<docId, tf>
|
|
9
|
-
this.docLengths = new Map(); // docId -> length
|
|
10
|
-
this.idf = new Map(); // token -> idf value
|
|
11
|
-
this.docs = new Map(); // docId -> content (optional, for snippet)
|
|
12
|
-
this.isDirty = false;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Tokenize text into normalized terms
|
|
17
|
-
* @param {string} text
|
|
18
|
-
* @returns {string[]} tokens
|
|
19
|
-
*/
|
|
20
|
-
tokenize(text) {
|
|
21
|
-
if (!text) return [];
|
|
22
|
-
return text.toLowerCase()
|
|
23
|
-
.replace(/[^\w\s]/g, '') // Remove punctuation
|
|
24
|
-
.split(/\s+/)
|
|
25
|
-
.filter(t => t.length > 2) // Filter stopwords/short
|
|
26
|
-
.map(t => t.substring(0, 20)); // Truncate
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Add a document to the index
|
|
31
|
-
* @param {string} id
|
|
32
|
-
* @param {string} content
|
|
33
|
-
* @param {Object} [metadata]
|
|
34
|
-
*/
|
|
35
|
-
add(id, content, metadata = {}) {
|
|
36
|
-
const tokens = this.tokenize(content);
|
|
37
|
-
const termFreqs = new Map();
|
|
38
|
-
|
|
39
|
-
tokens.forEach(t => {
|
|
40
|
-
termFreqs.set(t, (termFreqs.get(t) || 0) + 1);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
this.docLengths.set(id, tokens.length);
|
|
44
|
-
this.docs.set(id, { content, metadata });
|
|
45
|
-
|
|
46
|
-
// Update index
|
|
47
|
-
for (const [token, freq] of termFreqs.entries()) {
|
|
48
|
-
if (!this.index.has(token)) {
|
|
49
|
-
this.index.set(token, new Map());
|
|
50
|
-
}
|
|
51
|
-
this.index.get(token).set(id, freq);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
this.isDirty = true;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Remove a document
|
|
59
|
-
* @param {string} id
|
|
60
|
-
*/
|
|
61
|
-
remove(id) {
|
|
62
|
-
this.docLengths.delete(id);
|
|
63
|
-
this.docs.delete(id);
|
|
64
|
-
|
|
65
|
-
// This is expensive O(Vocab), but okay for small scale
|
|
66
|
-
for (const docMap of this.index.values()) {
|
|
67
|
-
docMap.delete(id);
|
|
68
|
-
}
|
|
69
|
-
this.isDirty = true;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Recalculate IDF scores
|
|
74
|
-
*/
|
|
75
|
-
_computeStats() {
|
|
76
|
-
if (!this.isDirty) return;
|
|
77
|
-
|
|
78
|
-
const N = this.docLengths.size;
|
|
79
|
-
this.idf.clear();
|
|
80
|
-
|
|
81
|
-
for (const [token, docMap] of this.index.entries()) {
|
|
82
|
-
const df = docMap.size;
|
|
83
|
-
// Standard IDF: log(N / (df + 1)) + 1
|
|
84
|
-
const idf = Math.log(N / (df + 1)) + 1;
|
|
85
|
-
this.idf.set(token, idf);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
this.isDirty = false;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Search for query terms
|
|
93
|
-
* @param {string} query
|
|
94
|
-
* @param {Object} options
|
|
95
|
-
* @returns {Array<{id: string, score: number, matches: string[], content: string, metadata: Object}>}
|
|
96
|
-
*/
|
|
97
|
-
search(query, options = {}) {
|
|
98
|
-
this._computeStats();
|
|
99
|
-
|
|
100
|
-
const tokens = this.tokenize(query);
|
|
101
|
-
const scores = new Map(); // docId -> score
|
|
102
|
-
const matches = new Map(); // docId -> matched tokens
|
|
103
|
-
|
|
104
|
-
const limit = options.limit || 10;
|
|
105
|
-
|
|
106
|
-
for (const token of tokens) {
|
|
107
|
-
const docMap = this.index.get(token);
|
|
108
|
-
if (!docMap) continue;
|
|
109
|
-
|
|
110
|
-
const idf = this.idf.get(token) || 0;
|
|
111
|
-
|
|
112
|
-
for (const [docId, tf] of docMap.entries()) {
|
|
113
|
-
// TF-IDF Score
|
|
114
|
-
// Score = tf * idf * (normalization?)
|
|
115
|
-
// Simple variant:
|
|
116
|
-
const score = tf * idf;
|
|
117
|
-
|
|
118
|
-
scores.set(docId, (scores.get(docId) || 0) + score);
|
|
119
|
-
|
|
120
|
-
if (!matches.has(docId)) matches.set(docId, []);
|
|
121
|
-
matches.get(docId).push(token);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Convert to array and sort
|
|
126
|
-
return Array.from(scores.entries())
|
|
127
|
-
.map(([id, score]) => ({
|
|
128
|
-
id,
|
|
129
|
-
score,
|
|
130
|
-
matches: matches.get(id) || [],
|
|
131
|
-
...this.docs.get(id)
|
|
132
|
-
}))
|
|
133
|
-
.sort((a, b) => b.score - a.score)
|
|
134
|
-
.slice(0, limit);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Bulk load records
|
|
139
|
-
* @param {Array} records
|
|
140
|
-
*/
|
|
141
|
-
load(records) {
|
|
142
|
-
records.forEach(r => this.add(r.id, r.content, r.metadata));
|
|
143
|
-
}
|
|
144
|
-
}
|
package/lib/utils/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// No exports - all utilities removed as unused
|