> ## Documentation Index
> Fetch the complete documentation index at: https://upstash-qstashminimalrightbar.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Upsert Vectors

> This endpoint upserts (adds) a vector to given index. You can also add metadata with the vector.

## Request

You can either upsert a single vector, or multiple vectors in a array.

<ParamField body="id" type="string" required>
  The ID of the vector
</ParamField>

<ParamField body="vector" type="number[]" required>
  The vector data to upsert.

  <Note>
    The provided vector should have the same number of dimensions as your index.
  </Note>
</ParamField>

<ParamField body="metadata" type="Object">
  The metadata of the vector. This is used to make it easier to identify the
  vector on queries.
</ParamField>

## Response

<ResponseField name="Response" type="Object">
  Returns `"Success"` on successful upsert operation.
</ResponseField>

<RequestExample>
  ```sh curl
  curl https://better-dodo-20522-us1-vector.upstash.io/upsert \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -d '{"id": "id10",
    "vector": [0.44,0.8,0.05,0.72,0.83,0.49,0.6,0.48],
    "metadata": { "key": "value" } }'
  ```

  ```js Node
  const url = "https://better-dodo-20522-us1-vector.upstash.io/upsert"; // Replace with your index endpoint.
  const token = "YOUR_TOKEN"; // Replace with your actual token
  const data = {
    id: "id10",
    vector: [0.44, 0.8, 0.05, 0.72, 0.83, 0.49, 0.6, 0.48],
    metadata: { key: "value" },
  };

  fetch(url, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${token}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify(data),
  })
    .then((response) => response.json())
    .then((data) => console.log(data))
    .catch((error) => console.error("Error:", error));
  ```

  ```python Python
  import requests
  import json

  url = 'https://better-dodo-20522-us1-vector.upstash.io/upsert' # Replace with your index endpoint.
  token = 'YOUR_TOKEN' # Replace with your actual token
  headers = {
      'Authorization': f'Bearer {token}',
      'Content-Type': 'application/json'
  }
  data = {
      'id': 'id10',
      'vector': [0.44, 0.8, 0.05, 0.72, 0.83, 0.49, 0.6, 0.48],
      'metadata': {'key': 'value'}
  }

  response = requests.post(url, headers=headers, data=json.dumps(data))
  print(response.json())
  ```
</RequestExample>

<ResponseExample>
  ```json 200 OK
  {
    "result" : "Success"
  }
  ```

  ```json 422 Unsuccessful
  {
    "error": "Invalid vector dimension: 2, expected: 256",
    "status": 422
  }
  ```
</ResponseExample>
