pub fn differentiable_search(
query: Float32Array,
candidate_embeddings: Vec<Float32Array>,
k: u32,
temperature: f64,
) -> Result<SearchResult>Expand description
Differentiable search using soft attention mechanism
§Arguments
query- The query vector (Float32Array)candidate_embeddings- List of candidate embedding vectors (Array of Float32Array)k- Number of top results to returntemperature- Temperature for softmax (lower = sharper, higher = smoother)
§Returns
Search result with indices and soft weights
§Example
const query = new Float32Array([1.0, 0.0, 0.0]);
const candidates = [new Float32Array([1.0, 0.0, 0.0]), new Float32Array([0.9, 0.1, 0.0]), new Float32Array([0.0, 1.0, 0.0])];
const result = differentiableSearch(query, candidates, 2, 1.0);
console.log(result.indices); // [0, 1]
console.log(result.weights); // [0.x, 0.y]