MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / hash_embed

Function hash_embed

atomic-repository/src/repository/vault_embeddings.rs:297–310  ·  view source on GitHub ↗

Simple hash-based "embedding" for testing purposes. Produces a deterministic vector from text content using character frequency analysis. NOT suitable for production — use a real embedding model (MiniLM, OpenAI, etc.) instead.

(text: &str, dims: usize)

Source from the content-addressed store, hash-verified

295/// frequency analysis. NOT suitable for production — use a real
296/// embedding model (MiniLM, OpenAI, etc.) instead.
297pub fn hash_embed(text: &str, dims: usize) -> Vec<f32> {
298 let mut vec = vec![0.0f32; dims];
299 for (i, byte) in text.bytes().enumerate() {
300 vec[i % dims] += byte as f32 / 255.0;
301 }
302 // Normalize
303 let norm: f32 = vec.iter().map(|x| x * x).sum::<f32>().sqrt();
304 if norm > 0.0 {
305 for v in &mut vec {
306 *v /= norm;
307 }
308 }
309 vec
310}
311
312#[cfg(test)]
313mod tests {

Callers 10

runMethod · 0.85
execute_planFunction · 0.85
test_embedFunction · 0.85
vault_auto_indexMethod · 0.85
embedMethod · 0.85
embed_syncMethod · 0.85

Calls 1

iterMethod · 0.45

Tested by 5

test_embedFunction · 0.68