forked from mistralai/mistral-inference
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEmbeddings _ Mistral AI Large Language Models.html
76 lines (74 loc) · 183 KB
/
Embeddings _ Mistral AI Large Language Models.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<!-- saved from url=(0048)https://docs.mistral.ai/capabilities/embeddings/ -->
<html lang="en" dir="ltr" class="docs-wrapper plugin-docs plugin-id-default docs-version-current docs-doc-page docs-doc-id-capabilities/embeddings" data-has-hydrated="true" data-google-analytics-opt-out="" data-bybit-channel-name="DM9imwGZgT5ugUyEqwL-f" data-bybit-is-default-wallet="true" data-theme="dark" data-rh="lang,dir,class,data-has-hydrated"><div id="in-page-channel-node-id" data-channel-name="in_page_channel_RxGQkH"></div><script async="false" src="chrome-extension://cpmkedoipcpimgecpmgpldfpohjplkpp/window-provider.js"></script><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="Docusaurus v3.2.1">
<title>Embeddings | Mistral AI Large Language Models</title><meta data-rh="true" name="twitter:card" content="summary_large_image"><meta data-rh="true" property="og:image" content="https://docs.mistral.ai/img/mistral-social-banner.jpg"><meta data-rh="true" name="twitter:image" content="https://docs.mistral.ai/img/mistral-social-banner.jpg"><link data-rh="true" rel="icon" href="https://docs.mistral.ai/img/favicon.ico"><link rel="stylesheet" href="./Embeddings _ Mistral AI Large Language Models_files/styles.5760d859.css">
<script src="./Embeddings _ Mistral AI Large Language Models_files/runtime~main.77a48988.js.download" defer="defer"></script>
<script src="./Embeddings _ Mistral AI Large Language Models_files/main.0b370f62.js.download" defer="defer"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0" data-rh="true"><meta property="og:locale" content="en" data-rh="true"><meta name="docusaurus_locale" content="en" data-rh="true"><meta name="docsearch:language" content="en" data-rh="true"><meta name="docusaurus_version" content="current" data-rh="true"><meta name="docusaurus_tag" content="docs-default-current" data-rh="true"><meta name="docsearch:version" content="current" data-rh="true"><meta name="docsearch:docusaurus_tag" content="docs-default-current" data-rh="true"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a811ed6a.32154ebd.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/02cb9835.2cd530c2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/7ccb0d94.d8b3d864.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/99938c86.a7f99cbb.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/045b7d00.268e7a7d.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/e015390e.98ed70ba.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/3f130913.0e0f4a08.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/f4834277.97d3d249.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/35155c61.3db4251e.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/f0ad3fbb.5feefe83.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/3c469c15.bb053fda.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/b3ecb6b5.ba27041d.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/f327c38b.f599bea6.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/7c146eec.d61c7e13.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/1ae8728a.f7d8de3a.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/00498170.241ece43.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/2ddf178c.cad62e22.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/c1e31d33.be447d0d.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/ef65460b.3a312f0f.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/d18bf588.f58ff7f7.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/e921f177.0d1ec9d9.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/47a2a88f.30dfc23f.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/5e95c892.2d7483fa.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/87c49e91.b3570ff1.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a7bd4aaa.690b4ba5.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/935f2afb.7c098d79.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/a94703ab.2132f644.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/54481e7f.7d2be6e2.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/17896441.fdb7390c.js"><link rel="prefetch" href="https://docs.mistral.ai/assets/js/306f7620.a35c7954.js"><link rel="canonical" href="https://docs.mistral.ai/capabilities/embeddings/" data-rh="true"><link rel="alternate" href="https://docs.mistral.ai/capabilities/embeddings/" hreflang="en" data-rh="true"><link rel="alternate" href="https://docs.mistral.ai/capabilities/embeddings/" hreflang="x-default" data-rh="true"><meta property="og:url" content="https://docs.mistral.ai/capabilities/embeddings/" data-rh="true"><meta property="og:title" content="Embeddings | Mistral AI Large Language Models" data-rh="true"><meta name="description" content="Embeddings are vectorial representations of text that capture the semantic meaning of paragraphs through their position in a high dimensional vector space. Mistral AI Embeddings API offers cutting-edge, state-of-the-art embeddings for text, which can be used for many NLP tasks. In this guide, we will cover the fundamentals of the embeddings API, including how to measure the distance between text embeddings, and explore its main use cases: clustering and classification." data-rh="true"><meta property="og:description" content="Embeddings are vectorial representations of text that capture the semantic meaning of paragraphs through their position in a high dimensional vector space. Mistral AI Embeddings API offers cutting-edge, state-of-the-art embeddings for text, which can be used for many NLP tasks. In this guide, we will cover the fundamentals of the embeddings API, including how to measure the distance between text embeddings, and explore its main use cases: clustering and classification." data-rh="true"></head>
<body class="" data-rh="class" style="overflow: visible;">
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){try{return new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}}()||function(){try{return localStorage.getItem("theme")}catch(t){}}();null!==e?t(e):window.matchMedia("(prefers-color-scheme: dark)").matches?t("dark"):(window.matchMedia("(prefers-color-scheme: light)").matches,t("light"))}(),function(){try{const c=new URLSearchParams(window.location.search).entries();for(var[t,e]of c)if(t.startsWith("docusaurus-data-")){var a=t.replace("docusaurus-data-","data-");document.documentElement.setAttribute(a,e)}}catch(t){}}()</script><div id="__docusaurus"><div role="region" aria-label="Skip to main content"><a class="skipToContent_yC05" href="https://docs.mistral.ai/capabilities/embeddings/#__docusaurus_skipToContent_fallback">Skip to main content</a></div><nav aria-label="Main" class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Toggle navigation bar" aria-expanded="false" class="navbar__toggle clean-btn" type="button"><svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a href="https://mistral.ai/" target="_self" rel="noopener noreferrer" class="navbar__brand"><div class="navbar__logo"><img src="./Embeddings _ Mistral AI Large Language Models_files/logo-dark.svg" alt="Mistral AI Logo" class="themedComponent_hPDO themedComponent--dark_l222"></div></a><a href="https://chat.mistral.ai/" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Le Chat</a><a href="https://console.mistral.ai/" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">La Plateforme</a><a aria-current="page" class="navbar__item navbar__link navbar__link--active" href="https://docs.mistral.ai/">Docs</a><a class="navbar__item navbar__link" href="https://docs.mistral.ai/api/">API</a></div><div class="navbar__items navbar__items--right"><a href="https://github.com/mistralai/" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">GitHub<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_yPTG"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a><a href="https://discord.gg/mistralai" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Discord<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_yPTG"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a><div class="toggle_NB6N colorModeToggle_q4rJ"><button class="clean-btn toggleButton_pYLp" type="button" title="Switch between dark and light mode (currently light mode)" aria-label="Switch between dark and light mode (currently light mode)" aria-live="polite"><svg viewBox="0 0 24 24" width="24" height="24" class="lightToggleIcon_mVu4"><path fill="currentColor" d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z"></path></svg><svg viewBox="0 0 24 24" width="24" height="24" class="darkToggleIcon_zXrM"><path fill="currentColor" d="M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"></path></svg></button></div><div class="navbarSearchContainer_cqyf"><div class="navbar__search"><span aria-label="expand searchbar" role="button" class="search-icon" tabindex="0"></span><span class="algolia-autocomplete" style="position: relative; display: inline-block; direction: ltr;"><input id="search_input_react" type="search" placeholder="Search Ctrl+K" aria-label="Search" class="navbar__search-input search-bar ds-input" autocomplete="off" spellcheck="false" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-owns="algolia-autocomplete-listbox-0" dir="auto" style="position: relative; vertical-align: top;"><pre aria-hidden="true" style="position: absolute; visibility: hidden; white-space: pre; font-family: Arial; font-size: 12.96px; font-style: normal; font-variant: normal; font-weight: 400; word-spacing: 0px; letter-spacing: normal; text-indent: 0px; text-rendering: auto; text-transform: none;"></pre><span class="ds-dropdown-menu" role="listbox" id="algolia-autocomplete-listbox-0" style="position: absolute; top: 100%; z-index: 100; display: none; left: 0px; right: auto;"><div class="ds-dataset-1"></div></span></span></div></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div></nav><div id="__docusaurus_skipToContent_fallback" class="main-wrapper mainWrapper_pZGw"><div class="docsWrapper_J1wO"><button aria-label="Scroll back to top" class="clean-btn theme-back-to-top-button backToTopButton_nC4L" type="button"></button><div class="docRoot_D4cR"><aside class="theme-doc-sidebar-container docSidebarContainer_Z9Rq"><div class="sidebarViewport__dLE"><div class="sidebar_ava_"><nav aria-label="Docs sidebar" class="menu thin-scrollbar menu_fHBh"><ul class="theme-doc-sidebar-menu menu__list"><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu-label">Getting Started</li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="https://docs.mistral.ai/">Introduction</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="https://docs.mistral.ai/getting-started/quickstart/">Quickstart</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="https://docs.mistral.ai/getting-started/models/">Models</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="https://docs.mistral.ai/getting-started/open_weight_models/">Open-weight models</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="https://docs.mistral.ai/getting-started/clients/">Clients</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="https://docs.mistral.ai/getting-started/changelog/">Changelog</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="https://docs.mistral.ai/getting-started/glossary/">Glossary</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu-label margin-top--md">Capabilities</li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="https://docs.mistral.ai/capabilities/completion/">Text generation</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link menu__link--active" href="https://docs.mistral.ai/capabilities/embeddings/" aria-current="page">Embeddings</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="https://docs.mistral.ai/capabilities/function_calling/">Function calling</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="https://docs.mistral.ai/capabilities/json_mode/">JSON mode</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="https://docs.mistral.ai/capabilities/guardrailing/">Guardrailing</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu-label margin-top--md">Deployment</li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="https://docs.mistral.ai/deployment/la_plateforme/">La Plateforme</a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" href="https://docs.mistral.ai/deployment/cloud/overview/">Cloud</a><button aria-label="Expand sidebar category 'Cloud'" aria-expanded="false" type="button" class="clean-btn menu__caret"></button></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" href="https://docs.mistral.ai/deployment/self-deployment/overview/">Self-deployment</a><button aria-label="Expand sidebar category 'Self-deployment'" aria-expanded="false" type="button" class="clean-btn menu__caret"></button></div></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu-label margin-top--md">Guides</li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="https://docs.mistral.ai/guides/prompting_capabilities/">Prompting capabilities</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="https://docs.mistral.ai/guides/rag/">Basic RAG</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item hidden"><a class="menu__link" href="https://docs.mistral.ai/guides/evaluation/">Evaluation</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="https://docs.mistral.ai/guides/tokenization/">Tokenization</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="https://docs.mistral.ai/guides/resources/">Other resources</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="https://docs.mistral.ai/guides/contribute/">How to contribute</a></li></ul></nav></div></div></aside><main class="docMainContainer_Bgup"><div class="container padding-top--md padding-bottom--lg"><div class="row"><div class="col docItemCol_Td3C"><div class="docItemContainer_REoc"><article><nav class="theme-doc-breadcrumbs breadcrumbsContainer_E2Xs" aria-label="Breadcrumbs"><ul class="breadcrumbs" itemscope="" itemtype="https://schema.org/BreadcrumbList"><li class="breadcrumbs__item"><a aria-label="Home page" class="breadcrumbs__link" href="https://docs.mistral.ai/"><svg viewBox="0 0 24 24" class="breadcrumbHomeIcon_M2Ot"><path d="M10 19v-5h4v5c0 .55.45 1 1 1h3c.55 0 1-.45 1-1v-7h1.7c.46 0 .68-.57.33-.87L12.67 3.6c-.38-.34-.96-.34-1.34 0l-8.36 7.53c-.34.3-.13.87.33.87H5v7c0 .55.45 1 1 1h3c.55 0 1-.45 1-1z" fill="currentColor"></path></svg></a></li><li itemscope="" itemprop="itemListElement" itemtype="https://schema.org/ListItem" class="breadcrumbs__item breadcrumbs__item--active"><span class="breadcrumbs__link" itemprop="name">Embeddings</span><meta itemprop="position" content="1"></li></ul></nav><div class="tocCollapsible_QOC6 theme-doc-toc-mobile tocMobile_EF9C"><button type="button" class="clean-btn tocCollapsibleButton_cni4">On this page</button></div><div class="theme-doc-markdown markdown"><header><h1>Embeddings</h1></header><p>Embeddings are vectorial representations of text that capture the semantic meaning of paragraphs through their position in a high dimensional vector space. Mistral AI Embeddings API offers cutting-edge, state-of-the-art embeddings for text, which can be used for many NLP tasks. In this guide, we will cover the fundamentals of the embeddings API, including how to measure the distance between text embeddings, and explore its main use cases: clustering and classification.</p>
<a target="_blank" href="https://colab.research.google.com/github/mistralai/cookbook/blob/main/embeddings.ipynb"><img src="./Embeddings _ Mistral AI Large Language Models_files/colab-badge.svg" alt="Open In Colab"></a>
<h2 class="anchor anchorWithStickyNavbar_r6n_" id="mistral-embeddings-api">Mistral Embeddings API<a href="https://docs.mistral.ai/capabilities/embeddings/#mistral-embeddings-api" class="hash-link" aria-label="Direct link to Mistral Embeddings API" title="Direct link to Mistral Embeddings API"></a></h2>
<p>To generate text embeddings using Mistral AI's embeddings API, we can make a request to the API endpoint and specify the embedding model <code>mistral-embed</code>, along with providing a list of input texts. The API will then return the corresponding embeddings as numerical vectors, which can be used for further analysis or processing in NLP applications.</p>
<div class="language-python codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-python codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token keyword" style="color: rgb(102, 217, 239);">from</span><span class="token plain"> mistralai</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">client </span><span class="token keyword" style="color: rgb(102, 217, 239);">import</span><span class="token plain"> MistralClient</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">client </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> MistralClient</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">api_key</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token string" style="color: rgb(166, 226, 46);">"TYPE YOUR API KEY HERE"</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">embeddings_batch_response </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> client</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">embeddings</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> model</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token string" style="color: rgb(166, 226, 46);">"mistral-embed"</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token builtin" style="color: rgb(230, 219, 116);">input</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token string" style="color: rgb(166, 226, 46);">"Embed this sentence."</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> </span><span class="token string" style="color: rgb(166, 226, 46);">"As well as this one."</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>The output <code>embeddings_batch_response</code> is an EmbeddingResponse object with the embeddings and the token usage information.</p>
<div class="codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-text codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">EmbeddingResponse(</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> id='eb4c2c739780415bb3af4e47580318cc', object='list', data=[</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> EmbeddingObject(object='embedding', embedding=[-0.0165863037109375,...], index=0),</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> EmbeddingObject(object='embedding', embedding=[-0.0234222412109375,...], index=1)],</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> model='mistral-embed', usage=UsageInfo(prompt_tokens=15, total_tokens=15, completion_tokens=0)</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">)</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Let's take a look of the length of the first embedding:</p>
<div class="language-python codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-python codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token builtin" style="color: rgb(230, 219, 116);">len</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">embeddings_batch_response</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">data</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token number" style="color: rgb(174, 129, 255);">0</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">embedding</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>It returns 1024, which means that our embedding dimension is 1024. The <code>mistral-embed</code> model generates embedding vectors of dimension 1024 for each text string, regardless of the text length. It's worth noting that while higher dimensional embeddings can better capture text information and improve the performance of NLP tasks, they may require more computational resources for hosting and inference, and may result in increased latency and memory usage for storing and processing these embeddings. This trade-off between performance and computational resources should be considered when designing NLP systems that rely on text embeddings.</p>
<h1>Distance Measures</h1>
<p>In the realm of text embeddings, texts with similar meanings or context tend to be located in closer proximity to each other within this space, as measured by the distance between their vectors. This is due to the fact that the model has learned to group semantically related texts together during the training process.</p>
<p>Let's take a look at a simple example. To simplify working with text embeddings, we can wrap the embedding API in this function:</p>
<div class="language-python codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-python codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token keyword" style="color: rgb(102, 217, 239);">from</span><span class="token plain"> sklearn</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">metrics</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">pairwise </span><span class="token keyword" style="color: rgb(102, 217, 239);">import</span><span class="token plain"> euclidean_distances</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token keyword" style="color: rgb(102, 217, 239);">def</span><span class="token plain"> </span><span class="token function" style="color: rgb(230, 219, 116);">get_text_embedding</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token builtin" style="color: rgb(230, 219, 116);">input</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">:</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> embeddings_batch_response </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> client</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">embeddings</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> model</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token string" style="color: rgb(166, 226, 46);">"mistral-embed"</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token builtin" style="color: rgb(230, 219, 116);">input</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token builtin" style="color: rgb(230, 219, 116);">input</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token keyword" style="color: rgb(102, 217, 239);">return</span><span class="token plain"> embeddings_batch_response</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">data</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token number" style="color: rgb(174, 129, 255);">0</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">embedding</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Suppose we have two sentences: one about cats and the other about books. We want to find how similar each sentence is to the reference sentence "Books are mirrors: You only see in them what you already have inside you". We can see that the distance between the reference sentence embeddings and the book sentence embeddings is smaller than the distance between the reference sentence embeddings and the cat sentence embeddings.</p>
<div class="language-python codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-python codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">sentences </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> </span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token string" style="color: rgb(166, 226, 46);">"A home without a cat — and a well-fed, well-petted and properly revered cat — may be a perfect home, perhaps, but how can it prove title?"</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token string" style="color: rgb(166, 226, 46);">"I think books are like people, in the sense that they'll turn up in your life when you most need them"</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">embeddings </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> </span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token plain">get_text_embedding</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">t</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"> </span><span class="token keyword" style="color: rgb(102, 217, 239);">for</span><span class="token plain"> t </span><span class="token keyword" style="color: rgb(102, 217, 239);">in</span><span class="token plain"> sentences</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">reference_sentence </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> </span><span class="token string" style="color: rgb(166, 226, 46);">"Books are mirrors: You only see in them what you already have inside you"</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">reference_embedding </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> get_text_embedding</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">reference_sentence</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token keyword" style="color: rgb(102, 217, 239);">for</span><span class="token plain"> t</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> e </span><span class="token keyword" style="color: rgb(102, 217, 239);">in</span><span class="token plain"> </span><span class="token builtin" style="color: rgb(230, 219, 116);">zip</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">sentences</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> embeddings</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">:</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> distance </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> euclidean_distances</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token plain">e</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> </span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token plain">reference_embedding</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token keyword" style="color: rgb(102, 217, 239);">print</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">t</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> distance</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Output</p>
<div class="codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-text codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">A home without a cat — and a well-fed, well-petted and properly revered cat — may be a perfect home, perhaps, but how can it prove title? [[0.80094257]]</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">I think books are like people, in the sense that they'll turn up in your life when you most need them [[0.58162089]]</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>In our example above, we used the Euclidean distance to measure the distance between embedding vectors (note that since Mistral AI embeddings are norm 1, cosine similarity, dot product or Euclidean distance are all equivalent).</p>
<h2 class="anchor anchorWithStickyNavbar_r6n_" id="paraphrase-detection">Paraphrase detection<a href="https://docs.mistral.ai/capabilities/embeddings/#paraphrase-detection" class="hash-link" aria-label="Direct link to Paraphrase detection" title="Direct link to Paraphrase detection"></a></h2>
<p>Another potential use case is paraphrase detection. In this simple example, we have a list of three sentences, and we would like to find out if any of the two sentences are paraphrases of each other. If the distance between two sentence embeddings is small, it suggests that the two sentences are semantically similar and could be potential paraphrases.</p>
<p>Result suggests that the first two sentences are semantically similar and could be potential paraphrases, whereas the third sentence is more different. This is just a super simple example. But this approach can be extended to more complex situations in real-world applications, such as detecting paraphrases in social media posts, news articles, or customer reviews.</p>
<div class="language-python codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-python codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token keyword" style="color: rgb(102, 217, 239);">import</span><span class="token plain"> itertools</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">sentences </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> </span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token string" style="color: rgb(166, 226, 46);">"Have a safe happy Memorial Day weekend everyone"</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token string" style="color: rgb(166, 226, 46);">"To all our friends at Whatsit Productions Films enjoy a safe happy Memorial Day weekend"</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token string" style="color: rgb(166, 226, 46);">"Where can I find the best cheese?"</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">sentence_embeddings </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> </span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token plain">get_text_embedding</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">t</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"> </span><span class="token keyword" style="color: rgb(102, 217, 239);">for</span><span class="token plain"> t </span><span class="token keyword" style="color: rgb(102, 217, 239);">in</span><span class="token plain"> sentences</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">sentence_embeddings_pairs </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> </span><span class="token builtin" style="color: rgb(230, 219, 116);">list</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">itertools</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">combinations</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">sentence_embeddings</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> </span><span class="token number" style="color: rgb(174, 129, 255);">2</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">sentence_pairs </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> </span><span class="token builtin" style="color: rgb(230, 219, 116);">list</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">itertools</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">combinations</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">sentences</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> </span><span class="token number" style="color: rgb(174, 129, 255);">2</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token keyword" style="color: rgb(102, 217, 239);">for</span><span class="token plain"> s</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> e </span><span class="token keyword" style="color: rgb(102, 217, 239);">in</span><span class="token plain"> </span><span class="token builtin" style="color: rgb(230, 219, 116);">zip</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">sentence_pairs</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> sentence_embeddings_pairs</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">:</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token keyword" style="color: rgb(102, 217, 239);">print</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">s</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> euclidean_distances</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token plain">e</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token number" style="color: rgb(174, 129, 255);">0</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> </span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token plain">e</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token number" style="color: rgb(174, 129, 255);">1</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Output</p>
<div class="codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-text codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">('Have a safe happy Memorial Day weekend everyone', 'To all our friends at Whatsit Productions Films enjoy a safe happy Memorial Day weekend') [[0.54326686]]</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">('Have a safe happy Memorial Day weekend everyone', 'Where can I find the best cheese?') [[0.92573978]]</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">('To all our friends at Whatsit Productions Films enjoy a safe happy Memorial Day weekend', 'Where can I find the best cheese?') [[0.9114184]]</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h2 class="anchor anchorWithStickyNavbar_r6n_" id="batch-processing">Batch processing<a href="https://docs.mistral.ai/capabilities/embeddings/#batch-processing" class="hash-link" aria-label="Direct link to Batch processing" title="Direct link to Batch processing"></a></h2>
<p>The Mistral AI Embeddings API is designed to process text in batches for improved efficiency and speed. In this example, we will demonstrate this by loading the Symptom2Disease dataset from <a href="https://www.kaggle.com/datasets/niyarrbarman/symptom2disease" target="_blank" rel="noopener noreferrer">Kaggle</a>, which contains 1200 rows with two columns: "label" and "text". The "label" column indicates the disease category, while the "text" column describes the symptoms associated with that disease.</p>
<p>We wrote a function <code>get_embeddings_by_chunks</code> that splits data into chunks and then sends each chunk to the Mistral AI Embeddings API to get the embeddings. Then we saved the embeddings as a new column in the dataframe. Note that the API will provide auto-chunking in the future, so that users don't need to manually split the data into chunks before sending it.</p>
<div class="language-python codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-python codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token keyword" style="color: rgb(102, 217, 239);">import</span><span class="token plain"> pandas </span><span class="token keyword" style="color: rgb(102, 217, 239);">as</span><span class="token plain"> pd</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">df </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> pd</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">read_csv</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token string" style="color: rgb(166, 226, 46);">"https://raw.githubusercontent.com/mistralai/cookbook/main/data/Symptom2Disease.csv"</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> index_col</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token number" style="color: rgb(174, 129, 255);">0</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token keyword" style="color: rgb(102, 217, 239);">def</span><span class="token plain"> </span><span class="token function" style="color: rgb(230, 219, 116);">get_embeddings_by_chunks</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">data</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> chunk_size</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">:</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> chunks </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> </span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token plain">data</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token plain">x </span><span class="token punctuation" style="color: rgb(248, 248, 242);">:</span><span class="token plain"> x </span><span class="token operator" style="color: rgb(102, 217, 239);">+</span><span class="token plain"> chunk_size</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token plain"> </span><span class="token keyword" style="color: rgb(102, 217, 239);">for</span><span class="token plain"> x </span><span class="token keyword" style="color: rgb(102, 217, 239);">in</span><span class="token plain"> </span><span class="token builtin" style="color: rgb(230, 219, 116);">range</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token number" style="color: rgb(174, 129, 255);">0</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> </span><span class="token builtin" style="color: rgb(230, 219, 116);">len</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">data</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> chunk_size</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> embeddings_response </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> </span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> client</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">embeddings</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">model</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token string" style="color: rgb(166, 226, 46);">"mistral-embed"</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> </span><span class="token builtin" style="color: rgb(230, 219, 116);">input</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain">c</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"> </span><span class="token keyword" style="color: rgb(102, 217, 239);">for</span><span class="token plain"> c </span><span class="token keyword" style="color: rgb(102, 217, 239);">in</span><span class="token plain"> chunks</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token keyword" style="color: rgb(102, 217, 239);">return</span><span class="token plain"> </span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token plain">d</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">embedding </span><span class="token keyword" style="color: rgb(102, 217, 239);">for</span><span class="token plain"> e </span><span class="token keyword" style="color: rgb(102, 217, 239);">in</span><span class="token plain"> embeddings_response </span><span class="token keyword" style="color: rgb(102, 217, 239);">for</span><span class="token plain"> d </span><span class="token keyword" style="color: rgb(102, 217, 239);">in</span><span class="token plain"> e</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">data</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">df</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token string" style="color: rgb(166, 226, 46);">"embeddings"</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token plain"> </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> get_embeddings_by_chunks</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">df</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token string" style="color: rgb(166, 226, 46);">"text"</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">tolist</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> </span><span class="token number" style="color: rgb(174, 129, 255);">50</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">df</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">head</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<img src="./Embeddings _ Mistral AI Large Language Models_files/embeddings1.png" alt="drawing" width="700">
<h1>t-SNE embeddings visualization</h1>
<p>We mentioned previously that our embeddings have 1024 dimensions, which makes them impossible to visualize directly. Thus, in order to visualize our embeddings, we can use a dimensionality reduction technique such as t-SNE to project our embeddings into a lower-dimensional space that is easier to visualize.</p>
<p>In this example, we transform our embeddings to 2 dimensions and create a 2D scatter plot showing the relationships among embeddings of different diseases.</p>
<div class="language-python codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-python codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token keyword" style="color: rgb(102, 217, 239);">import</span><span class="token plain"> seaborn </span><span class="token keyword" style="color: rgb(102, 217, 239);">as</span><span class="token plain"> sns</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token keyword" style="color: rgb(102, 217, 239);">from</span><span class="token plain"> sklearn</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">manifold </span><span class="token keyword" style="color: rgb(102, 217, 239);">import</span><span class="token plain"> TSNE</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token keyword" style="color: rgb(102, 217, 239);">import</span><span class="token plain"> numpy </span><span class="token keyword" style="color: rgb(102, 217, 239);">as</span><span class="token plain"> np</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">tsne </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> TSNE</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">n_components</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token number" style="color: rgb(174, 129, 255);">2</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> random_state</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token number" style="color: rgb(174, 129, 255);">0</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">fit_transform</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">np</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">array</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">df</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token string" style="color: rgb(166, 226, 46);">'embeddings'</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">to_list</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">ax </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> sns</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">scatterplot</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">x</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain">tsne</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token punctuation" style="color: rgb(248, 248, 242);">:</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> </span><span class="token number" style="color: rgb(174, 129, 255);">0</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> y</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain">tsne</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token punctuation" style="color: rgb(248, 248, 242);">:</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> </span><span class="token number" style="color: rgb(174, 129, 255);">1</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> hue</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain">np</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">array</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">df</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token string" style="color: rgb(166, 226, 46);">'label'</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">to_list</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">sns</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">move_legend</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">ax</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> </span><span class="token string" style="color: rgb(166, 226, 46);">'upper left'</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> bbox_to_anchor</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token number" style="color: rgb(174, 129, 255);">1</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> </span><span class="token number" style="color: rgb(174, 129, 255);">1</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<img src="./Embeddings _ Mistral AI Large Language Models_files/embeddings2.png" alt="drawing" width="600">
<h3 class="anchor anchorWithStickyNavbar_r6n_" id="comparison-with-fasttext">Comparison with fastText<a href="https://docs.mistral.ai/capabilities/embeddings/#comparison-with-fasttext" class="hash-link" aria-label="Direct link to Comparison with fastText" title="Direct link to Comparison with fastText"></a></h3>
<p>We can compare it with fastText, a popular open-source embeddings model. However, when examining the t-SNE embeddings plot, we notice that fastText embeddings fail to create clear separations between data points with matching labels.</p>
<div class="language-python codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-python codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token keyword" style="color: rgb(102, 217, 239);">import</span><span class="token plain"> fasttext</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">util</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">fasttext</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">util</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">download_model</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token string" style="color: rgb(166, 226, 46);">'en'</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> if_exists</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token string" style="color: rgb(166, 226, 46);">'ignore'</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"> </span><span class="token comment" style="color: rgb(130, 146, 162); font-style: italic;"># English</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">ft </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> fasttext</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">load_model</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token string" style="color: rgb(166, 226, 46);">'cc.en.300.bin'</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">df</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token string" style="color: rgb(166, 226, 46);">'fasttext_embeddings'</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token plain"> </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> df</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token string" style="color: rgb(166, 226, 46);">'text'</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token builtin" style="color: rgb(230, 219, 116);">apply</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token keyword" style="color: rgb(102, 217, 239);">lambda</span><span class="token plain"> x</span><span class="token punctuation" style="color: rgb(248, 248, 242);">:</span><span class="token plain"> ft</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">get_word_vector</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">x</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">tolist</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">tsne </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> TSNE</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">n_components</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token number" style="color: rgb(174, 129, 255);">2</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> random_state</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token number" style="color: rgb(174, 129, 255);">0</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">fit_transform</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">np</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">array</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">df</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token string" style="color: rgb(166, 226, 46);">'fasttext_embeddings'</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">to_list</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">ax </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> sns</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">scatterplot</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">x</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain">tsne</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token punctuation" style="color: rgb(248, 248, 242);">:</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> </span><span class="token number" style="color: rgb(174, 129, 255);">0</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> y</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain">tsne</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token punctuation" style="color: rgb(248, 248, 242);">:</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> </span><span class="token number" style="color: rgb(174, 129, 255);">1</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> hue</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain">np</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">array</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">df</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token string" style="color: rgb(166, 226, 46);">'label'</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">to_list</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">sns</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">move_legend</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">ax</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> </span><span class="token string" style="color: rgb(166, 226, 46);">'upper left'</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> bbox_to_anchor</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token number" style="color: rgb(174, 129, 255);">1</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> </span><span class="token number" style="color: rgb(174, 129, 255);">1</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<img src="./Embeddings _ Mistral AI Large Language Models_files/embeddings3.webp" alt="drawing" width="600">
<h2 class="anchor anchorWithStickyNavbar_r6n_" id="classification">Classification<a href="https://docs.mistral.ai/capabilities/embeddings/#classification" class="hash-link" aria-label="Direct link to Classification" title="Direct link to Classification"></a></h2>
<p>Text embeddings can be used as input features in machine learning models, such as classification and clustering. In this example, we use a classification model to predict the disease labels from the embeddings of disease description text.</p>
<div class="language-python codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-python codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token keyword" style="color: rgb(102, 217, 239);">from</span><span class="token plain"> sklearn</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">model_selection </span><span class="token keyword" style="color: rgb(102, 217, 239);">import</span><span class="token plain"> train_test_split</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token keyword" style="color: rgb(102, 217, 239);">from</span><span class="token plain"> sklearn</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">preprocessing </span><span class="token keyword" style="color: rgb(102, 217, 239);">import</span><span class="token plain"> StandardScaler</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token keyword" style="color: rgb(102, 217, 239);">from</span><span class="token plain"> sklearn</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">linear_model </span><span class="token keyword" style="color: rgb(102, 217, 239);">import</span><span class="token plain"> LogisticRegression</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token comment" style="color: rgb(130, 146, 162); font-style: italic;"># Create a train / test split</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">train_x</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> test_x</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> train_y</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> test_y </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> train_test_split</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> df</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token string" style="color: rgb(166, 226, 46);">"embeddings"</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> df</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token string" style="color: rgb(166, 226, 46);">"label"</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> test_size</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token number" style="color: rgb(174, 129, 255);">0.2</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token comment" style="color: rgb(130, 146, 162); font-style: italic;"># Normalize features</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">scaler </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> StandardScaler</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">train_x </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> scaler</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">fit_transform</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">train_x</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">to_list</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">test_x </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> scaler</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">transform</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">test_x</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">to_list</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token comment" style="color: rgb(130, 146, 162); font-style: italic;"># Train a classifier and compute the test accuracy</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token comment" style="color: rgb(130, 146, 162); font-style: italic;"># For a real problem, C should be properly cross validated and the confusion matrix analyzed</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">clf </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> LogisticRegression</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">random_state</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token number" style="color: rgb(174, 129, 255);">0</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> C</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token number" style="color: rgb(174, 129, 255);">1.0</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> max_iter</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token number" style="color: rgb(174, 129, 255);">500</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">fit</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> train_x</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> train_y</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">to_list</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token comment" style="color: rgb(130, 146, 162); font-style: italic;"># you can also try the sag algorithm:</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token comment" style="color: rgb(130, 146, 162); font-style: italic;"># clf = LogisticRegression(random_state=0, C=1.0, max_iter=1000, solver='sag').fit(train_x, train_y)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token keyword" style="color: rgb(102, 217, 239);">print</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token string-interpolation string" style="color: rgb(166, 226, 46);">f"Precision: </span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">{</span><span class="token string-interpolation interpolation number" style="color: rgb(174, 129, 255);">100</span><span class="token string-interpolation interpolation operator" style="color: rgb(102, 217, 239);">*</span><span class="token string-interpolation interpolation">np</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token string-interpolation interpolation">mean</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token string-interpolation interpolation">clf</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token string-interpolation interpolation">predict</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token string-interpolation interpolation">test_x</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token string-interpolation interpolation"> </span><span class="token string-interpolation interpolation operator" style="color: rgb(102, 217, 239);">==</span><span class="token string-interpolation interpolation"> test_y</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token string-interpolation interpolation">to_list</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">:</span><span class="token string-interpolation interpolation format-spec">.2f</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">}</span><span class="token string-interpolation string" style="color: rgb(166, 226, 46);">%"</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Output</p>
<div class="codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-text codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">Precision: 98.75%</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>After we trained the classifier with our embeddings data, we can try classify other text:</p>
<div class="language-python codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-python codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token comment" style="color: rgb(130, 146, 162); font-style: italic;"># Classify a single example</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">text </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> </span><span class="token string" style="color: rgb(166, 226, 46);">"I've been experiencing frequent headaches and vision problems."</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">clf</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">predict</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token plain">get_text_embedding</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">text</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Output</p>
<div class="codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-text codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">'Migraine'</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h3 class="anchor anchorWithStickyNavbar_r6n_" id="comparison-with-fasttext-1">Comparison with fastText<a href="https://docs.mistral.ai/capabilities/embeddings/#comparison-with-fasttext-1" class="hash-link" aria-label="Direct link to Comparison with fastText" title="Direct link to Comparison with fastText"></a></h3>
<p>Additionally, let's take a look at the performance using fastText embeddings in this classification task. It appears that the classification model achieves better performance with Mistral AI Embeddings model as compared to using fastText embeddings.</p>
<div class="language-python codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-python codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token comment" style="color: rgb(130, 146, 162); font-style: italic;"># Create a train / test split</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">train_x</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> test_x</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> train_y</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> test_y </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> train_test_split</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> df</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token string" style="color: rgb(166, 226, 46);">"fasttext_embeddings"</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> df</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token string" style="color: rgb(166, 226, 46);">"label"</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> test_size</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token number" style="color: rgb(174, 129, 255);">0.2</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token comment" style="color: rgb(130, 146, 162); font-style: italic;"># Normalize features</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">scaler </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> StandardScaler</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">train_x </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> scaler</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">fit_transform</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">train_x</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">to_list</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">test_x </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> scaler</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">transform</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">test_x</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">to_list</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token comment" style="color: rgb(130, 146, 162); font-style: italic;"># Train a classifier and compute the test accuracy</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token comment" style="color: rgb(130, 146, 162); font-style: italic;"># For a real problem, C should be properly cross validated and the confusion matrix analyzed</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">clf </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> LogisticRegression</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">random_state</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token number" style="color: rgb(174, 129, 255);">0</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> C</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token number" style="color: rgb(174, 129, 255);">1.0</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> max_iter</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token number" style="color: rgb(174, 129, 255);">500</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">fit</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> train_x</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> train_y</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">to_list</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token comment" style="color: rgb(130, 146, 162); font-style: italic;"># you can also try the sag algorithm:</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token comment" style="color: rgb(130, 146, 162); font-style: italic;"># clf = LogisticRegression(random_state=0, C=1.0, max_iter=1000, solver='sag').fit(train_x, train_y)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token keyword" style="color: rgb(102, 217, 239);">print</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token string-interpolation string" style="color: rgb(166, 226, 46);">f"Precision: </span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">{</span><span class="token string-interpolation interpolation number" style="color: rgb(174, 129, 255);">100</span><span class="token string-interpolation interpolation operator" style="color: rgb(102, 217, 239);">*</span><span class="token string-interpolation interpolation">np</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token string-interpolation interpolation">mean</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token string-interpolation interpolation">clf</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token string-interpolation interpolation">predict</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token string-interpolation interpolation">test_x</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token string-interpolation interpolation"> </span><span class="token string-interpolation interpolation operator" style="color: rgb(102, 217, 239);">==</span><span class="token string-interpolation interpolation"> test_y</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token string-interpolation interpolation">to_list</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">:</span><span class="token string-interpolation interpolation format-spec">.2f</span><span class="token string-interpolation interpolation punctuation" style="color: rgb(248, 248, 242);">}</span><span class="token string-interpolation string" style="color: rgb(166, 226, 46);">%"</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Output</p>
<div class="codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-text codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">Precision: 86.25%</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h2 class="anchor anchorWithStickyNavbar_r6n_" id="clustering">Clustering<a href="https://docs.mistral.ai/capabilities/embeddings/#clustering" class="hash-link" aria-label="Direct link to Clustering" title="Direct link to Clustering"></a></h2>
<p>What if we don't have disease labels? One approach to gain insights from the data is through clustering. Clustering is an unsupervised machine learning technique that groups similar data points together based on their similarity with respect to certain features. In the context of text embeddings, we can use the distance between each embedding as a measure of similarity, and group together data points with embeddings that are close to each other in the high-dimensional space.</p>
<p>Since we already know there are 24 clusters, let's use the K-means clustering with 24 clusters. Then we can inspect a few examples and verify whether the examples in a single cluster are similar to one another. For example, take a look at the first three rows of cluster 23. We can see that they look very similar in terms of symptoms.</p>
<div class="language-python codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-python codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token keyword" style="color: rgb(102, 217, 239);">from</span><span class="token plain"> sklearn</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">cluster </span><span class="token keyword" style="color: rgb(102, 217, 239);">import</span><span class="token plain"> KMeans</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">model </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> KMeans</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">n_clusters</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token number" style="color: rgb(174, 129, 255);">24</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> max_iter</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token number" style="color: rgb(174, 129, 255);">1000</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">model</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">fit</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">df</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token string" style="color: rgb(166, 226, 46);">'embeddings'</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">to_list</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">df</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token string" style="color: rgb(166, 226, 46);">"cluster"</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token plain"> </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> model</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">labels_</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token keyword" style="color: rgb(102, 217, 239);">print</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token operator" style="color: rgb(102, 217, 239);">*</span><span class="token plain">df</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token plain">df</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">cluster</span><span class="token operator" style="color: rgb(102, 217, 239);">==</span><span class="token number" style="color: rgb(174, 129, 255);">23</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">text</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">head</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token number" style="color: rgb(174, 129, 255);">3</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> sep</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token string" style="color: rgb(166, 226, 46);">'\n\n'</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Output:</p>
<div class="codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-text codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">I have been feeling extremely tired and weak, and I've also been coughing a lot with difficulty breathing. My fever is very high, and I'm producing a lot of mucus when I cough.</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">I've got a cough that won't go away, and I'm exhausted. I've been coughing up thick mucous and my fever is also pretty high.</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">I have a persistent cough and have been feeling quite fatigued. My fever is through the roof, and I'm having trouble breathing. When I cough, I also cough up a lot of mucous.</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h2 class="anchor anchorWithStickyNavbar_r6n_" id="retrieval">Retrieval<a href="https://docs.mistral.ai/capabilities/embeddings/#retrieval" class="hash-link" aria-label="Direct link to Retrieval" title="Direct link to Retrieval"></a></h2>
<p>Our embedding model excels in retrieval tasks, as it is trained with retrieval in mind. Embeddings are also incredibly helpful in implementing retrieval-augmented generation (RAG) systems, which use retrieved relevant information from a knowledge base to generate responses. At a high-level, we embed a knowledge base, whether it is a local directory, text files, or internal wikis, into text embeddings and store them in a vector database. Then, based on the user's query, we retrieve the most similar embeddings, which represent the relevant information from the knowledge base. Finally, we feed these relevant embeddings to a large language model to generate a response that is tailored to the user's query and context. If you are interested in learning more about how RAG systems work and how to implement a basic RAG, check out our <a href="https://docs.mistral.ai/guides/rag/">previous guide</a> on this topic.
The embeddings API allows you to embed sentences.</p>
<div class="tabs-container tabList_t0ny"><ul role="tablist" aria-orientation="horizontal" class="tabs"><li role="tab" tabindex="0" aria-selected="true" class="tabs__item tabItem_uTIH tabs__item--active">python</li><li role="tab" tabindex="-1" aria-selected="false" class="tabs__item tabItem_uTIH">javascript</li><li role="tab" tabindex="-1" aria-selected="false" class="tabs__item tabItem_uTIH">curl</li></ul><div class="margin-top--md"><div role="tabpanel" class="tabItem_Qjpd"><div class="language-python codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-python codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token keyword" style="color: rgb(102, 217, 239);">from</span><span class="token plain"> mistralai</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">client </span><span class="token keyword" style="color: rgb(102, 217, 239);">import</span><span class="token plain"> MistralClient</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">api_key </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> os</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">environ</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token string" style="color: rgb(166, 226, 46);">"MISTRAL_API_KEY"</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">client </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> MistralClient</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">api_key</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain">api_key</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain">embeddings_batch_response </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> client</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token plain">embeddings</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> model</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token string" style="color: rgb(166, 226, 46);">"mistral-embed"</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token builtin" style="color: rgb(230, 219, 116);">input</span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token string" style="color: rgb(166, 226, 46);">"Embed this sentence."</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> </span><span class="token string" style="color: rgb(166, 226, 46);">"As well as this one."</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div></div><div role="tabpanel" class="tabItem_Qjpd" hidden=""><div class="language-javascript codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-javascript codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token keyword module" style="color: rgb(102, 217, 239);">import</span><span class="token plain"> </span><span class="token imports maybe-class-name">MistralClient</span><span class="token plain"> </span><span class="token keyword module" style="color: rgb(102, 217, 239);">from</span><span class="token plain"> </span><span class="token string" style="color: rgb(166, 226, 46);">'@mistralai/mistralai'</span><span class="token punctuation" style="color: rgb(248, 248, 242);">;</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token keyword" style="color: rgb(102, 217, 239);">const</span><span class="token plain"> apiKey </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> process</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token property-access">env</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token constant" style="color: rgb(230, 219, 116);">MISTRAL_API_KEY</span><span class="token punctuation" style="color: rgb(248, 248, 242);">;</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token keyword" style="color: rgb(102, 217, 239);">const</span><span class="token plain"> client </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> </span><span class="token keyword" style="color: rgb(102, 217, 239);">new</span><span class="token plain"> </span><span class="token class-name" style="color: rgb(230, 219, 116);">MistralClient</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token plain">apiKey</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">;</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token keyword" style="color: rgb(102, 217, 239);">const</span><span class="token plain"> input </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> </span><span class="token punctuation" style="color: rgb(248, 248, 242);">[</span><span class="token punctuation" style="color: rgb(248, 248, 242);">]</span><span class="token punctuation" style="color: rgb(248, 248, 242);">;</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token keyword control-flow" style="color: rgb(102, 217, 239);">for</span><span class="token plain"> </span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token keyword" style="color: rgb(102, 217, 239);">let</span><span class="token plain"> i </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> </span><span class="token number" style="color: rgb(174, 129, 255);">0</span><span class="token punctuation" style="color: rgb(248, 248, 242);">;</span><span class="token plain"> i </span><span class="token operator" style="color: rgb(102, 217, 239);"><</span><span class="token plain"> </span><span class="token number" style="color: rgb(174, 129, 255);">10</span><span class="token punctuation" style="color: rgb(248, 248, 242);">;</span><span class="token plain"> i</span><span class="token operator" style="color: rgb(102, 217, 239);">++</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token plain"> </span><span class="token punctuation" style="color: rgb(248, 248, 242);">{</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> input</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token method function property-access" style="color: rgb(230, 219, 116);">push</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token string" style="color: rgb(166, 226, 46);">'What is the best French cheese?'</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">;</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token punctuation" style="color: rgb(248, 248, 242);">}</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token keyword" style="color: rgb(102, 217, 239);">const</span><span class="token plain"> embeddingsBatchResponse </span><span class="token operator" style="color: rgb(102, 217, 239);">=</span><span class="token plain"> </span><span class="token keyword control-flow" style="color: rgb(102, 217, 239);">await</span><span class="token plain"> client</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token method function property-access" style="color: rgb(230, 219, 116);">embeddings</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token punctuation" style="color: rgb(248, 248, 242);">{</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token literal-property property" style="color: rgb(249, 38, 114);">model</span><span class="token operator" style="color: rgb(102, 217, 239);">:</span><span class="token plain"> </span><span class="token string" style="color: rgb(166, 226, 46);">'mistral-embed'</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token literal-property property" style="color: rgb(249, 38, 114);">input</span><span class="token operator" style="color: rgb(102, 217, 239);">:</span><span class="token plain"> input</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token punctuation" style="color: rgb(248, 248, 242);">}</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">;</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain" style="display: inline-block;"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"></span><span class="token console class-name" style="color: rgb(230, 219, 116);">console</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token method function property-access" style="color: rgb(230, 219, 116);">log</span><span class="token punctuation" style="color: rgb(248, 248, 242);">(</span><span class="token string" style="color: rgb(166, 226, 46);">'Embeddings Batch:'</span><span class="token punctuation" style="color: rgb(248, 248, 242);">,</span><span class="token plain"> embeddingsBatchResponse</span><span class="token punctuation" style="color: rgb(248, 248, 242);">.</span><span class="token property-access">data</span><span class="token punctuation" style="color: rgb(248, 248, 242);">)</span><span class="token punctuation" style="color: rgb(248, 248, 242);">;</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div></div><div role="tabpanel" class="tabItem_Qjpd" hidden=""><div class="language-bash codeBlockContainer_YMIx theme-code-block" style="--prism-color: #f8f8f2; --prism-background-color: #272822;"><div class="codeBlockContent_l9UM"><pre tabindex="0" class="prism-code language-bash codeBlock_iAC8 thin-scrollbar" style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34);"><code class="codeBlockLines_jCwv"><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token function" style="color: rgb(230, 219, 116);">curl</span><span class="token plain"> </span><span class="token parameter variable" style="color: rgb(248, 248, 242);">--location</span><span class="token plain"> </span><span class="token string" style="color: rgb(166, 226, 46);">"https://api.mistral.ai/v1/embeddings"</span><span class="token plain"> </span><span class="token punctuation" style="color: rgb(248, 248, 242);">\</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token parameter variable" style="color: rgb(248, 248, 242);">--header</span><span class="token plain"> </span><span class="token string" style="color: rgb(166, 226, 46);">'Content-Type: application/json'</span><span class="token plain"> </span><span class="token punctuation" style="color: rgb(248, 248, 242);">\</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token parameter variable" style="color: rgb(248, 248, 242);">--header</span><span class="token plain"> </span><span class="token string" style="color: rgb(166, 226, 46);">'Accept: application/json'</span><span class="token plain"> </span><span class="token punctuation" style="color: rgb(248, 248, 242);">\</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token parameter variable" style="color: rgb(248, 248, 242);">--header</span><span class="token plain"> </span><span class="token string" style="color: rgb(166, 226, 46);">"Authorization: Bearer </span><span class="token string variable" style="color: rgb(248, 248, 242);">$MISTRAL_API_KEY</span><span class="token string" style="color: rgb(166, 226, 46);">"</span><span class="token plain"> </span><span class="token punctuation" style="color: rgb(248, 248, 242);">\</span><span class="token plain"></span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token plain"> </span><span class="token parameter variable" style="color: rgb(248, 248, 242);">--data</span><span class="token plain"> </span><span class="token string" style="color: rgb(166, 226, 46);">'{</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token string" style="color: rgb(166, 226, 46);"> "model": "mistral-embed",</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token string" style="color: rgb(166, 226, 46);"> "input": [</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token string" style="color: rgb(166, 226, 46);"> "Embed this sentence.", </span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token string" style="color: rgb(166, 226, 46);"> "As well as this one."</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token string" style="color: rgb(166, 226, 46);"> ]</span><br></span><span class="token-line" style="color: rgb(248, 248, 242);"><span class="token string" style="color: rgb(166, 226, 46);"> }'</span><br></span></code></pre><div class="buttonGroup_k3YM"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_Lgzn" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_SOZX"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_sALW"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div></div></div></div></div></article><nav class="pagination-nav docusaurus-mt-lg" aria-label="Docs pages"><a class="pagination-nav__link pagination-nav__link--prev" href="https://docs.mistral.ai/capabilities/completion/"><div class="pagination-nav__sublabel">Previous</div><div class="pagination-nav__label">Text generation</div></a><a class="pagination-nav__link pagination-nav__link--next" href="https://docs.mistral.ai/capabilities/function_calling/"><div class="pagination-nav__sublabel">Next</div><div class="pagination-nav__label">Function calling</div></a></nav></div></div><div class="col col--3"><div class="tableOfContents_dRcY thin-scrollbar theme-doc-toc-desktop"><ul class="table-of-contents table-of-contents__left-border"><li><a href="https://docs.mistral.ai/capabilities/embeddings/#mistral-embeddings-api" class="table-of-contents__link toc-highlight">Mistral Embeddings API</a></li><li><a href="https://docs.mistral.ai/capabilities/embeddings/#paraphrase-detection" class="table-of-contents__link toc-highlight">Paraphrase detection</a></li><li><a href="https://docs.mistral.ai/capabilities/embeddings/#batch-processing" class="table-of-contents__link toc-highlight">Batch processing</a><ul><li><a href="https://docs.mistral.ai/capabilities/embeddings/#comparison-with-fasttext" class="table-of-contents__link toc-highlight">Comparison with fastText</a></li></ul></li><li><a href="https://docs.mistral.ai/capabilities/embeddings/#classification" class="table-of-contents__link toc-highlight">Classification</a><ul><li><a href="https://docs.mistral.ai/capabilities/embeddings/#comparison-with-fasttext-1" class="table-of-contents__link toc-highlight">Comparison with fastText</a></li></ul></li><li><a href="https://docs.mistral.ai/capabilities/embeddings/#clustering" class="table-of-contents__link toc-highlight">Clustering</a></li><li><a href="https://docs.mistral.ai/capabilities/embeddings/#retrieval" class="table-of-contents__link toc-highlight">Retrieval</a></li></ul></div></div></div></div></main></div></div></div><footer class="footer footer--dark"><div class="container container-fluid"><div class="row footer__links"><div class="col footer__col"><div class="footer__title">Documentation</div><ul class="footer__items clean-list"><li class="footer__item"><a class="footer__link-item" href="https://docs.mistral.ai/">Documentation</a></li><li class="footer__item"><a class="footer__link-item" href="https://docs.mistral.ai/guides/contribute/">Contributing</a></li></ul></div><div class="col footer__col"><div class="footer__title">Community</div><ul class="footer__items clean-list"><li class="footer__item"><a href="https://discord.gg/mistralai" target="_blank" rel="noopener noreferrer" class="footer__link-item">Discord<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_yPTG"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://twitter.com/MistralAI" target="_blank" rel="noopener noreferrer" class="footer__link-item">X<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_yPTG"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://github.com/mistralai" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_yPTG"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">Copyright © 2024 Mistral AI.</div></div></div></footer></div>
<!-- Cloudflare Pages Analytics --><script defer="" src="./Embeddings _ Mistral AI Large Language Models_files/beacon.min.js.download" data-cf-beacon="{"token": "f43ca8e80d85407ea6ca57cd621eacc6"}"></script><!-- Cloudflare Pages Analytics --><script defer="" src="./Embeddings _ Mistral AI Large Language Models_files/vef91dfe02fce4ee0ad053f6de4f175db1715022073587" integrity="sha512-sDIX0kl85v1Cl5tu4WGLZCpH/dV9OHbA4YlKCuCiMmOQIk4buzoYDZSFj+TvC71mOBLh8CDC/REgE0GX0xcbjA==" data-cf-beacon="{"rayId":"88972f6e398eab5d","version":"2024.4.1","token":"36b4216ae2dc4d5488c249161e71fe1e"}" crossorigin="anonymous"></script>
</body></html>