Embed Data
Use the generate_embedding operation to generate embeddings (vector representation) for provided inputs using a specified embedding model.
This operation converts text into dense vector representations using the
specified embedding model. Ensure to load the model in the database using Load Your Own ONNX Model before initiating generate_embedding operation. Loading the
model is a one-time operation; you do not need to reload it every time while using
generate_embedding operation to generate embeddings.
Note:
This operation runs the loaded embedding model within Oracle AI Database and consumes database CPU resources. Large inputs, large batches, or frequent calls can affect database workload performance. For embedding-heavy workloads, consider using OCI Generative AI to generate embeddings externally.See the following for an example of how to use the
generate_embedding operation to generate embeddings.
from oracle_vecdb import OracleVecDB, Configuration
client.load_model(
model_name="all-MiniLM-L6-v2",
url="https://objectstorage.example.com/bucket/all-MiniLM-L6-v2.onnx",
)
embeddings = client.generate_embedding(
model_name="all-MiniLM-L6-v2",
inputs=[
"Wireless noise-cancelling headphones",
"Ergonomic office chair with lumbar support",
],
)
print(embeddings.to_dict()["data"][0]["embedding"])A JSON response is returned containing generated embeddings, an array of vectors corresponding to each input. An error is raised if the model is not loaded or if inputs are invalid.
Example response:
{
"data": [
{
"text": "Sample text to embed",
"embedding": [
0.0117027815,
0.00419755466,
-0.0301191173,
0.011317092,
0.0763486549
]
}
]
}For more information about the generate_embedding
operation, see Python API Reference.
POST /vecdb/embed can be used in the
following
example:curl -X POST \
"https://<host>:<port>/ords/<schema>/_/db-api/stable/vecdb/embed" \
-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 '{
"modelName": "DOC_EMBED_MODEL",
"inputs": [
{"text": "hello world"}
]
}'Responses:
-
Example 200 response:
{ "data": [ { "text": "hello world", "embedding": [ 0.0117027815, 0.00419755466, -0.0301191173, 0.011317092 ] } ] } - 400 - the request body included invalid parameters.
For more information about POST /vecdb/embed, see
REST API Reference.
See how DBMS_VECTOR_DATABASE.GENERATE_EMBEDDING can
be used in the following example:
dbms_vector_database.generate_embedding(
model_name => 'DOC_EMBED_MODEL',
inputs => SYS.JSON_ARRAY_T('[{"text": "hello world"}]')
);Example output:
{
"data": [
{
"text": "hello world",
"embedding": [
0.0117027815,
0.00419755466,
-0.0301191173,
0.011317092
]
}
]
}For information about the PL/SQL implementation, including parameters, see GENERATE_EMBEDDING.