Upsert Text
For tables with embedding models, text can be upserted using the
metadata field of the vectors parameter of the
upsert vectors operation.
For tables with integrated embedding models, you can provide text in the
metadata field as one of the values, with
embed_metadata_jsonpath configured upon table creation as the
key. Vector embeddings will be generated automatically.
See Create a Vector Table for more information about using the embed_params parameter to
configure the table for automatic embedding generation.
See the following for an example of upserting text into a table with
automatic embedding using upsert_vectors. In this example, the
table was created with the embed_params parameter configured
with "embed_metadata_jsonpath" : "content", so that any text
provided in the content field will be auto-embedded.
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_text_response = client.upsert_vectors(
table_name='documents',
vectors=[
{
'id': 'doc_1',
'metadata': {
'content': 'Machine learning is transforming healthcare',
'category': 'AI',
'author': 'John Doe'
}
},
{
'id': 'doc_2',
'metadata': {
'content': 'Vector databases enable semantic search',
'category': 'Database',
'author': 'Jane Smith'
}
}
]
)
print(ups_text_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 text using POST
/vecdb/vector-tables/{vector_table_name}/upsert:
curl -X POST \
"https://<host>:<port>/ords/<schema>/_/db-api/stable/vecdb/vector-tables/products/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": "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
}
}
]
}'-
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.
For information about the PL/SQL implementation, including parameters, see UPSERT_VECTORS.