# voyage-2

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

* `voyage-2`
  {% endhint %}
  {% endcolumn %}

{% column width="33.33333333333334%" %} <a href="https://aimlapi.com/app/voyage-2" class="button primary">Try in Playground</a>
{% endcolumn %}
{% endcolumns %}

## Model Overview

A general-purpose embedding model that delivers state-of-the-art performance across multiple domains while maintaining high efficiency. It's optimized for a balance between cost, latency, and retrieval quality.

## 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

{% openapi src="/files/VR35isst6QD3IlJ61nFV" path="/v1/embeddings" method="post" %}
[voyage-2.json](https://3927338786-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FROMd1X5PuqtikJ48n2N9%2Fuploads%2Fgit-blob-23bbcb539d99f68452ffbbe3fadc8e45e4a96dd8%2Fvoyage-2.json?alt=media\&token=342160ba-838f-4fcc-8c14-8ac53a059bf1)
{% endopenapi %}

## Code Example

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

```python
import openai

# Initialize the API client
client = openai.OpenAI(
    # Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>
    api_key="<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="voyage-2"
)

# Print the embedding
print(response)
```

{% 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: "voyage-2",
});

// 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.001198187, 0.049298365, 0.028401304, 0.033417277, -0.055729233, -0.084182143, 0.009030926, 0.020212591, -0.044087704, 0.020462111, 0.003028488, 0.05307113, -0.023698248, -0.006883118, -0.05646202, 0.000945727, 0.015159524, -0.002781284, -0.014497086, -0.043287832, 0.056263112, -0.014664626, -0.012783666, 0.021798261, 0.020149186, -0.00040017, 0.049402509, 0.051637456, -0.012695557, 0.041487299, 0.003978217, 0.011255085, 0.006779575, 0.020875007, 0.057707101, 0.014465009, -0.0040899, -0.05505462, 0.031611055, -0.012716668, -0.051720962, -0.014375405, -0.011334603, -0.015697889, -0.008672391, -0.06338267, 0.010669489, 0.022968747, -0.016906437, 0.01490831, 0.019405564, -0.05475156, 0.040595006, 0.04169935, -0.044304911, 0.018199893, -0.003556291, -0.017475201, -0.012739422, -0.016247479, -0.039491609, -0.035999682, 0.050156876, -0.048853625, -0.000868453, -0.023360942, -0.030231863, -0.066703193, 0.03264508, 0.012832661, -0.010381677, -0.03484907, 0.029493447, 0.006854032, -0.022368258, -0.013598492, -0.008583372, -0.024105456, 0.052614368, 0.0505866, 0.038397592, -0.041998185, -0.028611477, -0.002206625, 0.023181263, -0.003260826, 0.001625487, 0.008019842, -0.030142259, 0.013663144, -0.020966606, 0.018265339, -0.028291998, -0.02990957, 0.011609118, -0.001845041, -0.06387338, 0.008490836, -0.013855136, -0.015574744, -0.047282029, 0.037959184, -0.03569556, 0.062524155, -0.027133711, 0.01506374, -0.037750188, 0.005579574, -0.012883563, 0.008325232, -0.011427139, 0.026454872, 0.025160067, -0.0158771, 0.016693274, 0.04076026, 0.034705047, 0.056452639, -0.03413317, 0.015282825, -0.012572439, -0.000490361, 0.0163908, -0.012331745, -0.052867524, 0.029283743, 0.034171171, 0.007781742, -0.029384607, 0.057016537, -0.007166677, -0.024800241, 0.001211888, -0.047918174, 0.002634328, -0.037601471, 0.004386539, 0.056798857, 0.018685797, 0.006914608, 0.031465914, 0.012414045, -0.009234188, 0.03577866, -0.044168863, 0.029474214, 0.008096647, 0.055801481, -0.045081794, -0.015465318, -0.030047845, -0.014134975, -0.029257005, -0.028774267, 0.010630493, 0.015519386, -0.073758952, -0.027448498, -0.041372832, -0.009664314, 0.015075117, 0.030134693, -0.001441059, 0.035603058, 0.020678909, 0.008900155, 0.038376361, 0.06279625, 0.074670948, 0.003063203, 0.009223592, -0.025492212, -0.032606144, -0.042533465, 0.000810867, -0.017547095, 0.01060733, 0.011103672, -0.0412274, -0.017947676, 0.042320359, -0.024170021, 0.013410355, 0.033199597, -0.068362042, -0.013752396, -0.024007406, 0.037092932, -0.042873118, 0.01801658, 0.111038134, -0.037622288, 0.045559373, 0.013852498, -0.057670511, 0.020490319, 0.012189714, 0.004455179, 0.074316278, -0.014086301, -0.014457034, -0.009707415, 0.007642205, -0.027854297, 0.03253765, -0.010758918, 0.008705751, 0.035408273, -0.032618344, -0.080561377, -0.051747233, -0.028979629, -0.025693705, 0.04295193, -0.043374151, -0.03633628, 0.016753441, -0.053659424, 0.055474028, 0.037140079, 0.009594706, 0.010742909, 0.007659789, 0.024168789, -0.036221754, -0.014885176, 0.009512373, -0.012258912, 0.034117222, 0.034771662, 0.021216067, -0.024904449, -0.028171899, -0.00211362, 0.036748119, 0.017063066, -0.026057636, -0.020205554, -0.006556953, -0.008266491, -0.042868428, -0.03359367, 0.023219263, 0.030353839, -0.001692925, 0.021424126, 0.052400269, 0.062402181, 0.023540854, -0.028841354, 0.009650298, 0.032100182, -0.061093774, -0.007988648, -0.046846673, -0.037809297, -0.041549794, -0.033368487, 0.026495688, 0.064340636, 0.006349597, -0.012879575, 0.005167323, 0.015456961, 0.018827124, 0.011481295, 0.049941074, 0.003177525, -0.002744545, -0.053687572, -0.031027278, 0.022542305, -0.046837293, 0.019902494, 0.009571601, -0.034680944, 0.030735712, -0.014235837, 0.026802033, 0.042081222, 0.017979285, 0.033056982, 0.034685813, -0.028054148, 0.02453999, 0.044428762, 0.016298991, 0.023881679, 0.037066542, -0.001603614, -0.025365546, -0.01015834, 0.017794563, -0.029792756, -0.031316496, -0.000106845, -0.027813951, -0.014794107, 0.035539635, 0.002560381, -0.039581683, 0.030089246, 0.064851053, 0.021562288, 0.03165615, 0.000671329, -0.056645922, -0.026960129, 0.0125798, 0.015448488, -0.045676656, -0.014852514, -0.000891089, -0.009705304, 0.018401738, 0.004213195, -0.00807322, -0.030693488, 0.025196658, -0.050657436, 0.049876332, 0.02019453, -0.003393473, -0.035453312, -0.030501613, -0.020382592, 0.001321782, -0.014364615, 0.030947877, 0.001873482, -0.020154418, 0.015497336, 0.01416195, 0.021376979, -0.046149544, 0.041279003, 0.011299828, -0.028830094, -0.04904503, 0.056102667, -0.042783044, 0.035157289, -0.001227765, 0.009589897, -0.029410413, 0.008694381, -0.028968956, -0.036708008, -0.017044771, -0.025001032, -0.05728535, 0.009724069, 0.056744438, 0.023171647, 0.009714453, 0.021230141, -0.003341692, 0.026751366, -0.037849642, 0.051792271, 0.032075085, -0.047360372, 0.044511329, 0.015381673, -0.032888092, -0.022994079, 0.031133534, 0.005668767, 0.028056258, -0.021261925, 0.020336676, -0.004678897, -0.005449741, -0.004163554, -0.016482633, -0.019186245, -0.017180821, -0.00584695, -0.01140462, 0.055605382, -0.030624058, 0.036248025, -0.024241505, 0.002355047, 0.017398732, -0.036150444, -0.006220702, -0.046372849, 0.071542069, 0.008601004, -0.012999673, -0.005422472, 0.020756902, 0.024100296, -0.025406362, -0.028843816, 0.012709749, 0.027977442, 0.046310924, -0.043083761, -0.049864605, 0.006494969, 0.063335761, -0.04888881, -0.015992271, 0.028869968, 0.041111995, 0.022951858, -0.005264258, 0.019293355, -0.026273319, 0.044486932, -0.045276251, -0.028733453, 0.02591021, 0.000789903, -0.033494212, -0.068667918, -0.006247091, -0.016508318, 0.067724027, 0.010342973, 0.033561062, -0.006759091, 0.035951063, 0.0029429, 0.004145493, 0.020242205, -0.013639805, 0.020355793, -0.006030703, 0.022007728, -0.060298592, 0.018501194, -0.04678164, -0.059775036, 0.052164763, 0.049945764, -0.070929147, 0.033176377, -0.01071652, -0.046087615, 0.000207357, -0.026349554, 0.008776128, 0.017910557, 0.008822279, -0.023125907, 0.020568194, -0.015138098, 0.054378603, -0.020249769, -0.001507119, -0.023981135, 0.016336849, 0.046181444, 0.021443479, -0.056840144, 0.038629342, -0.050983489, -0.021071339, -0.00819669, 0.018861312, 0.001533647, -0.028306542, 0.035877876, 0.029374287, -0.012802461, 0.006991253, -0.050845794, 0.020390628, 0.062131021, 0.046376601, -0.009326362, -0.018890018, -0.045002982, -0.010183878, 0.014379334, 0.006753109, 0.00150662, -0.01997697, -0.000915337, -0.051079661, 0.004644298, 0.033421028, -0.033661224, -0.020539341, 0.030257197, 0.023084564, 0.031480696, -0.023011556, -0.019763367, 0.00390647, -0.020147938, -0.044338778, -0.048264861, -0.020901278, 0.009093144, 0.000939571, 0.023906544, -0.037469644, -0.032407936, 0.004809305, -0.001218925, 0.008487083, -0.002607206, -0.005626663, 0.024581626, 0.048285972, 0.004967473, -0.011110298, -0.047326129, 0.008415775, 0.07554283, -0.036838192, -0.003563299, 0.005138149, 0.00033197, -1.642e-05, -0.017634822, -0.014135562, -0.005822577, -0.042806499, 0.011845444, -0.049168881, -0.049296487, 0.000836464, 0.032443121, 0.026292086, -0.002519361, 0.026468949, -0.034626935, 0.005885272, 0.041636012, -0.002305085, 0.039814372, -0.012699896, -0.033670604, -0.01011691, 0.03670308, -0.035867088, -0.032834142, 0.044672709, -0.030727267, 0.02278121, 0.043229658, -0.043266486, -0.007680776, 0.024949661, -0.007461349, 0.1018769, 0.02559589, 0.024503808, -0.007787137, 0.040750761, 0.024837773, 0.026692722, 0.021341208, -0.057050318, -0.067151688, -0.003955728, 0.037419621, 0.007050972, -0.019158214, -0.038086083, 0.014505999, -0.028884513, -0.01822646, -0.010033023, 0.002201113, 0.010153737, 0.01152642, 0.016746109, -0.030719763, -0.001128294, -0.025997939, 0.042394605, 0.036704957, 0.041804433, 0.010647382, -0.022103431, -0.011162548, 0.062351517, -0.017835846, -0.033536434, -0.019252276, -0.02370036, 0.012110666, 0.052288614, 0.046012554, -0.053005449, 0.018220887, -0.009672582, 0.015586003, -0.003894624, -0.026198374, 0.018198017, -0.034109715, 0.003874041, -0.020770391, 0.016139345, 0.077196755, -0.010634129, 0.024236344, -0.015169119, 0.007839225, -0.032728001, -0.021668486, 0.02657339, -0.011413066, -0.028288949, -0.069546141, 0.007378625, 0.061276264, 0.001069004, -0.001435547, 0.013964181, 0.004753841, -0.020541921, 0.019881148, -0.009817544, 0.065479696, 0.00187055, 0.025630606, -0.024382245, 0.047288597, -0.001380908, -0.026860792, -0.01333956, -0.066286601, 0.00460583, 0.018205876, 0.002730852, -0.04935278, 0.016408391, -0.036551084, -0.023739342, 0.003795344, 0.011441624, 0.047080301, -0.022063555, 0.021539534, 0.016991876, 0.049174514, -0.019283533, 0.00505608, 0.034415122, 0.052903183, -0.036925919, 0.006959001, -0.001904914, 0.013772085, 0.020490082, 0.001032737, 0.045907937, 0.008717896, 0.035887729, 0.014888461, -0.014279115, -0.030578669, -0.021089165, -0.038909648, -0.007627324, 0.037595373, -0.042227592, 0.026331492, 0.008276765, -0.017613595, 0.033929568, -0.013962802, -0.07381431, -0.012064852, 0.018816451, -0.034075938, 0.031557865, -0.00180839, 0.031200154, -0.010580256, -0.002180412, -0.025208388, 0.025697224, -0.069080763, -0.035107091, -0.002558651, -0.008835532, 0.019562021, 0.029720509, -0.025191968, -0.016871661, -0.050041467, 0.002145755, 0.014632021, 0.029755928, 0.058864921, 0.046310924, -0.031594224, -0.044469107, -0.004312387, -0.084256269, 0.008796799, 0.010890921, 0.032170318, 0.07207007, -0.007934738, 0.014277004, -0.007730782, -0.026402801, -0.054509487, 0.006831118, -0.021223808, 0.008280489, -0.037382387, -0.028521404, -0.005341547, -0.018981585, -0.030643761, 0.019130725, 0.01587452, -0.023169771, 0.001345356, -0.006646352, 0.01316214, 0.035917755, -0.003329847, 0.01666313, 0.028536886, 0.032537185, -0.013834091, -0.021125523, 0.023532176, 0.013589021, -0.002929852, 0.023386275, 0.026110062, -0.020951474, -0.02376557, -0.019592045, 0.022843722, 0.011371606, 0.024481613, -0.02173868, 0.03051991, -0.031910889, 0.02027097, -0.014543589, 0.010243048, -0.020591535, -0.019456349, -0.052799586, 0.023783132, -0.021841655, 0.030468306, -0.008422167, -0.044297405, 0.003326152, -0.007173145, -0.020910075, 0.007811004, -0.00558192, -0.05133862, 0.047784001, -0.013194891, -0.018419446, 0.007394414, 0.00563455, -0.009235966, 0.046325937, 0.072061628, -0.010620466, -0.00684421, 0.037040859, 0.003614904, 0.006193903, -0.036946565, -0.042912524, 0.011873901, 0.013172841, -0.018089531, -0.061097525, 0.01953575, 0.002754902, -0.008945778, 0.01756246, 0.037157673, 0.010929624, -0.024050567, 0.008153808, 0.000359414, -0.032816783, 0.006732204, 0.015253856, -0.02360067, -0.01540996, -0.001822347, -0.002970901, 0.031182766, 0.039972, -0.02613985, -0.016019978, -0.008500776, 0.005331813, -0.006966447, 0.063030824, -0.015405211, 0.067567334, 0.029796975, 0.012576163, 0.007712076, -0.014417158, -0.021775039, -0.079656892, -0.005570426, -0.04779432, -0.010504267, 0.027108375, -0.047799483, -0.031130252, -0.001412559, 0.004513233, 0.014160542, -0.002898244, -0.022762798, -0.005124104, 0.016394436, 0.047179759, -0.033995718, 0.028233824, 0.014835213, 0.060594611, -0.032285728, 0.013866571, 0.017348887, -0.001160977, 0.030316073, -0.019644566, -0.022284752, 0.003982704, -0.009029635, -0.02066718, 0.054605901, -0.057648927, -0.029727075, -0.006310611, 0.054903563, 0.018591503, 0.0281658, -0.019154051, -0.004671508, -0.005608073, 0.025439203, 0.021644736, 0.012108027, -0.027437473, -0.060576085, 0.001439886, -0.033617124, 0.018243626, -0.045216907, -0.038642127, 0.007292671, -0.031046277, 0.013207615, -0.002650014, 0.079817332, -0.002122357, -0.023477288, 0.038829193, 0.038136754, -0.001622613, -0.008799115, -0.045834284, 0.066615, 0.007536034, 0.010009361, -0.005835293, -0.044623919, 0.027115414, 0.002192199, -0.012442739, -0.020488206, 0.027835766, 0.054031912, 0.005859609, 0.015641594, 0.012093074, -0.000808697, 0.029878605, -0.0101769, 0.043032624, 0.020055901, 0.014631434, 0.013278337, -0.02434741, -0.044821426, 0.05095534, -0.045242239, -0.03200331, -0.071131811, -0.014987388, 0.051412273, 0.039191362, -0.015005245, 0.058662258, 0.097095497, -0.004294912, -0.023883555, 0.059157658, 0.044377156, -0.020791268, 0.008307171, 0.001214351, -0.047954295, 0.029213376, -0.001246076, 0.021353288, -0.023426151, -0.042853884, -0.001466099, -0.009750165, 0.029869221, 0.0104385, -0.013709236, -0.049293905, -0.027357016, 0.000779464, 0.023469752, -0.016103925, 0.023613336, -0.011284523, -0.009527368, 0.0199256, -0.009235673, 0.052150693, 0.024881754, -0.006957476, -0.01268418, 0.020077949, 0.000591518, -0.005343834, -0.038358182, -0.020031506, 0.00576881, 0.065021113, -0.000830483, 0.020983053, -0.019768322, -0.005942858, -0.014661136, 0.047065292, -0.046664651, 0.01606355, 0.003663107, 0.019157277, 0.001670875, 0.009432152, -0.019699829, 0.000812069, -0.020781415, 0.043960098, -0.036490213, -0.001900142, 0.069007576, -0.029250436, 0.022790007, 0.030682934, 0.033113278, -0.022603409, -0.05646484, -0.055204391, 0.053308509, -0.007725505, -0.03162894, 0.043842345, -0.000238001, -0.024620095, -0.054692451, -0.010728138, 0.01129768, -0.00904629, -0.000388691, -0.081198901, 0.010880013, 0.012378013, 0.015225504, 0.028770156, 0.000204425, 0.001689113, -0.01323201, 0.04179411, 0.014519195, -0.03950005, 0.00101708, 0.013799838, 0.028874896, 0.054830141, 0.021270955, -0.025956186, 0.02234723, -0.024981562, 0.017288486, -0.02723592, 0.014630379, 0.009001604, -0.000573273, 0.028385591, -0.001617805, 0.051975001, -0.029455917, -0.029072165, -0.044029061, 0.017682206, -0.054965485, 0.031072548, -0.018017517, 0.002065328, 0.005563154, 0.012502041, -0.021870976, 0.000447172, 0.050289638, 0.002705959, -0.027021587, -0.066585906, -0.060553797], index=0, object='embedding')], model='voyage-2', object='list', usage=Usage(prompt_tokens=None, total_tokens=6))
```

{% endcode %}

</details>

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aimlapi.com/api-references/embedding-models/anthropic/voyage-2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
