ruvector 0.2.23 → 0.2.25

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 (111) hide show
  1. package/bin/cli.js +211 -63
  2. package/dist/analysis/complexity.d.ts +52 -0
  3. package/dist/analysis/complexity.d.ts.map +1 -0
  4. package/dist/analysis/complexity.js +146 -0
  5. package/dist/analysis/index.d.ts +15 -0
  6. package/dist/analysis/index.d.ts.map +1 -0
  7. package/dist/analysis/index.js +38 -0
  8. package/dist/analysis/patterns.d.ts +71 -0
  9. package/dist/analysis/patterns.d.ts.map +1 -0
  10. package/dist/analysis/patterns.js +243 -0
  11. package/dist/analysis/security.d.ts +51 -0
  12. package/dist/analysis/security.d.ts.map +1 -0
  13. package/dist/analysis/security.js +139 -0
  14. package/dist/core/adaptive-embedder.d.ts +156 -0
  15. package/dist/core/adaptive-embedder.d.ts.map +1 -0
  16. package/dist/core/adaptive-embedder.js +838 -0
  17. package/dist/core/agentdb-fast.d.ts +149 -0
  18. package/dist/core/agentdb-fast.d.ts.map +1 -0
  19. package/dist/core/agentdb-fast.js +301 -0
  20. package/dist/core/ast-parser.d.ts +108 -0
  21. package/dist/core/ast-parser.d.ts.map +1 -0
  22. package/dist/core/ast-parser.js +602 -0
  23. package/dist/core/attention-fallbacks.d.ts +321 -0
  24. package/dist/core/attention-fallbacks.d.ts.map +1 -0
  25. package/dist/core/attention-fallbacks.js +552 -0
  26. package/dist/core/cluster-wrapper.d.ts +148 -0
  27. package/dist/core/cluster-wrapper.d.ts.map +1 -0
  28. package/dist/core/cluster-wrapper.js +271 -0
  29. package/dist/core/coverage-router.d.ts +88 -0
  30. package/dist/core/coverage-router.d.ts.map +1 -0
  31. package/dist/core/coverage-router.js +315 -0
  32. package/dist/core/diff-embeddings.d.ts +93 -0
  33. package/dist/core/diff-embeddings.d.ts.map +1 -0
  34. package/dist/core/diff-embeddings.js +334 -0
  35. package/dist/core/diskann-wrapper.d.ts +53 -0
  36. package/dist/core/diskann-wrapper.d.ts.map +1 -0
  37. package/dist/core/diskann-wrapper.js +105 -0
  38. package/dist/core/gnn-wrapper.d.ts +143 -0
  39. package/dist/core/gnn-wrapper.d.ts.map +1 -0
  40. package/dist/core/gnn-wrapper.js +213 -0
  41. package/dist/core/graph-algorithms.d.ts +83 -0
  42. package/dist/core/graph-algorithms.d.ts.map +1 -0
  43. package/dist/core/graph-algorithms.js +514 -0
  44. package/dist/core/graph-wrapper.d.ts +147 -0
  45. package/dist/core/graph-wrapper.d.ts.map +1 -0
  46. package/dist/core/graph-wrapper.js +299 -0
  47. package/dist/core/index.d.ts +50 -0
  48. package/dist/core/index.d.ts.map +1 -0
  49. package/dist/core/index.js +92 -0
  50. package/dist/core/intelligence-engine.d.ts +258 -0
  51. package/dist/core/intelligence-engine.d.ts.map +1 -0
  52. package/dist/core/intelligence-engine.js +1030 -0
  53. package/dist/core/learning-engine.d.ts +160 -0
  54. package/dist/core/learning-engine.d.ts.map +1 -0
  55. package/dist/core/learning-engine.js +589 -0
  56. package/dist/core/neural-embeddings.d.ts +393 -0
  57. package/dist/core/neural-embeddings.d.ts.map +1 -0
  58. package/dist/core/neural-embeddings.js +1091 -0
  59. package/dist/core/neural-perf.d.ts +331 -0
  60. package/dist/core/neural-perf.d.ts.map +1 -0
  61. package/dist/core/neural-perf.js +704 -0
  62. package/dist/core/onnx/pkg/package.json +3 -0
  63. package/dist/core/onnx-embedder.d.ts +105 -0
  64. package/dist/core/onnx-embedder.d.ts.map +1 -0
  65. package/dist/core/onnx-embedder.js +410 -0
  66. package/dist/core/onnx-optimized.d.ts +109 -0
  67. package/dist/core/onnx-optimized.d.ts.map +1 -0
  68. package/dist/core/onnx-optimized.js +419 -0
  69. package/dist/core/parallel-intelligence.d.ts +109 -0
  70. package/dist/core/parallel-intelligence.d.ts.map +1 -0
  71. package/dist/core/parallel-intelligence.js +340 -0
  72. package/dist/core/parallel-workers.d.ts +177 -0
  73. package/dist/core/parallel-workers.d.ts.map +1 -0
  74. package/dist/core/parallel-workers.js +783 -0
  75. package/dist/core/router-wrapper.d.ts +75 -0
  76. package/dist/core/router-wrapper.d.ts.map +1 -0
  77. package/dist/core/router-wrapper.js +243 -0
  78. package/dist/core/rvf-wrapper.d.ts +86 -0
  79. package/dist/core/rvf-wrapper.d.ts.map +1 -0
  80. package/dist/core/rvf-wrapper.js +102 -0
  81. package/dist/core/sona-wrapper.d.ts +226 -0
  82. package/dist/core/sona-wrapper.d.ts.map +1 -0
  83. package/dist/core/sona-wrapper.js +282 -0
  84. package/dist/core/tensor-compress.d.ts +134 -0
  85. package/dist/core/tensor-compress.d.ts.map +1 -0
  86. package/dist/core/tensor-compress.js +432 -0
  87. package/dist/index.d.ts +106 -0
  88. package/dist/index.d.ts.map +1 -0
  89. package/dist/index.js +258 -0
  90. package/dist/services/embedding-service.d.ts +136 -0
  91. package/dist/services/embedding-service.d.ts.map +1 -0
  92. package/dist/services/embedding-service.js +294 -0
  93. package/dist/services/index.d.ts +6 -0
  94. package/dist/services/index.d.ts.map +1 -0
  95. package/dist/services/index.js +26 -0
  96. package/dist/types.d.ts +145 -0
  97. package/dist/types.d.ts.map +1 -0
  98. package/dist/types.js +2 -0
  99. package/dist/workers/benchmark.d.ts +44 -0
  100. package/dist/workers/benchmark.d.ts.map +1 -0
  101. package/dist/workers/benchmark.js +230 -0
  102. package/dist/workers/index.d.ts +10 -0
  103. package/dist/workers/index.d.ts.map +1 -0
  104. package/dist/workers/index.js +25 -0
  105. package/dist/workers/native-worker.d.ts +76 -0
  106. package/dist/workers/native-worker.d.ts.map +1 -0
  107. package/dist/workers/native-worker.js +490 -0
  108. package/dist/workers/types.d.ts +69 -0
  109. package/dist/workers/types.d.ts.map +1 -0
  110. package/dist/workers/types.js +7 -0
  111. package/package.json +8 -7
@@ -0,0 +1,143 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gnn-wrapper.d.ts","sourceRoot":"","sources":["../../src/core/gnn-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAsBH;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,YAAY,GAAG,YAAY,GAAG,YAAY,CAK1F;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,GAAG,YAAY,GAAG,YAAY,CAAC,EAAE,GAAG,YAAY,EAAE,CAMrG;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,kCAAkC;IAClC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,wCAAwC;IACxC,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,EAA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;;;;;;;;;AAED,wBAUE"}
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ /**
3
+ * GNN Wrapper - Safe wrapper around @ruvector/gnn with automatic array conversion
4
+ *
5
+ * This wrapper handles the array type conversion automatically, allowing users
6
+ * to pass either regular arrays or Float32Arrays.
7
+ *
8
+ * The native @ruvector/gnn requires Float32Array for maximum performance.
9
+ * This wrapper converts any input type to Float32Array automatically.
10
+ *
11
+ * Performance Tips:
12
+ * - Pass Float32Array directly for zero-copy performance
13
+ * - Use toFloat32Array/toFloat32ArrayBatch for pre-conversion
14
+ * - Avoid repeated conversions in hot paths
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.TensorCompress = exports.RuvectorLayer = void 0;
18
+ exports.toFloat32Array = toFloat32Array;
19
+ exports.toFloat32ArrayBatch = toFloat32ArrayBatch;
20
+ exports.differentiableSearch = differentiableSearch;
21
+ exports.hierarchicalForward = hierarchicalForward;
22
+ exports.getCompressionLevel = getCompressionLevel;
23
+ exports.isGnnAvailable = isGnnAvailable;
24
+ // Lazy load to avoid import errors if not installed
25
+ let gnnModule = null;
26
+ let loadError = null;
27
+ function getGnnModule() {
28
+ if (gnnModule)
29
+ return gnnModule;
30
+ if (loadError)
31
+ throw loadError;
32
+ try {
33
+ gnnModule = require('@ruvector/gnn');
34
+ return gnnModule;
35
+ }
36
+ catch (e) {
37
+ loadError = new Error(`@ruvector/gnn is not installed or failed to load: ${e.message}\n` +
38
+ `Install with: npm install @ruvector/gnn`);
39
+ throw loadError;
40
+ }
41
+ }
42
+ /**
43
+ * Convert any array-like input to Float32Array (native requires Float32Array)
44
+ * Optimized paths:
45
+ * - Float32Array: zero-copy return
46
+ * - Float64Array: efficient typed array copy
47
+ * - Array: direct Float32Array construction
48
+ */
49
+ function toFloat32Array(input) {
50
+ if (input instanceof Float32Array)
51
+ return input;
52
+ if (input instanceof Float64Array)
53
+ return new Float32Array(input);
54
+ if (Array.isArray(input))
55
+ return new Float32Array(input);
56
+ return new Float32Array(Array.from(input));
57
+ }
58
+ /**
59
+ * Convert array of arrays to array of Float32Arrays
60
+ */
61
+ function toFloat32ArrayBatch(input) {
62
+ const result = new Array(input.length);
63
+ for (let i = 0; i < input.length; i++) {
64
+ result[i] = toFloat32Array(input[i]);
65
+ }
66
+ return result;
67
+ }
68
+ /**
69
+ * Differentiable search using soft attention mechanism
70
+ *
71
+ * This wrapper automatically converts Float32Array inputs to regular arrays.
72
+ *
73
+ * @param query - Query vector (array or Float32Array)
74
+ * @param candidates - List of candidate vectors (arrays or Float32Arrays)
75
+ * @param k - Number of top results to return
76
+ * @param temperature - Temperature for softmax (lower = sharper, higher = smoother)
77
+ * @returns Search result with indices and soft weights
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * import { differentiableSearch } from 'ruvector/core/gnn-wrapper';
82
+ *
83
+ * // Works with regular arrays (auto-converted to Float32Array)
84
+ * const result1 = differentiableSearch([1, 0, 0], [[1, 0, 0], [0, 1, 0]], 2, 1.0);
85
+ *
86
+ * // For best performance, use Float32Array directly (zero-copy)
87
+ * const query = new Float32Array([1, 0, 0]);
88
+ * const candidates = [new Float32Array([1, 0, 0]), new Float32Array([0, 1, 0])];
89
+ * const result2 = differentiableSearch(query, candidates, 2, 1.0);
90
+ * ```
91
+ */
92
+ function differentiableSearch(query, candidates, k, temperature = 1.0) {
93
+ const gnn = getGnnModule();
94
+ // Convert to Float32Array (native Rust expects Float32Array for performance)
95
+ const queryFloat32 = toFloat32Array(query);
96
+ const candidatesFloat32 = toFloat32ArrayBatch(candidates);
97
+ return gnn.differentiableSearch(queryFloat32, candidatesFloat32, k, temperature);
98
+ }
99
+ /**
100
+ * GNN Layer for HNSW topology
101
+ */
102
+ class RuvectorLayer {
103
+ /**
104
+ * Create a new Ruvector GNN layer
105
+ *
106
+ * @param inputDim - Dimension of input node embeddings
107
+ * @param hiddenDim - Dimension of hidden representations
108
+ * @param heads - Number of attention heads
109
+ * @param dropout - Dropout rate (0.0 to 1.0)
110
+ */
111
+ constructor(inputDim, hiddenDim, heads, dropout = 0.1) {
112
+ const gnn = getGnnModule();
113
+ this.inner = new gnn.RuvectorLayer(inputDim, hiddenDim, heads, dropout);
114
+ }
115
+ /**
116
+ * Forward pass through the GNN layer
117
+ *
118
+ * @param nodeEmbedding - Current node's embedding
119
+ * @param neighborEmbeddings - Embeddings of neighbor nodes
120
+ * @param edgeWeights - Weights of edges to neighbors
121
+ * @returns Updated node embedding as Float32Array
122
+ */
123
+ forward(nodeEmbedding, neighborEmbeddings, edgeWeights) {
124
+ return this.inner.forward(toFloat32Array(nodeEmbedding), toFloat32ArrayBatch(neighborEmbeddings), toFloat32Array(edgeWeights));
125
+ }
126
+ /**
127
+ * Serialize the layer to JSON
128
+ */
129
+ toJson() {
130
+ return this.inner.toJson();
131
+ }
132
+ /**
133
+ * Deserialize the layer from JSON
134
+ */
135
+ static fromJson(json) {
136
+ const gnn = getGnnModule();
137
+ const layer = new RuvectorLayer(1, 1, 1, 0); // Dummy constructor
138
+ layer.inner = gnn.RuvectorLayer.fromJson(json);
139
+ return layer;
140
+ }
141
+ }
142
+ exports.RuvectorLayer = RuvectorLayer;
143
+ /**
144
+ * Tensor compressor with adaptive level selection
145
+ */
146
+ class TensorCompress {
147
+ constructor() {
148
+ const gnn = getGnnModule();
149
+ this.inner = new gnn.TensorCompress();
150
+ }
151
+ /**
152
+ * Compress an embedding based on access frequency
153
+ *
154
+ * @param embedding - Input embedding vector
155
+ * @param accessFreq - Access frequency (0.0 to 1.0)
156
+ * @returns Compressed tensor as JSON string
157
+ */
158
+ compress(embedding, accessFreq) {
159
+ return this.inner.compress(toFloat32Array(embedding), accessFreq);
160
+ }
161
+ /**
162
+ * Decompress a compressed tensor
163
+ *
164
+ * @param compressedJson - Compressed tensor JSON
165
+ * @returns Decompressed embedding
166
+ */
167
+ decompress(compressedJson) {
168
+ return this.inner.decompress(compressedJson);
169
+ }
170
+ }
171
+ exports.TensorCompress = TensorCompress;
172
+ /**
173
+ * Hierarchical forward pass through GNN layers
174
+ *
175
+ * @param query - Query vector
176
+ * @param layerEmbeddings - Embeddings organized by layer
177
+ * @param gnnLayersJson - JSON array of serialized GNN layers
178
+ * @returns Final embedding after hierarchical processing as Float32Array
179
+ */
180
+ function hierarchicalForward(query, layerEmbeddings, gnnLayersJson) {
181
+ const gnn = getGnnModule();
182
+ return gnn.hierarchicalForward(toFloat32Array(query), layerEmbeddings.map(layer => toFloat32ArrayBatch(layer)), gnnLayersJson);
183
+ }
184
+ /**
185
+ * Get compression level for a given access frequency
186
+ */
187
+ function getCompressionLevel(accessFreq) {
188
+ const gnn = getGnnModule();
189
+ return gnn.getCompressionLevel(accessFreq);
190
+ }
191
+ /**
192
+ * Check if GNN module is available
193
+ */
194
+ function isGnnAvailable() {
195
+ try {
196
+ getGnnModule();
197
+ return true;
198
+ }
199
+ catch {
200
+ return false;
201
+ }
202
+ }
203
+ exports.default = {
204
+ differentiableSearch,
205
+ RuvectorLayer,
206
+ TensorCompress,
207
+ hierarchicalForward,
208
+ getCompressionLevel,
209
+ isGnnAvailable,
210
+ // Export conversion helpers for performance optimization
211
+ toFloat32Array,
212
+ toFloat32ArrayBatch,
213
+ };
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Graph Algorithms - MinCut, Spectral Clustering, Community Detection
3
+ *
4
+ * Provides graph partitioning and clustering algorithms for:
5
+ * - Code module detection
6
+ * - Dependency clustering
7
+ * - Architecture analysis
8
+ * - Refactoring suggestions
9
+ */
10
+ export interface Graph {
11
+ nodes: string[];
12
+ edges: Array<{
13
+ from: string;
14
+ to: string;
15
+ weight?: number;
16
+ }>;
17
+ adjacency: Map<string, Map<string, number>>;
18
+ }
19
+ export interface Partition {
20
+ groups: string[][];
21
+ cutWeight: number;
22
+ modularity: number;
23
+ }
24
+ export interface SpectralResult {
25
+ clusters: Map<string, number>;
26
+ eigenvalues: number[];
27
+ coordinates: Map<string, number[]>;
28
+ }
29
+ /**
30
+ * Build adjacency representation from edges
31
+ */
32
+ export declare function buildGraph(nodes: string[], edges: Array<{
33
+ from: string;
34
+ to: string;
35
+ weight?: number;
36
+ }>): Graph;
37
+ /**
38
+ * Minimum Cut (Stoer-Wagner algorithm)
39
+ *
40
+ * Finds the minimum weight cut that partitions the graph into two parts.
41
+ * Useful for finding loosely coupled module boundaries.
42
+ */
43
+ export declare function minCut(graph: Graph): Partition;
44
+ /**
45
+ * Spectral Clustering (using power iteration)
46
+ *
47
+ * Uses graph Laplacian eigenvectors for clustering.
48
+ * Good for finding natural clusters in code dependencies.
49
+ */
50
+ export declare function spectralClustering(graph: Graph, k?: number): SpectralResult;
51
+ /**
52
+ * Louvain Community Detection
53
+ *
54
+ * Greedy modularity optimization for finding communities.
55
+ * Good for detecting natural module boundaries.
56
+ */
57
+ export declare function louvainCommunities(graph: Graph): Map<string, number>;
58
+ /**
59
+ * Calculate modularity of a partition
60
+ */
61
+ export declare function calculateModularity(graph: Graph, partition: string[][]): number;
62
+ /**
63
+ * Find bridges (edges whose removal disconnects components)
64
+ */
65
+ export declare function findBridges(graph: Graph): Array<{
66
+ from: string;
67
+ to: string;
68
+ }>;
69
+ /**
70
+ * Find articulation points (nodes whose removal disconnects components)
71
+ */
72
+ export declare function findArticulationPoints(graph: Graph): string[];
73
+ declare const _default: {
74
+ buildGraph: typeof buildGraph;
75
+ minCut: typeof minCut;
76
+ spectralClustering: typeof spectralClustering;
77
+ louvainCommunities: typeof louvainCommunities;
78
+ calculateModularity: typeof calculateModularity;
79
+ findBridges: typeof findBridges;
80
+ findArticulationPoints: typeof findArticulationPoints;
81
+ };
82
+ export default _default;
83
+ //# sourceMappingURL=graph-algorithms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-algorithms.d.ts","sourceRoot":"","sources":["../../src/core/graph-algorithms.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,WAAW,KAAK;IACpB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;QAAE,IA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