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

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 30486 241
New
devonestes
Introducing assertions, the library that helps you write really great test assertions! GitHub: GitHub - devonestes/assertions: Helpful a...
New
sasajuric
I’d like to announce a small library called boundaries. This is an experimental project which explores the idea of enforcing boundaries ...
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 12978 134
New
ityonemo
Currently just starting out on a new mini-project - getting zig NIFs to run in elixir. https://github.com/ityonemo/zigler The idea here...
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
brainlid
LangChain is short for Language Chain. An LLM, or Large Language Model, is the “Language” part. This library makes it easier for Elixir a...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement