@Test public void testSimilarity() { assertEquals(0, new Embedding(0).similarity(new Embedding(1)), 0.0001); assertEquals(1, new Embedding(1).similarity(new Embedding(1)), 0.0001); assertEquals(0, new Embedding(0, 1).similarity(new Embedding(1, 0)), 0.0001); assertEquals(1, new Embedding(1, 1).similarity(new Embedding(1, 0)), 0.0001); assertEquals(0.5, new Embedding(0, 1).similarity(new Embedding(0.5, 0.5)), 0.0001); assertEquals(0.25, new Embedding(0, 0.5, 0.5) .similarity(new Embedding(0.5, 0.25, 0.25)), 0.0001); }
public double similarity(final Embedding other) { if (embedding.length != other.embedding.length) throw new IllegalArgumentException("Dimensions not matching"); double similarity = 0; for (int i = 0; i < embedding.length; ++i) similarity += embedding[i] * other.embedding[i]; return similarity; }
Embedding { public double similarity(final Embedding other) { if (embedding.length != other.embedding.length) throw new IllegalArgumentException("Dimensions not matching"); double similarity = 0; for (int i = 0; i < embedding.length; ++i) similarity += embedding[i] * other.embedding[i]; return similarity; } }
Embedding { public double similarity(final Embedding other) { if (embedding.length != other.embedding.length) throw new IllegalArgumentException("Dimensions not matching"); double similarity = 0; for (int i = 0; i < embedding.length; ++i) similarity += embedding[i] * other.embedding[i]; return similarity; } Embedding(final double... embedding);  Embedding(final String lineToParse); }
Embedding { public double similarity(final Embedding other) { if (embedding.length != other.embedding.length) throw new IllegalArgumentException("Dimensions not matching"); double similarity = 0; for (int i = 0; i < embedding.length; ++i) similarity += embedding[i] * other.embedding[i]; return similarity; } Embedding(final double... embedding);  Embedding(final String lineToParse); double similarity(final Embedding other); @Override String toString(); }
Embedding { public double similarity(final Embedding other) { if (embedding.length != other.embedding.length) throw new IllegalArgumentException("Dimensions not matching"); double similarity = 0; for (int i = 0; i < embedding.length; ++i) similarity += embedding[i] * other.embedding[i]; return similarity; } Embedding(final double... embedding);  Embedding(final String lineToParse); double similarity(final Embedding other); @Override String toString();  }