File size: 5,406 Bytes
40d7073
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
 * GNN Wrapper - Safe wrapper around @ruvector/gnn with automatic array conversion
 *
 * This wrapper handles the array type conversion automatically, allowing users
 * to pass either regular arrays or Float32Arrays.
 *
 * The native @ruvector/gnn requires Float32Array for maximum performance.
 * This wrapper converts any input type to Float32Array automatically.
 *
 * Performance Tips:
 * - Pass Float32Array directly for zero-copy performance
 * - Use toFloat32Array/toFloat32ArrayBatch for pre-conversion
 * - Avoid repeated conversions in hot paths
 */
/**
 * Convert any array-like input to Float32Array (native requires Float32Array)
 * Optimized paths:
 * - Float32Array: zero-copy return
 * - Float64Array: efficient typed array copy
 * - Array: direct Float32Array construction
 */
export declare function toFloat32Array(input: number[] | Float32Array | Float64Array): Float32Array;
/**
 * Convert array of arrays to array of Float32Arrays
 */
export declare function toFloat32ArrayBatch(input: (number[] | Float32Array | Float64Array)[]): Float32Array[];
/**
 * Search result from differentiable search
 */
export interface DifferentiableSearchResult {
    /** Indices of top-k candidates */
    indices: number[];
    /** Soft weights for top-k candidates */
    weights: number[];
}
/**
 * Differentiable search using soft attention mechanism
 *
 * This wrapper automatically converts Float32Array inputs to regular arrays.
 *
 * @param query - Query vector (array or Float32Array)
 * @param candidates - List of candidate vectors (arrays or Float32Arrays)
 * @param k - Number of top results to return
 * @param temperature - Temperature for softmax (lower = sharper, higher = smoother)
 * @returns Search result with indices and soft weights
 *
 * @example
 * ```typescript
 * import { differentiableSearch } from 'ruvector/core/gnn-wrapper';
 *
 * // Works with regular arrays (auto-converted to Float32Array)
 * const result1 = differentiableSearch([1, 0, 0], [[1, 0, 0], [0, 1, 0]], 2, 1.0);
 *
 * // For best performance, use Float32Array directly (zero-copy)
 * const query = new Float32Array([1, 0, 0]);
 * const candidates = [new Float32Array([1, 0, 0]), new Float32Array([0, 1, 0])];
 * const result2 = differentiableSearch(query, candidates, 2, 1.0);
 * ```
 */
export declare function differentiableSearch(query: number[] | Float32Array | Float64Array, candidates: (number[] | Float32Array | Float64Array)[], k: number, temperature?: number): DifferentiableSearchResult;
/**
 * GNN Layer for HNSW topology
 */
export declare class RuvectorLayer {
    private inner;
    /**
     * Create a new Ruvector GNN layer
     *
     * @param inputDim - Dimension of input node embeddings
     * @param hiddenDim - Dimension of hidden representations
     * @param heads - Number of attention heads
     * @param dropout - Dropout rate (0.0 to 1.0)
     */
    constructor(inputDim: number, hiddenDim: number, heads: number, dropout?: number);
    /**
     * Forward pass through the GNN layer
     *
     * @param nodeEmbedding - Current node's embedding
     * @param neighborEmbeddings - Embeddings of neighbor nodes
     * @param edgeWeights - Weights of edges to neighbors
     * @returns Updated node embedding as Float32Array
     */
    forward(nodeEmbedding: number[] | Float32Array, neighborEmbeddings: (number[] | Float32Array)[], edgeWeights: number[] | Float32Array): Float32Array;
    /**
     * Serialize the layer to JSON
     */
    toJson(): string;
    /**
     * Deserialize the layer from JSON
     */
    static fromJson(json: string): RuvectorLayer;
}
/**
 * Tensor compressor with adaptive level selection
 */
export declare class TensorCompress {
    private inner;
    constructor();
    /**
     * Compress an embedding based on access frequency
     *
     * @param embedding - Input embedding vector
     * @param accessFreq - Access frequency (0.0 to 1.0)
     * @returns Compressed tensor as JSON string
     */
    compress(embedding: number[] | Float32Array, accessFreq: number): string;
    /**
     * Decompress a compressed tensor
     *
     * @param compressedJson - Compressed tensor JSON
     * @returns Decompressed embedding
     */
    decompress(compressedJson: string): number[];
}
/**
 * Hierarchical forward pass through GNN layers
 *
 * @param query - Query vector
 * @param layerEmbeddings - Embeddings organized by layer
 * @param gnnLayersJson - JSON array of serialized GNN layers
 * @returns Final embedding after hierarchical processing as Float32Array
 */
export declare function hierarchicalForward(query: number[] | Float32Array, layerEmbeddings: (number[] | Float32Array)[][], gnnLayersJson: string[]): Float32Array;
/**
 * Get compression level for a given access frequency
 */
export declare function getCompressionLevel(accessFreq: number): string;
/**
 * Check if GNN module is available
 */
export declare function isGnnAvailable(): boolean;
declare const _default: {
    differentiableSearch: typeof differentiableSearch;
    RuvectorLayer: typeof RuvectorLayer;
    TensorCompress: typeof TensorCompress;
    hierarchicalForward: typeof hierarchicalForward;
    getCompressionLevel: typeof getCompressionLevel;
    isGnnAvailable: typeof isGnnAvailable;
    toFloat32Array: typeof toFloat32Array;
    toFloat32ArrayBatch: typeof toFloat32ArrayBatch;
};
export default _default;
//# sourceMappingURL=gnn-wrapper.d.ts.map