# Source: https://docs.aimlapi.com/api-references/embedding-models/together-ai/m2-bert-80m-retrieval.md

# m2-bert-80M-retrieval

{% columns %}
{% column width="66.66666666666666%" %}
{% hint style="info" %}
This documentation is valid for the following list of our models:

* `togethercomputer/m2-bert-80M-32k-retrieval`
  {% endhint %}
  {% endcolumn %}

{% column width="33.33333333333334%" %} <a href="https://aimlapi.com/app/togethercomputer/m2-bert-80M-32k-retrieval" class="button primary">Try in Playground</a>
{% endcolumn %}
{% endcolumns %}

## Model Overview

The model integrates advanced machine learning techniques to excel in searching and retrieving relevant information from vast datasets. With its 8k parameter design, it balances performance and efficiency, making it suitable for applications requiring high-speed data access and analysis.

## Setup your API Key

If you don’t have an API key for the AI/ML API yet, feel free to use our [Quickstart guide](https://docs.aimlapi.com/quickstart/setting-up).

## API Schema

## POST /v1/embeddings

>

```json
{"openapi":"3.0.0","info":{"title":"AI/ML Gateway","version":"1.0"},"servers":[{"url":"https://api.aimlapi.com"}],"security":[{"access-token":[]}],"components":{"securitySchemes":{"access-token":{"scheme":"bearer","bearerFormat":"<YOUR_AIMLAPI_KEY>","type":"http","description":"Bearer key"}},"schemas":{"Embedding.v1.CreateEmbeddingsResponseDTO":{"type":"object","properties":{"object":{"type":"string","enum":["object"]},"data":{"type":"array","items":{"type":"object","properties":{"object":{"type":"string","enum":["embedding"]},"index":{"type":"number"},"embedding":{"type":"array","items":{"type":"number"}}},"required":["object","index","embedding"]}},"model":{"type":"string"},"usage":{"type":"object","properties":{"total_tokens":{"type":"number","nullable":true}}}},"required":["object","data","model","usage"]}}},"paths":{"/v1/embeddings":{"post":{"operationId":"EmbeddingsController_createEmbeddings_v1","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"model":{"enum":["togethercomputer/m2-bert-80M-32k-retrieval"]},"input":{"anyOf":[{"type":"string","minLength":1},{"type":"array","items":{"type":"string"},"minItems":1}],"description":"Input text to embed, encoded as a string or array of tokens."}},"required":["model","input"]}}}},"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Embedding.v1.CreateEmbeddingsResponseDTO"}}}}},"tags":["Embeddings"]}}}}
```

## Code Example

{% tabs %}
{% tab title="Python" %}

<pre class="language-python"><code class="lang-python">import openai
<strong>
</strong># Initialize the API client
client = openai.OpenAI(
    # Insert your AIML API Key instead of &#x3C;YOUR_AIMLAPI_KEY>
    api_key="&#x3C;YOUR_AIMLAPI_KEY>",
    base_url="https://api.aimlapi.com/v1",
)

# Define the text for which to generate an embedding
text = "Laura is a DJ."

# Request the embedding
response = client.embeddings.create(
    input=text,
    model="togethercomputer/m2-bert-80M-32k-retrieval"
)

# Print the embedding
print(response)
</code></pre>

{% endtab %}

{% tab title="JS" %}

```javascript
import OpenAI from "openai";
import util from "util";

// Initialize the API client
const client = new OpenAI({
  // Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>
  apiKey: "<YOUR_AIMLAPI_KEY>",
  baseURL: "https://api.aimlapi.com/v1",
});

// Define the text for which to generate an embedding
const text = "Laura is a DJ.";

const response = await client.embeddings.create({
  input: text,
  model: "togethercomputer/m2-bert-80M-32k-retrieval",
});

// Convert embedding to a regular array (not TypedArray)
const pythonLikeResponse = {
  ...response,
  data: response.data.map(item => ({
    ...item,
    embedding: Array.from(item.embedding),
  })),
};

// Python-like print
console.log(
  util.inspect(pythonLikeResponse, {
    depth: null,
    maxArrayLength: null,
    compact: true,
  })
);
```

{% endtab %}
{% endtabs %}

This example shows how to set up an API client, send text to the embedding API, and print the response with the embedding vector. See how large a vector response the model generates from just a single short input phrase.

<details>

<summary>Response</summary>

{% code overflow="wrap" %}

```json
CreateEmbeddingResponse(data=[Embedding(embedding=[-0.022518871, -0.05492567, 0.04314954, 0.01908204, 0.032154366, 0.018771874, 0.13725114, -0.014640589, 0.0061788796, 0.017178858, -0.030379634, -0.041357648, -0.03360474, 0.042473987, 0.053178973, -0.005236369, -0.03219526, 0.041428592, 0.06592321, 0.0067112693, -0.023770168, -0.019299848, 0.007993773, -0.05168535, -0.015209434, 0.0017797928, -0.07260841, 0.116862014, -0.08432825, 0.041688, 0.001939922, 0.087542035, 0.00027340185, 0.054711558, -0.024200993, -0.031384196, 0.074323244, 0.07123001, 0.023314048, 0.044129774, 0.046673443, -0.017252263, 0.05124588, 0.011533485, 0.11889566, 0.06285429, 0.008315098, 0.025877435, 0.059764042, 0.019463, 0.04239476, -0.03612913, -0.013776412, 0.013890059, 0.103183284, -0.13443822, 0.04495936, -0.009156373, -0.006672909, 0.078052625, -0.09794928, -0.021736462, 0.028952237, -0.041858006, 0.036441904, -0.018249668, 0.045701273, 0.064397104, 0.047778558, -0.04607775, 0.0613175, 0.017838702, 0.059114438, -0.017155133, -0.08712801, -0.15317874, 0.059551563, -0.0060825604, -0.06012979, 7.0648035e-05, -0.0051896097, -0.06964658, -0.007011863, 0.027934607, -0.034792814, -0.026817398, -0.00048898155, -0.062317953, -0.066565625, -0.075289406, -0.0046270085, 0.04413178, -0.063599475, -0.02996869, 0.06441472, -0.06308936, 0.03392907, 0.011777486, -0.04050071, -0.10732842, -0.01925484, -0.020376364, 0.07858302, -0.06894146, 0.039393075, -0.04308492, 0.024917038, -0.0914849, 0.10169439, -0.028998805, 0.046734434, -0.059912268, -0.029643107, 0.011367351, -0.12327092, 0.0052152043, -0.028607994, -0.011932978, -0.043691877, 0.0194266, 0.030180357, 0.12889579, 0.0754103, -0.03970011, 0.07680547, 0.051464014, 0.01168237, -0.05554915, -0.040402085, -0.111259386, -0.07429493, 0.05731342, -0.020595822, 0.043496504, 0.044175837, 0.020880852, 0.012339997, -0.00298804, 0.05948228, -0.0004091635, 0.021892816, 0.009636341, -0.010041086, 0.079659864, -0.039106905, 0.025148746, 0.025120387, 0.08840679, -0.017683662, -0.005038673, 0.05305955, 0.017893763, 0.050628677, 0.070915446, -0.030047618, 0.03086825, -0.002983781, -0.031904973, -0.08130232, 0.00899561, 0.0032726931, -0.040147297, -0.08352723, -0.1173947, 0.15183096, 0.0061662495, 0.03798979, -0.0077478862, -0.028694391, 0.03062653, 0.06121598, -0.060576487, -0.063433364, 0.007295667, -0.073930494, 0.046088267, 0.017132975, 0.04507851, 0.03084464, 0.053483658, 0.034529164, -0.07918834, 0.055112015, 0.01247878, 0.069280356, 0.020827884, 0.042166162, -0.020410769, 0.026415937, -0.10586825, 0.03401086, -0.11206052, 0.022029875, -0.08723038, 0.03311326, -0.013136459, -0.0043826587, 0.08547261, -0.007686176, 0.01795148, -0.033622082, -0.0038820533, -0.07831721, 0.0046814843, 0.07146545, 0.016800385, -0.030045308, 0.025980774, 0.0651566, -0.0034665945, -0.050702367, 0.03332023, -0.04632355, -0.00829293, -0.012228441, 0.044963043, -0.01864288, -0.021899091, 0.047760963, 0.054829728, 0.07316751, 0.029128728, -0.038002785, -0.021813853, -0.012928496, -0.032905307, 0.049185347, 0.048306346, -0.059512895, -0.008473875, -0.10521597, -0.09854483, -0.053533103, 0.0081416285, 0.048627093, 0.086243056, 0.04579295, 0.00020610541, 0.057024997, 0.0045687314, -0.017045287, 0.06937633, -0.018246774, 0.0030933763, -0.047455445, 0.100754544, 0.009138106, -0.06142859, -0.011727202, 0.05943007, 0.019529304, -0.08178414, 0.04293396, 0.008947786, 0.062455736, -0.0044998615, 0.0067285607, -0.0592153, 0.015219912, 0.017413614, -0.015478038, -0.015715232, 0.015510913, 0.08534412, -0.005082124, 0.01736335, -0.021218432, 0.11955415, -0.033334773, 0.09443946, 0.068228334, -0.015644321, -0.005873024, 0.049607933, 0.01715967, 0.03214081, -0.032750327, 0.091966696, 0.032227907, -0.034452155, -0.025407549, -0.040212154, 0.07745749, 0.0054787705, 0.060588814, 0.00085411756, -0.09548096, -0.028679665, -0.016162518, 0.016654978, -0.0083382875, -0.027987378, -0.043397427, 0.09862202, -0.012673832, 0.022648692, -0.026811635, -0.05019208, -0.024081457, -0.039421905, -0.003121619, -0.027325125, -0.023387887, 0.011899437, -0.0043352665, -0.040094543, 0.043613266, 0.054189432, -0.029557189, 0.036127467, -0.016424673, 0.0048351507, -0.03273681, -0.01763599, 0.006455148, 0.027774762, 0.0965571, -0.013099461, 0.10815064, 0.0644431, 0.032897606, -0.02136664, -0.0030217145, 0.054244217, -0.011225383, -0.045582764, 0.011226498, 0.092165194, 0.020423887, -0.011025544, -0.0896547, -0.008121796, 0.025983114, 0.03126251, 0.010954731, -0.078501426, 0.08812612, -0.17783329, 0.079572335, 0.0366609, 0.024194011, -0.058190376, -0.03911377, 0.029253501, -0.006428917, -0.061678503, -0.058610704, -0.024597418, 0.10173387, -0.010054734, 0.042108692, -0.0037493475, 0.038082212, 0.05548489, 0.04893639, 0.00017219223, -0.026868304, 0.059743445, -0.044876374, 0.022350973, -0.0010833307, 0.005143426, -0.032703284, -0.018576814, -0.015566642, -0.032420512, 0.06200163, 0.010864542, -0.020961571, -0.06874651, 0.00077768305, 0.0062362673, 0.029155679, -0.091916256, -0.0015506713, -0.014262802, 0.012104339, -0.06674989, 0.0778559, 0.103922434, 0.059907734, -0.007881259, -0.07194788, -0.06436307, 0.026487429, 0.07824377, 0.084921435, 0.06936699, -0.019934516, -0.02544156, 0.03439074, 0.033536144, -0.071031325, 0.09915472, 0.04934314, 0.01840032, 0.041281283, 0.019535236, -0.03159787, 0.0028999106, 0.045704037, -0.01994819, 0.05776877, 0.054494046, -0.021583393, -0.006835557, -0.016128188, 0.089669, -0.018075528, -0.031506024, 0.10640809, 0.05311536, 0.07978824, -0.028725374, -0.008919856, -0.08879467, 0.08501562, -0.07716739, 0.024608573, 0.088180654, 0.057911232, 0.17356439, -0.062507294, 0.045779735, -0.060949843, 0.0043140682, 0.0014630527, -0.039740812, 0.059488088, -0.10273114, 0.08456389, 0.017332463, 0.09486501, -0.06817094, 0.10525956, -0.018798547, -0.09653561, -0.0130648725, 0.034245886, -0.07156934, -0.03941032, 0.02632053, -0.009588361, -0.04658321, -0.047364846, -0.033951584, -0.04864003, 0.11221384, -0.019882238, -0.08250822, -0.07023993, 0.08075739, -0.04651175, 0.1277658, -0.059738882, 0.008536227, 0.011508066, 0.01578062, -0.0028480047, 0.1062885, -0.06019234, -0.047270287, -0.09146898, 0.074352525, -0.06831037, 0.049275126, -0.05490411, -0.13465248, -0.14108478, -0.038410764, 0.038202513, -0.01447899, 0.124756694, 0.04916432, 0.052207407, -0.05710036, -0.006149548, -0.006929, 0.034152646, 0.057394102, -0.05677231, 0.048502147, 0.004141689, -0.042022724, 0.046504058, 0.06590855, -0.05777849, 0.019975701, -0.024726968, -0.08754647, 0.018082233, 0.061266966, 0.072870076, -0.0778968, 0.074223295, 0.006374571, 0.130426, 0.0226941, 0.0043493654, -0.04955937, 0.0036248127, 0.099575765, -0.088754416, -0.010983745, -0.009471881, -0.036653765, -0.0009121259, 0.10609331, -0.032778006, 0.086380266, -0.04930271, -0.02300316, -0.04129246, -0.008538411, 0.014015781, -0.042881224, -0.047556598, -0.03297384, 0.029435204, -0.0384602, -0.06857866, -0.091861345, 0.07803545, 0.02102974, -0.11948425, 0.024376437, 0.007228921, -0.058134653, -0.0013609343, 0.023084294, -0.057189673, -0.05728298, -0.0484506, -0.0821063, 0.019594098, -0.006331754, -0.059106775, -0.007418993, -0.03072285, 0.060713455, 0.018790137, -0.006208014, 0.079967655, -0.015576144, 0.028650763, -0.002998559, 0.065844886, -0.010050332, 0.0339818, -0.08275663, -0.0031037864, 0.05263937, 0.04846317, 0.05583557, -0.02816636, -0.03598453, 0.019715307, 0.0245313, 0.0009092835, 0.025249347, 0.10045381, -0.045542967, 0.06498728, 0.014768274, -0.04126555, 0.016090501, 0.002490195, 0.09871467, 0.036914844, 0.04130855, -0.03172271, -0.038417645, 0.041601047, -0.051246494, -0.051879317, -0.03654171, -0.0330898, 0.02112689, -0.09168839, 0.035563994, -0.010605103, -0.100304686, 0.10010761, 0.0037157943, 0.07160889, -0.1396608, 0.03641288, -0.017214408, -0.100317664, 0.0062580574, -0.06306692, 0.024881214, -0.04646615, 0.04418978, -0.057057884, -0.081657864, 0.057855934, 0.06479904, 0.09202495, -0.022400219, -0.010139982, -0.03231404, 0.07246991, 0.01929464, -0.07119892, 0.0010536053, 0.049358428, 0.0077756452, 0.036952395, -0.04327241, 0.042407084, 0.03172406, -0.025600178, -0.0673364, 0.0010437515, -0.107536286, -0.04833168, -0.029389678, -0.004706864, 0.031769544, -0.09903898, 0.15186864, 0.07637274, -0.0020486386, 0.046456393, -0.07706689, 0.05339683, 0.03166027, -0.058898803, -0.11018255, 0.014999272, 0.11599336, -0.030609714, -0.022608014, -0.0028181057, 0.008997316, 0.020821538, -0.008648947, 0.030247014, -0.05174877, 0.0006816386, 0.038979083, -0.021107972, -0.05501357, -0.03942976, -0.033877965, -0.049762525, -0.024049241, -0.0596664, 0.025880108, 0.0041145524, -0.050766345, -0.08031096, -0.004088612, -0.053904913, 0.01243612, 0.009684816, 0.05124111, -0.026534285, 0.011635154, 0.05288512, 0.06260319, -0.018155998, -0.027150845, 0.05731768, -0.04091087, 0.080586776, 0.023885174, -0.011623526, 0.06870043, -0.021252401, -0.022097027, -0.07718119, 0.05513044, -0.047646742, -0.012553494, -0.025166888, 0.03182203, -0.021530312, -0.081266604, -0.04483667, -0.0067918906, 0.06554406, 0.0020491984, 0.05770826, 0.013739085, -0.028647613, -0.049964804, -0.026096478, 0.066631645, -0.040899485, -0.009702203, -0.07454616, 0.010306494, -0.029889302, -0.040272836, 0.051952727, -0.01145505, 0.03268713, -0.0093141785, -0.0599903, -0.043513667, 0.056817, 0.04209819, -0.05415263, 0.046982195, 0.050723214, -0.046014734, 0.023149105, 0.029349804, 0.0019439462, 0.011594587, 0.010603982, 0.035190985, 0.041638557, 0.0272645, -0.02095035, 0.067932725, 0.067013115, -0.1120199, 0.028714051, -0.06291958, 0.011970274, 0.042574234, 0.030516073, -0.01871271, -0.064694345, -0.003966169, -0.082643494, 0.06852858, -0.08306689, -0.04162032, -0.0024824948, 0.010162806, 0.016500138, -0.035984974, -0.026145082, -0.060093585, 0.00283806, -0.11145292, 0.018978847, -0.030565565, -0.028125482, -0.0050368947, 0.018238999, -0.027782504, -0.072863534, 0.017784791, -0.03187564, 0.041816197, -0.034067683, 0.020410407, 0.04560171, -0.009920052, -0.012512977, 0.04930977, -0.017679198, 0.049749006, 0.034082506, -0.07823904, 0.035949912, 0.06900245, 0.0141290035, 0.07220982, -0.060865786, 0.00061688427, -0.04459162, 0.045151222], index=0, object='embedding')], model='togethercomputer/m2-bert-80M-32k-retrieval', object='list', usage=None, meta={'usage': {'credits_used': 1}})
```

{% endcode %}

</details>

You can find a more advanced example of using embedding vectors in our article [Find Relevant Answers: Semantic Search with Text Embeddings](https://docs.aimlapi.com/use-cases/find-relevant-answers-semantic-search-with-text-embeddings) in the Use Cases section.