Call the AI Search Open Platform multimodal embedding service to convert text and images into vectors for search and retrieval.
Prerequisites
Before you begin, ensure that you have:
Activated the AI Search Open Platform service. See Activate the service.
An API key for authentication. See Obtain an API key.
SDK version 2.1.0 or later. To install or upgrade, run:
pip install --upgrade alibabacloud_searchplat20240529
Call the multimodal embedding service
The following example calls the multimodal embedding service with a text input.
from alibabacloud_tea_openapi.models import Config
from alibabacloud_searchplat20240529.client import Client
from alibabacloud_searchplat20240529.models import GetMultiModalEmbeddingRequest, GetMultiModalEmbeddingRequestInput
# Configure the client
config = Config(
bearer_token="Replace with your API-KEY",
endpoint="<your-api-endpoint>",
protocol="http"
)
client = Client(config=config)
# Build the request
request = GetMultiModalEmbeddingRequest()
request.from_map({
"input": [
{"text": "Science and technology are the primary productive forces"}
]
})
# Call the service
# "default" is the workspace name; replace "ops-m2-encoder" with another supported service ID if needed
response = client.get_multi_modal_embedding("default", "ops-m2-encoder", request)
print(response)Replace the following placeholders:
| Placeholder | Description |
|---|---|
Replace with your API-KEY | Your API key for authentication |
<your-api-endpoint> | Your API endpoint, without the http:// prefix |
Parameters
The request body must not exceed 8 MB. For the full parameter reference, see Multimodal embedding API reference.