# Upsert Vectors

> Upserts (inserts or updates) the vector.

<Tip>
  The vector will be upserted into the default namespace by default.
  You can use a different namespace by specifying it in the request path.
</Tip>

## Request

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

<ParamField body="id" type="string" required>
  The id of the vector.
</ParamField>
<ParamField body="vector" type="number[]">
  The dense vector value for dense and hybrid indexes.
  <Note>The vector should have the same dimensions as your index.</Note>
</ParamField>
<ParamField body="sparseVector" type="Object[]">
  The sparse vector value for sparse and hybrid indexes.
  <Expandable defaultOpen="true">
    <ResponseField name="indices" type="number[]">
      Indices of the non-zero valued dimensions.
    </ResponseField>
    <ResponseField name="values" type="number[]">
      Values of the non-zero valued dimensions.
    </ResponseField>
  </Expandable>
</ParamField>
<ParamField body="metadata" type="Object">
  The metadata of the vector. This makes identifying vectors
  on retrieval easier and can be used to with filters on queries.
</ParamField>
<ParamField body="data" type="string">
  The data of the vector. This is an unstructured raw text
  data, which can be anything associated with this vector.
</ParamField>

<Note>
For dense indexes, only `vector` should be provided, and `sparseVector` should not be set.

For sparse indexes, only `sparseVector` should be provided, and `vector` should not be set.

For hybrid indexes both of `vector` and `sparseVector` must be present.
</Note>

## Path

<ParamField path="namespace" type="string" default="">
  The namespace to use.
  When no namespace is specified, the default namespace will be used.
</ParamField>

## Response

<ResponseField name="result" type="string">
  `"Success"` string.
</ResponseField>

<RequestExample>

```sh curl
curl $UPSTASH_VECTOR_REST_URL/upsert \
  -X POST \
  -H "Authorization: Bearer $UPSTASH_VECTOR_REST_TOKEN" \
  -d '[ 
    { "id": "id-0", "vector": [0.1, 0.2], "metadata": { "link": "upstash.com" } }, 
    { "id": "id-1", "vector": [0.2, 0.3] }
  ]'
```

```sh curl (Namespace)
curl $UPSTASH_VECTOR_REST_URL/upsert/ns \
  -X POST \
  -H "Authorization: Bearer $UPSTASH_VECTOR_REST_TOKEN" \
  -d '{ "id": "id-2", "vector": [0.1, 0.2], "metadata": { "link": "upstash.com" } }'
```

</RequestExample>

<ResponseExample>

```json 200 OK
{
    "result": "Success"
}
```

```json 422 Unprocessable Entity
{
    "error": "Invalid vector dimension: 2, expected: 256",
    "status": 422
}
```

</ResponseExample>
