Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 715857429
  • Loading branch information
niuchl authored and copybara-github committed Jan 15, 2025
1 parent 7f37c5b commit 992ec61
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ public void embed_succeedsWithBert() throws Exception {
assertThat(result0.embeddingResult().embeddings().get(0).floatEmbedding()).hasLength(512);
assertThat(result0.embeddingResult().embeddings().get(0).floatEmbedding()[0])
.isWithin(FLOAT_DIFF_TOLERANCE)
.of(20.59746f);
.of(21.214869f);
TextEmbedderResult result1 = textEmbedder.embed("what a great and fantastic trip");
assertThat(result1.embeddingResult().embeddings().size()).isEqualTo(1);
assertThat(result1.embeddingResult().embeddings().get(0).floatEmbedding()).hasLength(512);
assertThat(result1.embeddingResult().embeddings().get(0).floatEmbedding()[0])
.isWithin(FLOAT_DIFF_TOLERANCE)
.of(21.774776f);
.of(22.626257f);

// Check cosine similarity.
double similarity =
TextEmbedder.cosineSimilarity(
result0.embeddingResult().embeddings().get(0),
result1.embeddingResult().embeddings().get(0));
assertThat(similarity).isWithin(DOUBLE_DIFF_TOLERANCE).of(0.968879);
assertThat(similarity).isWithin(DOUBLE_DIFF_TOLERANCE).of(0.9714174924235968);
}

@Test
Expand Down Expand Up @@ -140,7 +140,7 @@ public void classify_succeedsWithBertAndDifferentThemes() throws Exception {
TextEmbedder.cosineSimilarity(
result0.embeddingResult().embeddings().get(0),
result1.embeddingResult().embeddings().get(0));
assertThat(similarity).isWithin(DOUBLE_DIFF_TOLERANCE).of(0.3565317439544432);
assertThat(similarity).isWithin(DOUBLE_DIFF_TOLERANCE).of(0.3549060071739994);
}

@Test
Expand Down

0 comments on commit 992ec61

Please sign in to comment.