ruvector 0.2.21 → 0.2.23

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.
Files changed (123) hide show
  1. package/README.md +2 -2
  2. package/bin/cli.js +160 -0
  3. package/package.json +9 -5
  4. package/src/decompiler/api-prober.js +302 -0
  5. package/src/decompiler/model-decompiler.js +423 -0
  6. package/dist/analysis/complexity.d.ts +0 -52
  7. package/dist/analysis/complexity.d.ts.map +0 -1
  8. package/dist/analysis/complexity.js +0 -146
  9. package/dist/analysis/index.d.ts +0 -15
  10. package/dist/analysis/index.d.ts.map +0 -1
  11. package/dist/analysis/index.js +0 -38
  12. package/dist/analysis/patterns.d.ts +0 -71
  13. package/dist/analysis/patterns.d.ts.map +0 -1
  14. package/dist/analysis/patterns.js +0 -243
  15. package/dist/analysis/security.d.ts +0 -51
  16. package/dist/analysis/security.d.ts.map +0 -1
  17. package/dist/analysis/security.js +0 -139
  18. package/dist/core/adaptive-embedder.d.ts +0 -156
  19. package/dist/core/adaptive-embedder.d.ts.map +0 -1
  20. package/dist/core/adaptive-embedder.js +0 -838
  21. package/dist/core/agentdb-fast.d.ts +0 -149
  22. package/dist/core/agentdb-fast.d.ts.map +0 -1
  23. package/dist/core/agentdb-fast.js +0 -301
  24. package/dist/core/ast-parser.d.ts +0 -108
  25. package/dist/core/ast-parser.d.ts.map +0 -1
  26. package/dist/core/ast-parser.js +0 -602
  27. package/dist/core/attention-fallbacks.d.ts +0 -321
  28. package/dist/core/attention-fallbacks.d.ts.map +0 -1
  29. package/dist/core/attention-fallbacks.js +0 -552
  30. package/dist/core/cluster-wrapper.d.ts +0 -148
  31. package/dist/core/cluster-wrapper.d.ts.map +0 -1
  32. package/dist/core/cluster-wrapper.js +0 -271
  33. package/dist/core/coverage-router.d.ts +0 -88
  34. package/dist/core/coverage-router.d.ts.map +0 -1
  35. package/dist/core/coverage-router.js +0 -315
  36. package/dist/core/diff-embeddings.d.ts +0 -93
  37. package/dist/core/diff-embeddings.d.ts.map +0 -1
  38. package/dist/core/diff-embeddings.js +0 -334
  39. package/dist/core/gnn-wrapper.d.ts +0 -143
  40. package/dist/core/gnn-wrapper.d.ts.map +0 -1
  41. package/dist/core/gnn-wrapper.js +0 -213
  42. package/dist/core/graph-algorithms.d.ts +0 -83
  43. package/dist/core/graph-algorithms.d.ts.map +0 -1
  44. package/dist/core/graph-algorithms.js +0 -514
  45. package/dist/core/graph-wrapper.d.ts +0 -147
  46. package/dist/core/graph-wrapper.d.ts.map +0 -1
  47. package/dist/core/graph-wrapper.js +0 -299
  48. package/dist/core/index.d.ts +0 -48
  49. package/dist/core/index.d.ts.map +0 -1
  50. package/dist/core/index.js +0 -89
  51. package/dist/core/intelligence-engine.d.ts +0 -258
  52. package/dist/core/intelligence-engine.d.ts.map +0 -1
  53. package/dist/core/intelligence-engine.js +0 -1030
  54. package/dist/core/learning-engine.d.ts +0 -160
  55. package/dist/core/learning-engine.d.ts.map +0 -1
  56. package/dist/core/learning-engine.js +0 -589
  57. package/dist/core/neural-embeddings.d.ts +0 -393
  58. package/dist/core/neural-embeddings.d.ts.map +0 -1
  59. package/dist/core/neural-embeddings.js +0 -1091
  60. package/dist/core/neural-perf.d.ts +0 -331
  61. package/dist/core/neural-perf.d.ts.map +0 -1
  62. package/dist/core/neural-perf.js +0 -704
  63. package/dist/core/onnx/loader.js +0 -348
  64. package/dist/core/onnx/pkg/LICENSE +0 -21
  65. package/dist/core/onnx/pkg/loader.js +0 -348
  66. package/dist/core/onnx/pkg/package.json +0 -3
  67. package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm.d.ts +0 -112
  68. package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm.js +0 -5
  69. package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm_bg.js +0 -638
  70. package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm_bg.wasm +0 -0
  71. package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm_bg.wasm.d.ts +0 -29
  72. package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm_cjs.js +0 -127
  73. package/dist/core/onnx-embedder.d.ts +0 -105
  74. package/dist/core/onnx-embedder.d.ts.map +0 -1
  75. package/dist/core/onnx-embedder.js +0 -410
  76. package/dist/core/onnx-llm.d.ts +0 -206
  77. package/dist/core/onnx-llm.d.ts.map +0 -1
  78. package/dist/core/onnx-llm.js +0 -430
  79. package/dist/core/onnx-optimized.d.ts +0 -109
  80. package/dist/core/onnx-optimized.d.ts.map +0 -1
  81. package/dist/core/onnx-optimized.js +0 -419
  82. package/dist/core/parallel-intelligence.d.ts +0 -109
  83. package/dist/core/parallel-intelligence.d.ts.map +0 -1
  84. package/dist/core/parallel-intelligence.js +0 -340
  85. package/dist/core/parallel-workers.d.ts +0 -177
  86. package/dist/core/parallel-workers.d.ts.map +0 -1
  87. package/dist/core/parallel-workers.js +0 -671
  88. package/dist/core/router-wrapper.d.ts +0 -62
  89. package/dist/core/router-wrapper.d.ts.map +0 -1
  90. package/dist/core/router-wrapper.js +0 -209
  91. package/dist/core/rvf-wrapper.d.ts +0 -86
  92. package/dist/core/rvf-wrapper.d.ts.map +0 -1
  93. package/dist/core/rvf-wrapper.js +0 -102
  94. package/dist/core/sona-wrapper.d.ts +0 -226
  95. package/dist/core/sona-wrapper.d.ts.map +0 -1
  96. package/dist/core/sona-wrapper.js +0 -282
  97. package/dist/core/tensor-compress.d.ts +0 -134
  98. package/dist/core/tensor-compress.d.ts.map +0 -1
  99. package/dist/core/tensor-compress.js +0 -432
  100. package/dist/index.d.ts +0 -105
  101. package/dist/index.d.ts.map +0 -1
  102. package/dist/index.js +0 -221
  103. package/dist/services/embedding-service.d.ts +0 -136
  104. package/dist/services/embedding-service.d.ts.map +0 -1
  105. package/dist/services/embedding-service.js +0 -294
  106. package/dist/services/index.d.ts +0 -6
  107. package/dist/services/index.d.ts.map +0 -1
  108. package/dist/services/index.js +0 -26
  109. package/dist/types.d.ts +0 -145
  110. package/dist/types.d.ts.map +0 -1
  111. package/dist/types.js +0 -2
  112. package/dist/workers/benchmark.d.ts +0 -44
  113. package/dist/workers/benchmark.d.ts.map +0 -1
  114. package/dist/workers/benchmark.js +0 -230
  115. package/dist/workers/index.d.ts +0 -10
  116. package/dist/workers/index.d.ts.map +0 -1
  117. package/dist/workers/index.js +0 -25
  118. package/dist/workers/native-worker.d.ts +0 -76
  119. package/dist/workers/native-worker.d.ts.map +0 -1
  120. package/dist/workers/native-worker.js +0 -490
  121. package/dist/workers/types.d.ts +0 -69
  122. package/dist/workers/types.d.ts.map +0 -1
  123. package/dist/workers/types.js +0 -7
@@ -1,93 +0,0 @@
1
- /**
2
- * Diff Embeddings - Semantic encoding of git diffs
3
- *
4
- * Generates embeddings for code changes to enable:
5
- * - Change classification (feature, bugfix, refactor)
6
- * - Similar change detection
7
- * - Risk assessment
8
- * - Review prioritization
9
- */
10
- export interface DiffHunk {
11
- file: string;
12
- oldStart: number;
13
- oldLines: number;
14
- newStart: number;
15
- newLines: number;
16
- content: string;
17
- additions: string[];
18
- deletions: string[];
19
- }
20
- export interface DiffAnalysis {
21
- file: string;
22
- hunks: DiffHunk[];
23
- totalAdditions: number;
24
- totalDeletions: number;
25
- complexity: number;
26
- riskScore: number;
27
- category: 'feature' | 'bugfix' | 'refactor' | 'docs' | 'test' | 'config' | 'unknown';
28
- embedding?: number[];
29
- }
30
- export interface CommitAnalysis {
31
- hash: string;
32
- message: string;
33
- author: string;
34
- date: string;
35
- files: DiffAnalysis[];
36
- totalAdditions: number;
37
- totalDeletions: number;
38
- riskScore: number;
39
- embedding?: number[];
40
- }
41
- /**
42
- * Parse a unified diff into hunks
43
- */
44
- export declare function parseDiff(diff: string): DiffHunk[];
45
- /**
46
- * Classify a change based on patterns
47
- */
48
- export declare function classifyChange(diff: string, message?: string): 'feature' | 'bugfix' | 'refactor' | 'docs' | 'test' | 'config' | 'unknown';
49
- /**
50
- * Calculate risk score for a diff
51
- */
52
- export declare function calculateRiskScore(analysis: DiffAnalysis): number;
53
- /**
54
- * Analyze a single file diff
55
- */
56
- export declare function analyzeFileDiff(file: string, diff: string, message?: string): Promise<DiffAnalysis>;
57
- /**
58
- * Get diff for a commit
59
- */
60
- export declare function getCommitDiff(commitHash?: string): string;
61
- /**
62
- * Get diff for staged changes
63
- */
64
- export declare function getStagedDiff(): string;
65
- /**
66
- * Get diff for unstaged changes
67
- */
68
- export declare function getUnstagedDiff(): string;
69
- /**
70
- * Analyze a commit
71
- */
72
- export declare function analyzeCommit(commitHash?: string): Promise<CommitAnalysis>;
73
- /**
74
- * Find similar past commits based on diff embeddings
75
- */
76
- export declare function findSimilarCommits(currentDiff: string, recentCommits?: number, topK?: number): Promise<Array<{
77
- hash: string;
78
- similarity: number;
79
- message: string;
80
- }>>;
81
- declare const _default: {
82
- parseDiff: typeof parseDiff;
83
- classifyChange: typeof classifyChange;
84
- calculateRiskScore: typeof calculateRiskScore;
85
- analyzeFileDiff: typeof analyzeFileDiff;
86
- analyzeCommit: typeof analyzeCommit;
87
- getCommitDiff: typeof getCommitDiff;
88
- getStagedDiff: typeof getStagedDiff;
89
- getUnstagedDiff: typeof getUnstagedDiff;
90
- findSimilarCommits: typeof findSimilarCommits;
91
- };
92
- export default _default;
93
- //# sourceMappingURL=diff-embeddings.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"diff-embeddings.d.ts","sourceRoot":"","sources":["../../src/core/diff-embeddings.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,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,IAAI,MAAM,CAStC;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,MAAM,CASxC;AAED;;GAEG;AACH,wBAAsB,aAAa,CAAC,UAAU,GAAE,MAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAwDxF;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,WAAW,EAAE,MAAM,EACnB,aAAa,GAAE,MAAW,EAC1B,IAAI,GAAE,MAAU,GACf,OAAO,CAAC,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAgCvE;;;;;;;;;;;;AAmBD,wBAUE"}
@@ -1,334 +0,0 @@
1
- "use strict";
2
- /**
3
- * Diff Embeddings - Semantic encoding of git diffs
4
- *
5
- * Generates embeddings for code changes to enable:
6
- * - Change classification (feature, bugfix, refactor)
7
- * - Similar change detection
8
- * - Risk assessment
9
- * - Review prioritization
10
- */
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.parseDiff = parseDiff;
13
- exports.classifyChange = classifyChange;
14
- exports.calculateRiskScore = calculateRiskScore;
15
- exports.analyzeFileDiff = analyzeFileDiff;
16
- exports.getCommitDiff = getCommitDiff;
17
- exports.getStagedDiff = getStagedDiff;
18
- exports.getUnstagedDiff = getUnstagedDiff;
19
- exports.analyzeCommit = analyzeCommit;
20
- exports.findSimilarCommits = findSimilarCommits;
21
- const child_process_1 = require("child_process");
22
- const onnx_embedder_1 = require("./onnx-embedder");
23
- /**
24
- * Parse a unified diff into hunks
25
- */
26
- function parseDiff(diff) {
27
- const hunks = [];
28
- const lines = diff.split('\n');
29
- let currentFile = '';
30
- let currentHunk = null;
31
- for (const line of lines) {
32
- // File header
33
- if (line.startsWith('diff --git')) {
34
- const match = line.match(/diff --git a\/(.+) b\/(.+)/);
35
- if (match) {
36
- currentFile = match[2];
37
- }
38
- }
39
- // Hunk header
40
- if (line.startsWith('@@')) {
41
- if (currentHunk) {
42
- hunks.push(currentHunk);
43
- }
44
- const match = line.match(/@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@/);
45
- if (match) {
46
- currentHunk = {
47
- file: currentFile,
48
- oldStart: parseInt(match[1]),
49
- oldLines: parseInt(match[2] || '1'),
50
- newStart: parseInt(match[3]),
51
- newLines: parseInt(match[4] || '1'),
52
- content: '',
53
- additions: [],
54
- deletions: [],
55
- };
56
- }
57
- }
58
- else if (currentHunk) {
59
- // Content lines
60
- if (line.startsWith('+') && !line.startsWith('+++')) {
61
- currentHunk.additions.push(line.substring(1));
62
- currentHunk.content += line + '\n';
63
- }
64
- else if (line.startsWith('-') && !line.startsWith('---')) {
65
- currentHunk.deletions.push(line.substring(1));
66
- currentHunk.content += line + '\n';
67
- }
68
- else if (line.startsWith(' ')) {
69
- currentHunk.content += line + '\n';
70
- }
71
- }
72
- }
73
- if (currentHunk) {
74
- hunks.push(currentHunk);
75
- }
76
- return hunks;
77
- }
78
- /**
79
- * Classify a change based on patterns
80
- */
81
- function classifyChange(diff, message = '') {
82
- const lowerMessage = message.toLowerCase();
83
- const lowerDiff = diff.toLowerCase();
84
- // Check message patterns
85
- if (/\b(fix|bug|issue|error|crash|patch)\b/.test(lowerMessage))
86
- return 'bugfix';
87
- if (/\b(feat|feature|add|new|implement)\b/.test(lowerMessage))
88
- return 'feature';
89
- if (/\b(refactor|clean|improve|optimize)\b/.test(lowerMessage))
90
- return 'refactor';
91
- if (/\b(doc|readme|comment|jsdoc)\b/.test(lowerMessage))
92
- return 'docs';
93
- if (/\b(test|spec|coverage)\b/.test(lowerMessage))
94
- return 'test';
95
- if (/\b(config|ci|cd|build|deps)\b/.test(lowerMessage))
96
- return 'config';
97
- // Check diff patterns
98
- if (/\.(md|txt|rst)$/.test(diff))
99
- return 'docs';
100
- if (/\.(test|spec)\.[jt]sx?/.test(diff))
101
- return 'test';
102
- if (/\.(json|ya?ml|toml|ini)$/.test(diff))
103
- return 'config';
104
- // Check content patterns
105
- if (/\bcatch\b|\btry\b|\berror\b/.test(lowerDiff) && /\bfix\b/.test(lowerDiff))
106
- return 'bugfix';
107
- if (/\bfunction\b|\bclass\b|\bexport\b/.test(lowerDiff))
108
- return 'feature';
109
- return 'unknown';
110
- }
111
- /**
112
- * Calculate risk score for a diff
113
- */
114
- function calculateRiskScore(analysis) {
115
- let risk = 0;
116
- // Size risk
117
- const totalChanges = analysis.totalAdditions + analysis.totalDeletions;
118
- if (totalChanges > 500)
119
- risk += 0.3;
120
- else if (totalChanges > 200)
121
- risk += 0.2;
122
- else if (totalChanges > 50)
123
- risk += 0.1;
124
- // Complexity risk
125
- if (analysis.complexity > 20)
126
- risk += 0.2;
127
- else if (analysis.complexity > 10)
128
- risk += 0.1;
129
- // File type risk
130
- if (analysis.file.includes('auth') || analysis.file.includes('security'))
131
- risk += 0.2;
132
- if (analysis.file.includes('database') || analysis.file.includes('migration'))
133
- risk += 0.15;
134
- if (analysis.file.includes('api') || analysis.file.includes('endpoint'))
135
- risk += 0.1;
136
- // Pattern risk (deletions of error handling, etc.)
137
- for (const hunk of analysis.hunks) {
138
- for (const del of hunk.deletions) {
139
- if (/\bcatch\b|\berror\b|\bvalidat/.test(del))
140
- risk += 0.1;
141
- if (/\bif\b.*\bnull\b|\bundefined\b/.test(del))
142
- risk += 0.05;
143
- }
144
- }
145
- return Math.min(1, risk);
146
- }
147
- /**
148
- * Analyze a single file diff
149
- */
150
- async function analyzeFileDiff(file, diff, message = '') {
151
- const hunks = parseDiff(diff).filter(h => h.file === file || h.file === '');
152
- const totalAdditions = hunks.reduce((sum, h) => sum + h.additions.length, 0);
153
- const totalDeletions = hunks.reduce((sum, h) => sum + h.deletions.length, 0);
154
- // Calculate complexity (branch keywords in additions)
155
- let complexity = 0;
156
- for (const hunk of hunks) {
157
- for (const add of hunk.additions) {
158
- if (/\bif\b|\belse\b|\bfor\b|\bwhile\b|\bswitch\b|\bcatch\b|\?/.test(add)) {
159
- complexity++;
160
- }
161
- }
162
- }
163
- const category = classifyChange(diff, message);
164
- const analysis = {
165
- file,
166
- hunks,
167
- totalAdditions,
168
- totalDeletions,
169
- complexity,
170
- riskScore: 0,
171
- category,
172
- };
173
- analysis.riskScore = calculateRiskScore(analysis);
174
- // Generate embedding for the diff
175
- if ((0, onnx_embedder_1.isReady)()) {
176
- const diffText = hunks.map(h => h.content).join('\n');
177
- const result = await (0, onnx_embedder_1.embed)(`${category} change in ${file}: ${diffText.substring(0, 500)}`);
178
- analysis.embedding = result.embedding;
179
- }
180
- return analysis;
181
- }
182
- /**
183
- * Get diff for a commit
184
- */
185
- function getCommitDiff(commitHash = 'HEAD') {
186
- try {
187
- return (0, child_process_1.execSync)(`git show ${commitHash} --format="" 2>/dev/null`, {
188
- encoding: 'utf8',
189
- maxBuffer: 10 * 1024 * 1024,
190
- });
191
- }
192
- catch {
193
- return '';
194
- }
195
- }
196
- /**
197
- * Get diff for staged changes
198
- */
199
- function getStagedDiff() {
200
- try {
201
- return (0, child_process_1.execSync)('git diff --cached 2>/dev/null', {
202
- encoding: 'utf8',
203
- maxBuffer: 10 * 1024 * 1024,
204
- });
205
- }
206
- catch {
207
- return '';
208
- }
209
- }
210
- /**
211
- * Get diff for unstaged changes
212
- */
213
- function getUnstagedDiff() {
214
- try {
215
- return (0, child_process_1.execSync)('git diff 2>/dev/null', {
216
- encoding: 'utf8',
217
- maxBuffer: 10 * 1024 * 1024,
218
- });
219
- }
220
- catch {
221
- return '';
222
- }
223
- }
224
- /**
225
- * Analyze a commit
226
- */
227
- async function analyzeCommit(commitHash = 'HEAD') {
228
- const diff = getCommitDiff(commitHash);
229
- // Get commit metadata
230
- let message = '', author = '', date = '';
231
- try {
232
- const info = (0, child_process_1.execSync)(`git log -1 --format="%s|%an|%aI" ${commitHash} 2>/dev/null`, {
233
- encoding: 'utf8',
234
- }).trim();
235
- [message, author, date] = info.split('|');
236
- }
237
- catch { }
238
- // Parse hunks and group by file
239
- const hunks = parseDiff(diff);
240
- const fileHunks = new Map();
241
- for (const hunk of hunks) {
242
- if (!fileHunks.has(hunk.file)) {
243
- fileHunks.set(hunk.file, []);
244
- }
245
- fileHunks.get(hunk.file).push(hunk);
246
- }
247
- // Analyze each file
248
- const files = [];
249
- for (const [file, fileHunkList] of fileHunks) {
250
- const fileDiff = fileHunkList.map(h => h.content).join('\n');
251
- const analysis = await analyzeFileDiff(file, diff, message);
252
- files.push(analysis);
253
- }
254
- const totalAdditions = files.reduce((sum, f) => sum + f.totalAdditions, 0);
255
- const totalDeletions = files.reduce((sum, f) => sum + f.totalDeletions, 0);
256
- const riskScore = files.length > 0
257
- ? files.reduce((sum, f) => sum + f.riskScore, 0) / files.length
258
- : 0;
259
- // Generate commit embedding
260
- let embedding;
261
- if ((0, onnx_embedder_1.isReady)()) {
262
- const commitText = `${message}\n\nFiles changed: ${files.map(f => f.file).join(', ')}\n+${totalAdditions} -${totalDeletions}`;
263
- const result = await (0, onnx_embedder_1.embed)(commitText);
264
- embedding = result.embedding;
265
- }
266
- return {
267
- hash: commitHash,
268
- message,
269
- author,
270
- date,
271
- files,
272
- totalAdditions,
273
- totalDeletions,
274
- riskScore,
275
- embedding,
276
- };
277
- }
278
- /**
279
- * Find similar past commits based on diff embeddings
280
- */
281
- async function findSimilarCommits(currentDiff, recentCommits = 50, topK = 5) {
282
- if (!(0, onnx_embedder_1.isReady)()) {
283
- await (0, onnx_embedder_1.initOnnxEmbedder)();
284
- }
285
- // Get current diff embedding
286
- const currentEmbedding = (await (0, onnx_embedder_1.embed)(currentDiff.substring(0, 1000))).embedding;
287
- // Get recent commits
288
- let commits = [];
289
- try {
290
- commits = (0, child_process_1.execSync)(`git log -${recentCommits} --format="%H" 2>/dev/null`, {
291
- encoding: 'utf8',
292
- }).trim().split('\n');
293
- }
294
- catch {
295
- return [];
296
- }
297
- // Analyze and compare
298
- const results = [];
299
- for (const hash of commits.slice(0, Math.min(commits.length, recentCommits))) {
300
- const analysis = await analyzeCommit(hash);
301
- if (analysis.embedding) {
302
- const similarity = cosineSimilarity(currentEmbedding, analysis.embedding);
303
- results.push({ hash, similarity, message: analysis.message });
304
- }
305
- }
306
- return results
307
- .sort((a, b) => b.similarity - a.similarity)
308
- .slice(0, topK);
309
- }
310
- function cosineSimilarity(a, b) {
311
- if (a.length !== b.length)
312
- return 0;
313
- let dotProduct = 0;
314
- let normA = 0;
315
- let normB = 0;
316
- for (let i = 0; i < a.length; i++) {
317
- dotProduct += a[i] * b[i];
318
- normA += a[i] * a[i];
319
- normB += b[i] * b[i];
320
- }
321
- const magnitude = Math.sqrt(normA) * Math.sqrt(normB);
322
- return magnitude === 0 ? 0 : dotProduct / magnitude;
323
- }
324
- exports.default = {
325
- parseDiff,
326
- classifyChange,
327
- calculateRiskScore,
328
- analyzeFileDiff,
329
- analyzeCommit,
330
- getCommitDiff,
331
- getStagedDiff,
332
- getUnstagedDiff,
333
- findSimilarCommits,
334
- };
@@ -1,143 +0,0 @@
1
- /**
2
- * GNN Wrapper - Safe wrapper around @ruvector/gnn with automatic array conversion
3
- *
4
- * This wrapper handles the array type conversion automatically, allowing users
5
- * to pass either regular arrays or Float32Arrays.
6
- *
7
- * The native @ruvector/gnn requires Float32Array for maximum performance.
8
- * This wrapper converts any input type to Float32Array automatically.
9
- *
10
- * Performance Tips:
11
- * - Pass Float32Array directly for zero-copy performance
12
- * - Use toFloat32Array/toFloat32ArrayBatch for pre-conversion
13
- * - Avoid repeated conversions in hot paths
14
- */
15
- /**
16
- * Convert any array-like input to Float32Array (native requires Float32Array)
17
- * Optimized paths:
18
- * - Float32Array: zero-copy return
19
- * - Float64Array: efficient typed array copy
20
- * - Array: direct Float32Array construction
21
- */
22
- export declare function toFloat32Array(input: number[] | Float32Array | Float64Array): Float32Array;
23
- /**
24
- * Convert array of arrays to array of Float32Arrays
25
- */
26
- export declare function toFloat32ArrayBatch(input: (number[] | Float32Array | Float64Array)[]): Float32Array[];
27
- /**
28
- * Search result from differentiable search
29
- */
30
- export interface DifferentiableSearchResult {
31
- /** Indices of top-k candidates */
32
- indices: number[];
33
- /** Soft weights for top-k candidates */
34
- weights: number[];
35
- }
36
- /**
37
- * Differentiable search using soft attention mechanism
38
- *
39
- * This wrapper automatically converts Float32Array inputs to regular arrays.
40
- *
41
- * @param query - Query vector (array or Float32Array)
42
- * @param candidates - List of candidate vectors (arrays or Float32Arrays)
43
- * @param k - Number of top results to return
44
- * @param temperature - Temperature for softmax (lower = sharper, higher = smoother)
45
- * @returns Search result with indices and soft weights
46
- *
47
- * @example
48
- * ```typescript
49
- * import { differentiableSearch } from 'ruvector/core/gnn-wrapper';
50
- *
51
- * // Works with regular arrays (auto-converted to Float32Array)
52
- * const result1 = differentiableSearch([1, 0, 0], [[1, 0, 0], [0, 1, 0]], 2, 1.0);
53
- *
54
- * // For best performance, use Float32Array directly (zero-copy)
55
- * const query = new Float32Array([1, 0, 0]);
56
- * const candidates = [new Float32Array([1, 0, 0]), new Float32Array([0, 1, 0])];
57
- * const result2 = differentiableSearch(query, candidates, 2, 1.0);
58
- * ```
59
- */
60
- export declare function differentiableSearch(query: number[] | Float32Array | Float64Array, candidates: (number[] | Float32Array | Float64Array)[], k: number, temperature?: number): DifferentiableSearchResult;
61
- /**
62
- * GNN Layer for HNSW topology
63
- */
64
- export declare class RuvectorLayer {
65
- private inner;
66
- /**
67
- * Create a new Ruvector GNN layer
68
- *
69
- * @param inputDim - Dimension of input node embeddings
70
- * @param hiddenDim - Dimension of hidden representations
71
- * @param heads - Number of attention heads
72
- * @param dropout - Dropout rate (0.0 to 1.0)
73
- */
74
- constructor(inputDim: number, hiddenDim: number, heads: number, dropout?: number);
75
- /**
76
- * Forward pass through the GNN layer
77
- *
78
- * @param nodeEmbedding - Current node's embedding
79
- * @param neighborEmbeddings - Embeddings of neighbor nodes
80
- * @param edgeWeights - Weights of edges to neighbors
81
- * @returns Updated node embedding as Float32Array
82
- */
83
- forward(nodeEmbedding: number[] | Float32Array, neighborEmbeddings: (number[] | Float32Array)[], edgeWeights: number[] | Float32Array): Float32Array;
84
- /**
85
- * Serialize the layer to JSON
86
- */
87
- toJson(): string;
88
- /**
89
- * Deserialize the layer from JSON
90
- */
91
- static fromJson(json: string): RuvectorLayer;
92
- }
93
- /**
94
- * Tensor compressor with adaptive level selection
95
- */
96
- export declare class TensorCompress {
97
- private inner;
98
- constructor();
99
- /**
100
- * Compress an embedding based on access frequency
101
- *
102
- * @param embedding - Input embedding vector
103
- * @param accessFreq - Access frequency (0.0 to 1.0)
104
- * @returns Compressed tensor as JSON string
105
- */
106
- compress(embedding: number[] | Float32Array, accessFreq: number): string;
107
- /**
108
- * Decompress a compressed tensor
109
- *
110
- * @param compressedJson - Compressed tensor JSON
111
- * @returns Decompressed embedding
112
- */
113
- decompress(compressedJson: string): number[];
114
- }
115
- /**
116
- * Hierarchical forward pass through GNN layers
117
- *
118
- * @param query - Query vector
119
- * @param layerEmbeddings - Embeddings organized by layer
120
- * @param gnnLayersJson - JSON array of serialized GNN layers
121
- * @returns Final embedding after hierarchical processing as Float32Array
122
- */
123
- export declare function hierarchicalForward(query: number[] | Float32Array, layerEmbeddings: (number[] | Float32Array)[][], gnnLayersJson: string[]): Float32Array;
124
- /**
125
- * Get compression level for a given access frequency
126
- */
127
- export declare function getCompressionLevel(accessFreq: number): string;
128
- /**
129
- * Check if GNN module is available
130
- */
131
- export declare function isGnnAvailable(): boolean;
132
- declare const _default: {
133
- differentiableSearch: typeof differentiableSearch;
134
- RuvectorLayer: typeof RuvectorLayer;
135
- TensorCompress: typeof TensorCompress;
136
- hierarchicalForward: typeof hierarchicalForward;
137
- getCompressionLevel: typeof getCompressionLevel;
138
- isGnnAvailable: typeof isGnnAvailable;
139
- toFloat32Array: typeof toFloat32Array;
140
- toFloat32ArrayBatch: typeof toFloat32ArrayBatch;
141
- };
142
- export default _default;
143
- //# sourceMappingURL=gnn-wrapper.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gnn-wrapper.d.ts","sourceRoot":"","sources":["../../src/core/gnn-wrapper.ts"],"names":[],"mappings":"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