sigma-memory 0.1.2 → 0.2.0
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/dist/index.d.ts +11 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -33
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +11 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/vector-store.d.ts +100 -0
- package/dist/vector-store.d.ts.map +1 -0
- package/dist/vector-store.js +322 -0
- package/dist/vector-store.js.map +1 -0
- package/package.json +10 -6
- package/src/index.ts +38 -32
- package/src/types.ts +14 -12
- package/src/vector-store.ts +384 -0
- package/src/vendor.d.ts +30 -0
- package/dist/qmd.d.ts +0 -35
- package/dist/qmd.d.ts.map +0 -1
- package/dist/qmd.js +0 -162
- package/dist/qmd.js.map +0 -1
- package/src/qmd.ts +0 -180
package/src/qmd.ts
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { execSync } from 'child_process';
|
|
2
|
-
import type { MemoryConfig, SearchResult } from './types.js';
|
|
3
|
-
|
|
4
|
-
export class QMDManager {
|
|
5
|
-
private config: MemoryConfig;
|
|
6
|
-
private qmdCommand: string;
|
|
7
|
-
|
|
8
|
-
constructor(config: MemoryConfig) {
|
|
9
|
-
this.config = config;
|
|
10
|
-
this.qmdCommand = config.qmdCommand || 'qmd';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Retourne true si QMD est installé et fonctionnel
|
|
15
|
-
*/
|
|
16
|
-
isAvailable(): boolean {
|
|
17
|
-
if (!this.config.qmdEnabled) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
// Teste si le binaire QMD est accessible
|
|
23
|
-
execSync(`${this.qmdCommand} --version`, {
|
|
24
|
-
stdio: 'ignore',
|
|
25
|
-
timeout: 5000
|
|
26
|
-
});
|
|
27
|
-
return true;
|
|
28
|
-
} catch (error) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Lance `qmd query` et parse les résultats
|
|
35
|
-
*/
|
|
36
|
-
async search(query: string, maxResults = 10): Promise<SearchResult[]> {
|
|
37
|
-
if (!this.isAvailable()) {
|
|
38
|
-
return [];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
const output = execSync(
|
|
43
|
-
`${this.qmdCommand} query "${query.replace(/"/g, '\\"')}" --limit ${maxResults} --format json`,
|
|
44
|
-
{
|
|
45
|
-
encoding: 'utf8',
|
|
46
|
-
timeout: 30000,
|
|
47
|
-
cwd: this.config.memoryDir
|
|
48
|
-
}
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
if (!output.trim()) {
|
|
52
|
-
return [];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const result = JSON.parse(output);
|
|
56
|
-
|
|
57
|
-
// Le format attendu est { results: [{file, line, content, score}] }
|
|
58
|
-
if (result.results && Array.isArray(result.results)) {
|
|
59
|
-
return result.results.map((item: any) => ({
|
|
60
|
-
file: item.file || '',
|
|
61
|
-
line: item.line || 0,
|
|
62
|
-
content: item.content || '',
|
|
63
|
-
score: item.score || 0
|
|
64
|
-
}));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return [];
|
|
68
|
-
} catch (error) {
|
|
69
|
-
// QMD search failed silently
|
|
70
|
-
return [];
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Lance `qmd update` pour reindexer
|
|
76
|
-
*/
|
|
77
|
-
async update(): Promise<boolean> {
|
|
78
|
-
if (!this.isAvailable()) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
try {
|
|
83
|
-
execSync(`${this.qmdCommand} update`, {
|
|
84
|
-
stdio: 'ignore',
|
|
85
|
-
timeout: 60000,
|
|
86
|
-
cwd: this.config.memoryDir
|
|
87
|
-
});
|
|
88
|
-
return true;
|
|
89
|
-
} catch (error) {
|
|
90
|
-
// QMD update failed silently
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Lance `qmd embed` pour recalculer les embeddings
|
|
97
|
-
*/
|
|
98
|
-
async embed(): Promise<boolean> {
|
|
99
|
-
if (!this.isAvailable()) {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
try {
|
|
104
|
-
execSync(`${this.qmdCommand} embed`, {
|
|
105
|
-
stdio: 'ignore',
|
|
106
|
-
timeout: 300000, // 5 minutes pour les embeddings
|
|
107
|
-
cwd: this.config.memoryDir
|
|
108
|
-
});
|
|
109
|
-
return true;
|
|
110
|
-
} catch (error) {
|
|
111
|
-
// QMD embed failed silently
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Liste les collections QMD
|
|
118
|
-
*/
|
|
119
|
-
async collections(): Promise<string[]> {
|
|
120
|
-
if (!this.isAvailable()) {
|
|
121
|
-
return [];
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
try {
|
|
125
|
-
const output = execSync(`${this.qmdCommand} collections --format json`, {
|
|
126
|
-
encoding: 'utf8',
|
|
127
|
-
timeout: 10000,
|
|
128
|
-
cwd: this.config.memoryDir
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
if (!output.trim()) {
|
|
132
|
-
return [];
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const result = JSON.parse(output);
|
|
136
|
-
|
|
137
|
-
// Retourne la liste des noms de collections
|
|
138
|
-
if (result.collections && Array.isArray(result.collections)) {
|
|
139
|
-
return result.collections.map((col: any) => col.name || col);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return [];
|
|
143
|
-
} catch (error) {
|
|
144
|
-
// QMD collections failed silently
|
|
145
|
-
return [];
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Retourne le statut (nb fichiers, nb chunks, dernière mise à jour)
|
|
151
|
-
*/
|
|
152
|
-
async status(): Promise<{ files: number; chunks: number; lastUpdate: string | null } | null> {
|
|
153
|
-
if (!this.isAvailable()) {
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
try {
|
|
158
|
-
const output = execSync(`${this.qmdCommand} status --format json`, {
|
|
159
|
-
encoding: 'utf8',
|
|
160
|
-
timeout: 10000,
|
|
161
|
-
cwd: this.config.memoryDir
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
if (!output.trim()) {
|
|
165
|
-
return { files: 0, chunks: 0, lastUpdate: null };
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const result = JSON.parse(output);
|
|
169
|
-
|
|
170
|
-
return {
|
|
171
|
-
files: result.files || 0,
|
|
172
|
-
chunks: result.chunks || 0,
|
|
173
|
-
lastUpdate: result.lastUpdate || null
|
|
174
|
-
};
|
|
175
|
-
} catch (error) {
|
|
176
|
-
// QMD status check failed silently
|
|
177
|
-
return { files: 0, chunks: 0, lastUpdate: null };
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|