MCPcopy Create free account
hub / github.com/cactus-compute/cactus / test_embeddings

Function test_embeddings

tests/test_embed.cpp:11–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9static const char* g_assets_path = std::getenv("CACTUS_TEST_ASSETS");
10
11bool test_embeddings() {
12 std::cout << "\n╔══════════════════════════════════════════╗\n"
13 << "║ EMBEDDINGS TEST ║\n"
14 << "╚══════════════════════════════════════════╝\n";
15
16 cactus_model_t model = cactus_init(g_model_path, nullptr, false);
17 if (!model) return false;
18
19 const char* texts[] = {"My name is Henry Ndubuaku", "Your name is Henry Ndubuaku"};
20 std::vector<float> emb1(2048), emb2(2048);
21 size_t dim1, dim2;
22
23 Timer t1;
24 cactus_embed(model, texts[0], emb1.data(), emb1.size() * sizeof(float), &dim1, true);
25 double time1 = t1.elapsed_ms();
26
27 Timer t2;
28 cactus_embed(model, texts[1], emb2.data(), emb2.size() * sizeof(float), &dim2, true);
29 double time2 = t2.elapsed_ms();
30
31 float similarity = 0;
32 for (size_t i = 0; i < dim1; ++i) {
33 similarity += emb1[i] * emb2[i];
34 }
35
36 std::cout << "\n[Results]\n"
37 << "├─ Embedding dim: " << dim1 << "\n"
38 << "├─ Time (text1): " << std::fixed << std::setprecision(2) << time1 << "ms\n"
39 << "├─ Time (text2): " << time2 << "ms\n"
40 << "└─ Similarity: " << std::setprecision(4) << similarity << std::endl;
41
42 cactus_destroy(model);
43 return true;
44}
45
46static bool test_image_embeddings() {
47 std::cout << "\n╔══════════════════════════════════════════╗\n"

Callers 1

mainFunction · 0.85

Calls 6

dataMethod · 0.80
sizeMethod · 0.80
elapsed_msMethod · 0.80
cactus_initFunction · 0.50
cactus_embedFunction · 0.50
cactus_destroyFunction · 0.50

Tested by

no test coverage detected