Tous les produits
Search
Centre de documentation

Vector Retrieval Service for Milvus:Extraction de mots-clés

Dernière mise à jour :Sep 14, 2026

AI_KEYWORDS est une fonction d'IA intégrée à Alibaba Cloud Milvus qui extrait des mots-clés représentatifs à partir de textes, d'images ou de vidéos. Utilisez-la pour l'indexation de recherche, le marquage d'articles et la récupération d'actifs multilingues.

Syntaxe de la commande

AI_KEYWORDS prend en charge deux modes d'appel :

  • API REST — Appelez directement l'endpoint pour extraire des mots-clés à la demande à partir de textes, d'images ou de vidéos.

  • Fonction de collection — Intégrez l'extraction de mots-clés dans le schéma d'une collection afin que les mots-clés soient automatiquement extraits lors de l'insertion des données.

API REST

@id="cmdtabbkwd001"

API REST

Envoyez une requête POST vers l'endpoint AI keywords :

@id="c0058k7q2t58"

POST /v2/vectordb/ai/keywords
Content-Type: application/json

{
  "model_name": "<model_name>",
  "texts": ["<text_or_media_url>"],
  "params": {"max_keywords": 10, "target_language": "zh"}
}

@id="cmdrestskwd01"

@id="cmdresthkwd01"

Fonction de collection (SDK Python)

@id="cmdpyseckwd01"

Fonction de collection (SDK Python)

Définissez l'extraction de mots-clés comme une fonction de collection dans le schéma. La fonction se déclenche automatiquement lors de l'insertion et écrit les résultats dans le champ de sortie spécifié :

@id="cmdpycodkwd01"

schema = MilvusClient.create_schema(auto_id=True, enable_dynamic_field=False)
schema.add_field("id", DataType.INT64, is_primary=True)
schema.add_field("content", DataType.VARCHAR, max_length=8192)
schema.add_field("keywords", DataType.JSON)
schema.add_field("dummy_vector", DataType.FLOAT_VECTOR, dim=2)
schema.add_function(
    Function(
        name="extract_keywords",
        function_type=texttransform_function_type(),
        input_field_names=["content"],
        output_field_names=["keywords"],
        params={
            "provider": "aliyun_milvus",
            "model_name": "<model_name>",
            "task": "ai_keywords",
            "max_keywords": "5",
            "target_language": "en",
            "temperature": "0",
        },
    )
)

@id="cmdpyhkwd0001"

Paramètres

@id="p0065k7q2t65" Paramètre @id="p0067k7q2t67" Description
@id="p0003k7q2t03" model_name @id="p0005k7q2t05" Obligatoire. Nom du modèle. Pour les images ou les vidéos, utilisez un modèle multimodal configuré (par exemple, qwen3.7-plus).
@id="p0008k7q2t08" texts @id="p0010k7q2t10" Obligatoire pour l'API REST. Contenu textuel à traiter ou URL pointant vers une image ou une vidéo.
@id="p0013k7q2t13" max_keywords @id="p0015k7q2t15" Facultatif. Nombre maximal de mots-clés à extraire. Valeur par défaut : 10. Plage valide : 1–50.
@id="p0018k7q2t18" target_language @id="p0020k7q2t20" Facultatif. Langue des mots-clés en sortie. Par défaut, la langue d'entrée est utilisée. Valeurs prises en charge : zh, en, es, fr, de, ja, ko, ru, ar et pt.
@id="p0023k7q2t23" prompt @id="p0025k7q2t25" Facultatif. Règles d'extraction supplémentaires, jusqu'à 5 000 caractères. Ne prend pas en charge l'interpolation de variables de modèle ${...}.
@id="p0028k7q2t28" media_type @id="p0030k7q2t30" Facultatif. Valeurs valides : image ou video.
@id="p0033k7q2t33" temperature/max_concurrency/timeout_sec @id="p0035k7q2t35" Facultatif. Paramètres de stabilité du modèle, de concurrence et de délai d'expiration.
@id="p0038k7q2t38" provider/task @id="p0040k7q2t40" Obligatoire uniquement pour la fonction de collection. Fixé respectivement à aliyun_milvus et ai_keywords.

Valeurs de retour

Chaque élément de sortie est une chaîne JSON au format {"keywords":["keyword 1","keyword 2"]}. Lorsque AI_KEYWORDS est utilisé comme fonction de collection, le schéma analyse automatiquement ce résultat et l'écrit dans le champ de sortie JSON.

Exemple 1 : Marquage automatique d'articles techniques avec des mots-clés (texte)

Une base de connaissances doit écrire les mots-clés des articles dans un champ d'index pour permettre le filtrage et l'agrégation.

API REST

@id="tab0074k7q2t74"

API REST

@id="c0077k7q2t77"

#!/usr/bin/env bash
set -euo pipefail

MILVUS_REST_BASE_URL="http://c-xxxx.milvus.aliyuncs.com:19530"
MILVUS_AUTH_TOKEN="<yourUsername>:<yourPassword>"

post_json() {
  local path="$1"
  local body="$2"
  curl -X POST \
    "$MILVUS_REST_BASE_URL$path" \
    -H "Authorization: Bearer $MILVUS_AUTH_TOKEN" \
    -H "Content-Type: application/json" \
    -d "$body"
}

BODY=$(cat <<JSON
{
  "model_name": "qwen3.7-max",
  "texts": ["Milvus is an open-source vector database for high-performance approximate nearest neighbor search in RAG, recommendation, and image search."],
  "params": {"max_keywords": 5, "target_language": "en", "temperature": 0}
}
JSON
)
RESPONSE_BODY="$(post_json "/v2/vectordb/ai/keywords" "$BODY")"
if command -v jq >/dev/null 2>&1; then
  echo "$RESPONSE_BODY" | jq .
  [ "$(echo "$RESPONSE_BODY" | jq -r '.code // -1')" = "0" ] || exit 1
else
  echo "$RESPONSE_BODY"
fi

@id="rt0075k7q2t75"

@id="h0076k7q2t76"

Python (Fonction de collection)

@id="pt0078k7q2t78"

Python (Fonction de collection)

L'exemple suivant utilise des fonctions utilitaires partagées (texttransform_function_type et run_texttransform_example) qui gèrent la création du schéma, l'enregistrement de la fonction, l'insertion des données et l'interrogation des résultats. Les exemples 2 et 3 réutilisent ces mêmes utilitaires.

@id="c0080k7q2t80"

from __future__ import annotations

from typing import Any

from pymilvus import DataType, Function, FunctionType, MilvusClient

MILVUS_URI = "http://c-xxxx.milvus.aliyuncs.com:19530"
MILVUS_TOKEN = "<yourUsername>:<yourPassword>"

DUMMY_VECTOR_DIM = 2
TEXTTRANSFORM_FUNCTION_TYPE = 9

def texttransform_function_type() -> Any:
    for type_name in ("TEXTTRANSFORM", "TEXT_TRANSFORM", "TextTransform"):
        function_type = getattr(FunctionType, type_name, None)
        if function_type is not None:
            return function_type
    # Alibaba Cloud Milvus provides TEXTTRANSFORM as a managed extension (function type value 9);
    # some pymilvus versions do not have this enum member built in, while Function(...) validates through FunctionType(...).
    existing = getattr(FunctionType, "_value2member_map_", {}).get(TEXTTRANSFORM_FUNCTION_TYPE)
    if existing is not None:
        return existing
    extension = int.__new__(FunctionType, TEXTTRANSFORM_FUNCTION_TYPE)
    extension._name_ = "TEXTTRANSFORM"
    extension._value_ = TEXTTRANSFORM_FUNCTION_TYPE
    FunctionType._value2member_map_[TEXTTRANSFORM_FUNCTION_TYPE] = extension
    FunctionType._member_map_["TEXTTRANSFORM"] = extension
    return extension

def add_id(schema: Any) -> None:
    schema.add_field("id", DataType.INT64, is_primary=True)

def add_dummy_vector(schema: Any) -> None:
    schema.add_field("dummy_vector", DataType.FLOAT_VECTOR, dim=DUMMY_VECTOR_DIM)

def run_texttransform_example(*, client, collection_name, input_fields, output_field, function_name, function_params, rows) -> None:
    if client.has_collection(collection_name):
        client.drop_collection(collection_name)
    schema = MilvusClient.create_schema(auto_id=True, enable_dynamic_field=False)
    add_id(schema)
    for name, data_type, max_length in input_fields:
        field_params = {"max_length": max_length} if max_length is not None else {}
        schema.add_field(name, data_type, **field_params)
    output_name, output_data_type, output_max_length = output_field
    output_params = {"max_length": output_max_length} if output_max_length is not None else {}
    schema.add_field(output_name, output_data_type, **output_params)
    add_dummy_vector(schema)
    schema.add_function(
        Function(
            name=function_name,
            function_type=texttransform_function_type(),
            input_field_names=[name for name, _, _ in input_fields],
            output_field_names=[output_name],
            params=function_params,
        )
    )
    index_params = client.prepare_index_params()
    index_params.add_index(field_name="dummy_vector", index_type="AUTOINDEX", metric_type="COSINE")
    client.create_collection(collection_name=collection_name, schema=schema, index_params=index_params)
    client.insert(collection_name, rows)
    client.flush(collection_name)
    fields = [name for name, _, _ in input_fields] + [output_name]
    for row in client.query(collection_name, filter="", output_fields=fields, limit=len(rows)):
        print(row)

client = MilvusClient(uri=MILVUS_URI, token=MILVUS_TOKEN)

run_texttransform_example(
    client=client,
    collection_name="simple_ai_keywords_text",
    input_fields=[("content", DataType.VARCHAR, 8192)],
    output_field=("keywords", DataType.JSON, None),
    function_name="extract_keywords",
    function_params={"provider": "aliyun_milvus", "model_name": "qwen3.7-max", "task": "ai_keywords", "max_keywords": "5", "target_language": "en", "temperature": "0"},
    rows=[{"content": "Milvus is an open-source vector database for high-performance approximate nearest neighbor search in RAG, recommendation, and image search.", "dummy_vector": [0.1, 0.2]}],
)

@id="p0081k7q2t81"

Résultat attendu : Le champ keywords renvoie {"keywords":["Milvus","vector database","approximate nearest neighbor search","RAG","open-source"]} (mots-clés en anglais lorsque target_language=en).

@id="h0079k7q2t79"

Exemple 2 : Extraction de mots-clés à partir d'images de produits (image)

Une équipe média doit générer des mots-clés en anglais à partir d'images pour permettre la recherche d'actifs multilingue.

API REST

@id="tab0085k7q2t85"

API REST

@id="c0088k7q2t88"

#!/usr/bin/env bash
set -euo pipefail

MILVUS_REST_BASE_URL="http://c-xxxx.milvus.aliyuncs.com:19530"
MILVUS_AUTH_TOKEN="<yourUsername>:<yourPassword>"

post_json() {
  local path="$1"
  local body="$2"
  curl -X POST \
    "$MILVUS_REST_BASE_URL$path" \
    -H "Authorization: Bearer $MILVUS_AUTH_TOKEN" \
    -H "Content-Type: application/json" \
    -d "$body"
}

BODY=$(cat <<JSON
{"model_name":"qwen3.7-plus","texts":["https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260415/hynnff/wan-video-edit-clothes.webp"],"params":{"media_type":"image","max_keywords":5,"target_language":"en","temperature":0,"timeout_sec":120,"enable_thinking":false}}
JSON
)
RESPONSE_BODY="$(post_json "/v2/vectordb/ai/keywords" "$BODY")"
if command -v jq >/dev/null 2>&1; then
  echo "$RESPONSE_BODY" | jq .
  [ "$(echo "$RESPONSE_BODY" | jq -r '.code // -1')" = "0" ] || exit 1
else
  echo "$RESPONSE_BODY"
fi

@id="rt0086k7q2t86"

@id="h0087k7q2t87"

Python (Fonction de collection)

@id="pt0089k7q2t89"

Python (Fonction de collection)

Cet exemple utilise les mêmes fonctions utilitaires définies dans l'exemple 1. Seul l'appel spécifique est présenté ci-dessous.

@id="c0091k7q2t91"

client = MilvusClient(uri=MILVUS_URI, token=MILVUS_TOKEN)

run_texttransform_example(
    client=client,
    collection_name="simple_ai_keywords_image",
    input_fields=[("image_url", DataType.VARCHAR, 4096)],
    output_field=("keywords", DataType.JSON, None),
    function_name="extract_image_keywords",
    function_params={"provider": "aliyun_milvus", "model_name": "qwen3.7-plus", "task": "ai_keywords", "media_type": "image", "max_keywords": "5", "target_language": "en", "temperature": "0"},
    rows=[{"image_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260415/hynnff/wan-video-edit-clothes.webp", "dummy_vector": [0.1, 0.2]}],
)

@id="p0092k7q2t92"

Résultat attendu : Le champ keywords renvoie jusqu'à 5 mots-clés en anglais extraits de l'image, au format {"keywords":[...]}.

@id="h0090k7q2t90"

Exemple 3 : Extraction de mots-clés à partir d'actifs vidéo (vidéo)

Une bibliothèque vidéo doit étiqueter automatiquement les vidéos pour permettre leur récupération par sujet et par scène.

API REST

@id="tab0096k7q2t96"

API REST

@id="c0099k7q2t02"

#!/usr/bin/env bash
set -euo pipefail

MILVUS_REST_BASE_URL="http://c-xxxx.milvus.aliyuncs.com:19530"
MILVUS_AUTH_TOKEN="<yourUsername>:<yourPassword>"

post_json() {
  local path="$1"
  local body="$2"
  curl -X POST \
    "$MILVUS_REST_BASE_URL$path" \
    -H "Authorization: Bearer $MILVUS_AUTH_TOKEN" \
    -H "Content-Type: application/json" \
    -d "$body"
}

BODY=$(cat <<JSON
{"model_name":"qwen3.7-plus","texts":["https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260409/dozxak/Wan_Video_Edit_33_1.mp4"],"params":{"media_type":"video","max_keywords":5,"target_language":"en","temperature":0}}
JSON
)
RESPONSE_BODY="$(post_json "/v2/vectordb/ai/keywords" "$BODY")"
if command -v jq >/dev/null 2>&1; then
  echo "$RESPONSE_BODY" | jq .
  [ "$(echo "$RESPONSE_BODY" | jq -r '.code // -1')" = "0" ] || exit 1
else
  echo "$RESPONSE_BODY"
fi

@id="rt0097k7q2t00"

@id="h0098k7q2t01"

Python (Fonction de collection)

@id="pt0100k7q2t03"

Python (Fonction de collection)

Cet exemple utilise les mêmes fonctions utilitaires définies dans l'exemple 1. Seul l'appel spécifique est présenté ci-dessous.

@id="c0102k7q2t05"

client = MilvusClient(uri=MILVUS_URI, token=MILVUS_TOKEN)

run_texttransform_example(
    client=client,
    collection_name="simple_ai_keywords_video",
    input_fields=[("video_url", DataType.VARCHAR, 4096)],
    output_field=("keywords", DataType.JSON, None),
    function_name="extract_video_keywords",
    function_params={"provider": "aliyun_milvus", "model_name": "qwen3.7-plus", "task": "ai_keywords", "media_type": "video", "max_keywords": "5", "target_language": "en", "temperature": "0"},
    rows=[{"video_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260409/dozxak/Wan_Video_Edit_33_1.mp4", "dummy_vector": [0.1, 0.2]}],
)

@id="p0103k7q2t06"

Résultat attendu : Le champ keywords renvoie jusqu'à 5 mots-clés en anglais liés au sujet de la vidéo, qui peuvent être écrits dans les champs de récupération vidéo.

@id="h0101k7q2t04"