generate_embedding

Use the generate embedding operation to generate embeddings for provided inputs using a specified embedding model.

Converts text into dense vector representations using the specified embedding model. The model must be loaded in the database using load_model() first.

Loading the model is a one-time operation. You do not need to reload it every time you use generate_embedding to generate embeddings.

Performance consideration: 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.

Parameters

Parameter Type Value Range Required Default Description Notes
model_name str Valid model identifier Yes No default Name of the loaded embedding model to use. Model must exist in the database schema.
inputs list[str or dict] Non-empty array Yes No default List of text inputs to embed. The value can be a list of strings or a list of dictionaries with a text field. Each dictionary input must include text; an empty list is invalid.
debug_flags dict Object or NULL No None Debug or tracing flags for detailed logging. Optional; omit unless diagnostics are needed.

Raises Exception – InvalidModelNameFormatError may be raised when the model name is invalid. The operation can also fail if the model is not loaded or inputs are invalid.

Load a model, generate embeddings, and inspect the response

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"])

Return type EmbeddingResponse

Returns Example response:

{
    "data": [
        {
            "text": "Sample text to embed",
            "embedding": [
                0.0117027815,
                0.00419755466,
                -0.0301191173,
                0.011317092,
                0.0763486549
            ]
        }
    ]
}