Ariadne 1.0

Ariadne is the model Memtrace uses to find code by what it does, not only by its name. It turns a piece of code, or a question about code, into a list of 768 numbers, so that code and questions about the same thing end up close together.

It is small: 70 MB and 17.5 million parameters. That makes it fast enough to run on any laptop without a graphics card, and much faster with one.

Named after Ariadne's thread, the one that leads through the labyrinth. Its sibling, Aletheia, finds the decisions in a conversation.

How it was made

Ariadne learned by copying a larger model, jina-embeddings-v2-base-code. We gave both models 5 million pieces of code and taught Ariadne to give the same answers as Jina.

The 5 million pieces are exactly what Memtrace embeds when it indexes a project: functions, classes and the text inside them. They come from about 400 popular open-source projects on GitHub, all under permissive licences (MIT, Apache 2.0, BSD and similar), in 32 languages: TypeScript, Python, Go, Rust, C++, Java, C#, JavaScript, C, Swift, Kotlin, Ruby, PHP, Dart, Elixir, Zig, COBOL, Lua, Perl, R, HCL, Vue, SCSS, CSS, HTML, PL/pgSQL, T-SQL, GDScript, Nextflow, ActionScript, Bicep and Gherkin. Training took about half an hour on one graphics card.

How good it is

All of these were measured on projects Ariadne never saw during training.

Test Ariadne 1.0 Jina v2 base code
Find the function from its docstring, top 10, Django 80.1% 89.7%
Find the function from its docstring, top 10, pytest 84.4% 91.6%
Memtrace search on 150 real pytest issues, top 10 (three ways of asking) 86.7 / 61.3 / 57.3% 87.3 / 59.3 / 57.3%
Memtrace search on 150 real Keycloak issues, top 10 (three ways of asking) 64.0 / 53.3 / 54.0% 62.7 / 52.0 / 54.0%

On its own, Ariadne is 7 to 10 points behind Jina. Inside Memtrace, which combines exact names, keyword search, the code graph and these vectors, the two scored the same. That second result says more about Memtrace than about the model: with vectors switched off entirely, Memtrace scored about the same on those issues too. Read it as "safe to use in Memtrace", not as "as good as Jina".

Across 15 languages, Ariadne keeps two thirds of the ten closest matches Jina would pick.

How fast it is

Measured on a desktop with an Intel Core Ultra 7 265KF and an NVIDIA RTX 5070, in batches of 32:

Where it runs Pieces of code per second
1 CPU thread about 145
8 CPU threads about 830
Graphics card (CUDA) about 13,000

In Memtrace, embedding all of Keycloak (about 450,000 pieces) took 4 minutes with Ariadne and 14 minutes with Jina at half precision, on the same graphics card.

Using it

In Memtrace it is the default from version 1.2.23. There is nothing to set up. To keep using Jina instead, set MEMTRACE_EMBED_MODEL=jina-code or pick it on the Settings page.

Anywhere else, with ONNX Runtime and the tokenizer in this repository:

import numpy as np
import onnxruntime as ort
from huggingface_hub import snapshot_download
from tokenizers import Tokenizer

path = snapshot_download("memtrace/ariadne-1.0")
tokenizer = Tokenizer.from_file(f"{path}/tokenizer.json")
tokenizer.enable_truncation(max_length=384)
tokenizer.enable_padding(pad_id=0, pad_token="<pad>")
session = ort.InferenceSession(f"{path}/onnx/model.onnx")

texts = ["def parse_date(value): ...", "where do we turn a string into a date?"]
encoded = tokenizer.encode_batch(texts)
ids = np.array([e.ids for e in encoded], dtype=np.int64)
mask = np.array([e.attention_mask for e in encoded], dtype=np.int64)
vectors = session.run(None, {"input_ids": ids, "attention_mask": mask})[0]
print(vectors @ vectors.T)  # the vectors are already normalised: this is cosine similarity

The model takes input_ids and attention_mask and returns sentence_embedding: one normalised 768-number vector per text. Questions need no prefix.

Limits

  • It reads at most 384 tokens at a time. Split longer code into pieces first; Memtrace does this for you.
  • It learned from Jina, so it shares Jina's blind spots and does not know anything Jina did not.
  • It learned from code and the English comments and strings inside it. Questions in other human languages will work less well.
  • The files of a version never change. A better model will get a new version name.

Architecture

A 2-layer transformer encoder, 256 wide with 4 attention heads, learned positions for 384 tokens, the tokenizer of jina-embeddings-v2-base-code, mean pooling over the tokens and a linear layer up to 768 numbers. config.json lists the details.

Licence

Apache 2.0. The tokenizer files come from jinaai/jina-embeddings-v2-base-code, also Apache 2.0, and the model was trained to reproduce that model's vectors.

Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support