georgeguimaraes

georgeguimaraes

Alike - Semantic similarity testing for Elixir

Alike :wavy_dash: - Semantic similarity testing for Elixir

Hey everyone! I’m excited to share Alike, a library for testing semantic similarity in Elixir.

The Problem

Testing LLM outputs, chatbots, or NLP pipelines is tricky. String matching is too brittle:

  # This fails even though the meaning is the same
  assert response == "Hi there! How can I help you?"
  # actual: "Hello! How may I assist you today?"

The Solution

Alike introduces the wave operator <~> for semantic similarity assertions:

  import Alike.WaveOperator

  # These pass - same meaning, different words
  assert "The cat is sleeping" <~> "A feline is taking a nap"
  assert "Hello! How can I help?" <~> "Hi there! What can I do for you?"

  # This fails - contradiction detected
  refute "The sky is blue" <~> "The sky is red"

The magic of ML in your test suite

What I find incredible about building this in Elixir is that we can run actual ML models inside our test suite, as naturally as any other code.

Thanks to Bumblebee and Nx, the models run as supervised Nx.Serving processes. They’re just GenServers! This means:

  • Parallel tests just work - With async: true, multiple test processes call the model concurrently, and Nx.Serving batches requests automatically
  • No external services - No Docker containers, no Python sidecars, no API calls. The models live in your BEAM instance
  • One model, many callers - Unlike Python where parallel test workers each need their own model copy (or a separate inference server), Elixir shares one model across all test processes efficiently

It’s the kind of thing that feels like it shouldn’t be this easy, but the BEAM + Nx ecosystem makes it natural.

How it works

Alike runs two models locally via Bumblebee + Nx:

  1. Sentence embeddings (all-MiniLM-L12-v2) for similarity
  2. NLI model (nli-distilroberta-base) for contradiction detection

No API keys needed - everything runs on your machine.

Installation

  def deps do
    [{:alike, "~> 0.2.0", only: :test}]
  end

Links

https://github.com/georgeguimaraes/alike

Would love to hear your feedback!

First Post!

spurgus

spurgus

That’s interesting! I have a test for image recognition where I ask the model, “What insect is this? One word only, downcased”, and I had to assert like this:

assert String.contains?(response.text, "ant") || String.contains?(response.text, "spider")

Maybe I can use Alike here :smiley:

Last Post!

georgeguimaraes

georgeguimaraes

That would be a cool use case. Let me know how it goes. The model used in Alike should be able to identify insect words

Where Next?

Popular in Announcing Top

Hal9000
Here is my first stab at this. README pasted below. https://github.com/Hal9000/elixir_random Comments and critiques are welcome. Thank...
New
wmnnd
Hi there, for my project DBLSQD, I needed a file storage solution that is a bit more flexible than Arc. Because I thought others might f...
New
devonestes
Introducing assertions, the library that helps you write really great test assertions! GitHub: GitHub - devonestes/assertions: Helpful a...
New
RobertDober
Earmark is a pure-Elixir Markdown converter. It is intended to be used as a library (just call Earmark.as_html), but can also be used as...
239 12888 134
New
kevinlang
Hey all, We have made an Ecto3 Adapter for SQLite3, ecto_sqlite3! We have successfully on-boarded the full suite of integration tests (...
New
nikokozak
Hello all, I’ve been working on Svonix - a library for quickly integrating Svelte components into Phoenix views. It’s a much-needed succ...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New

Other popular topics Top

openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42533 114
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement