# Upsert data into an AI Search index

Launch stage: Public Preview

`POST /api/2.0/ai-search/{name=workspaces/*/endpoints/*/indexes/*}:upsertData`

Upsert rows into a Direct Access AI Search index.

API scopes: ai-search

## Path parameters

- `name` (string, required)
  Full resource name of the index. Must be a Direct Access index.
   Format: `workspaces/{workspace_id}/endpoints/{endpoint_id}/indexes/{index_id}`

## Request body

- `inputs_json` (string, required)
  JSON array of the rows to insert or update, serialized as a string. Each element is an object
   that maps column names to values and must include the primary key column; vector columns are
   given as arrays of numbers. A row whose primary key already exists is overwritten. The array
   must not be empty.

## Returns

- `status` (string, optional, Output only)
  Overall status of the upsert: `SUCCESS` when every row was written, `PARTIAL_SUCCESS` when
   some rows failed (see `result.failed_primary_keys`), or `FAILURE` when the operation failed.
  Possible values:
  - `SUCCESS`
  - `PARTIAL_SUCCESS`
  - `FAILURE`
- `result` (object, optional, Output only)
  Per-row outcome of the upsert.
  - `success_row_count` (int64, optional, Output only)
    Count of rows processed successfully.
  - `failed_primary_keys` (array of string, optional, Output only)
    Primary keys of rows that failed to process.

## Request

### Upsert two rows

```json
{
  "inputs_json": "[{\"id\": 101, \"question\": \"How do I reset my password?\", \"answer\": \"Open Settings, choose Security, and select Reset password.\", \"answer_vector\": [0.12, 0.47, -0.08]}, {\"id\": 102, \"question\": \"Where can I download invoices?\", \"answer\": \"Invoices are listed under Billing in the account console.\", \"answer_vector\": [0.31, -0.22, 0.05]}]"
}
```

## Response

### All rows written

```json
{
  "status": "SUCCESS",
  "result": {
    "success_row_count": 2
  }
}
```

