Skip to content

Instantly share code, notes, and snippets.

@Kerollmops
Created June 12, 2025 10:16
Show Gist options
  • Save Kerollmops/d2d12ac1898360484638d2b8f2730bb8 to your computer and use it in GitHub Desktop.
Save Kerollmops/d2d12ac1898360484638d2b8f2730bb8 to your computer and use it in GitHub Desktop.
A simple example to group documents to embedded, increase the group size to reduce the size of the groups
// This is set by the engine for every invocation of this function.
let context = #{ group_size: 3, group_id: 1 };
// The _vectors field doesn't even exists.
let doc = #{ id: "abc1234", metadata: #{ title: "super title" } };
print(doc);
// ---- start -----
fn hash(s) {
s.to_chars().reduce(|sum| sum + this.to_int(), 0)
}
if hash(doc.id) % context.group_size == context.group_id {
// Force embeddings regeneration
doc._vectors = #{ openai: #{ regenerate: true } };
// Change the template output and trigger the embedder
doc.metadata.title = " " + doc.metadata.title;
}
// ----- end ------
print(doc);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment