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

Function hash_embed

atomic-repository/src/repository/vault_embeddings.rs:283–296  ·  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

281/// frequency analysis. NOT suitable for production — use a real
282/// embedding model (MiniLM, OpenAI, etc.) instead.
283pub fn hash_embed(text: &str, dims: usize) -> Vec<f32> {
284 let mut vec = vec![0.0f32; dims];
285 for (i, byte) in text.bytes().enumerate() {
286 vec[i % dims] += byte as f32 / 255.0;
287 }
288 // Normalize
289 let norm: f32 = vec.iter().map(|x| x * x).sum::<f32>().sqrt();
290 if norm > 0.0 {
291 for v in &mut vec {
292 *v /= norm;
293 }
294 }
295 vec
296}
297
298#[cfg(test)]
299mod 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