Upsert Vectors

Vectors can be inserted or updated in a table by listing them in the vectors parameter of the upsert vectors operation.

You can include the dimension values of each vector using the dense_vector field of the vectors parameter.

See the following for an example of upserting pre-computed vectors:

from oracle_vecdb import OracleVecDB, Configuration

client = OracleVecDB(Configuration(
    rest_url="https://<host>/ords/<schema>/_/db-api/stable/vecdb/",
    access_token="<bearer-token>", # or username="<user>", password="<pass>"
))

ups_vec_response = client.upsert_vectors(
    table_name='products',
    vectors=[
        {
            'id': 'prod_1',
            'dense_vector': [0.1, 0.2, 0.3, 0.4, 0.5],
            'metadata': {
                'name': 'Wireless Headphones',
                'category': 'electronics',
                'price': 99.99
            }
        },
        {
            'id': 'prod_2',
            'dense_vector': [0.2, 0.3, 0.1, 0.5, 0.4],
            'metadata': {
                'name': 'Smart Watch',
                'category': 'electronics',
                'price': 199.99
            }
        }
    ]
)
print(ups_vec_response)

If the table is configured with auto_generate_id set to true, then you don't need to provide id as part of the upsert object.

A JSON response is returned confirming successful upsert with a count of inserted and updated vectors.

Example response:

{
    "upserted_count": 10
}

For more information about the upsert_vectors operation, see Python API Reference.

See the following example of upserting vectors using POST /vecdb/vector-tables/{vector_table_name}/upsert:

curl -X POST \
  "https://<host>:<port>/ords/<schema>/_/db-api/stable/vecdb/vector-tables/sample_table/upsert" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  # Choose ONE authentication method:

  # Option 1: Basic authentication
  -u "<user>:<password>" \

  # Option 2: OAuth Bearer token
  # -H "Authorization: Bearer <access_token>" \

  -d '{
    "vectors": [
      {
        "id": "vec1",
        "dense_vector": [0.1, 0.5, 0.4, 0.56],
        "metadata": {
          "type": "document",
          "source": "Wikipedia"
        }
      },
      {
        "id": "vec2",
        "dense_vector": [0.14, 0.534, 0.12, 0.58],
        "metadata": {
          "type": "document",
          "source": "Internal"
        }
      }
    ]
  }'

Responses:

  • Example 201 response:

    {
      "upserted_count": 2
    }
  • 400 - the request body included invalid parameters.
  • 404 - the specified vector table does not exist.

For more information about POST /vecdb/vector-tables/{vector_table_name}/upsert, see REST API Reference.

See how DBMS_VECTOR_DATABASE.UPSERT_VECTORS can be used in the following example:

dbms_vector_database.upsert_vectors(
    'sample_table',
    vectors => JSON('[
      {
        "id": "vec1",
        "dense_vector": [0.1, 0.5, 0.4, 0.56],
        "metadata": {"type": "document", "source": "Wikipedia"}
      },
      {
        "id": "vec2",
        "dense_vector": [0.14, 0.534, 0.12, 0.58],
        "metadata": {"type": "document", "source": "Internal"}
      }
    ]')
);
Example response:
{
  "upserted_count": 2
}

For more information and parameters, see UPSERT_VECTORS.