正在加载

使用推理 API 进行语义搜索

Elastic Stack Serverless

本教程中的说明向您展示了如何使用推理 API 工作流程以及各种服务对您的数据执行语义搜索。

重要事项

要以最简单的方式在 Elastic Stack 中执行语义搜索,请参阅 semantic_text 端到端教程。

以下示例使用

您可以使用任何 Cohere 和 OpenAI 模型,推理 API 都支持它们。 有关 HuggingFace 上提供的推荐模型列表,请参阅 API 文档中支持的模型列表。

单击下面任何窗口小部件上您要使用的服务的名称,以查看相应的说明。

需要一个 Cohere 帐户才能将推理 API 与 Cohere 服务一起使用。

ELSER 是 Elastic 训练的模型。 如果您有 Elasticsearch 部署,则使用带有 elasticsearch 服务的推理 API 没有其他要求。

需要一个 HuggingFace 帐户才能将推理 API 与 HuggingFace 服务一起使用。

需要一个 OpenAI 帐户才能将推理 API 与 OpenAI 服务一起使用。

  • 一个 Google Cloud 帐户
  • Google Cloud 中的一个项目
  • 在您的项目中启用的 Vertex AI API
  • Google Vertex AI API 的有效服务帐户
  • 该服务帐户必须具有 Vertex AI 用户角色和 aiplatform.endpoints.predict 权限。
  • La Plateforme 上的 Mistral 帐户
  • 为您的帐户生成的 API 密钥
  • 具有 Amazon Bedrock 访问权限的 AWS 帐户
  • 用于访问 Amazon Bedrock 的一对访问密钥和秘密密钥

通过使用 创建推理 API来创建推理端点

 PUT _inference/text_embedding/cohere_embeddings <1> {
    "service": "cohere",
    "service_settings": {
        "api_key": "<api_key>",
        "model_id": "embed-english-v3.0",
        "embedding_type": "byte"
    }
}
  1. 任务类型是路径中的 text_embedding,推理端点的唯一标识符 inference_idcohere_embeddings
  2. 您的 Cohere 帐户的 API 密钥。 您可以在 Cohere 仪表板的 API 密钥部分下找到您的 API 密钥。 您只需要提供一次 API 密钥。 Get inference API 不会返回您的 API 密钥。
  3. 要使用的嵌入模型的名称。 您可以在此处找到 Cohere 嵌入模型列表。
注意

当使用此模型时,建议在 dense_vector 字段映射中使用的相似度度量是 dot_product。 在 Cohere 模型的情况下,嵌入已归一化为单位长度,在这种情况下,dot_productcosine 度量是等效的。

 PUT _inference/sparse_embedding/elser_embeddings <1> {
  "service": "elasticsearch",
  "service_settings": {
    "num_allocations": 1,
    "num_threads": 1
  }
}
  1. 任务类型是路径中的 sparse_embedding,推理端点的唯一标识符 inference_idelser_embeddings

您无需提前下载和部署 ELSER 模型,如果您尚未下载该模型,则上述 API 请求将下载该模型并将其部署。

注意

当使用 Kibana 控制台时,您可能会在响应中看到 502 错误的网关错误。 此错误通常只反映超时,而模型在后台下载。 您可以在 Machine Learning UI 中查看下载进度。 如果使用 Python 客户端,您可以将 timeout 参数设置为更高的值。

首先,您需要在 Hugging Face 端点页面上创建一个新的推理端点,以获取端点 URL。 在新的端点创建页面上选择模型 all-mpnet-base-v2,然后在高级配置部分下选择 Sentence Embeddings 任务。 创建端点。 在端点初始化完成后复制 URL,您需要在以下推理 API 调用中使用该 URL。

 PUT _inference/text_embedding/hugging_face_embeddings <1> {
  "service": "hugging_face",
  "service_settings": {
    "api_key": "<access_token>",
    "url": "<url_endpoint>"
  }
}
  1. 任务类型是路径中的 text_embedding,推理端点的唯一标识符 inference_idhugging_face_embeddings
  2. 有效的 HuggingFace 访问令牌。 您可以在您帐户的设置页面上找到它。
  3. 您在 Hugging Face 上创建的推理端点 URL。
 PUT _inference/text_embedding/openai_embeddings <1> {
    "service": "openai",
    "service_settings": {
        "api_key": "<api_key>",
        "model_id": "text-embedding-ada-002"
    }
}
  1. 任务类型是路径中的 text_embedding,推理端点的唯一标识符 inference_idopenai_embeddings
  2. 您的 OpenAI 帐户的 API 密钥。 您可以在 OpenAI 帐户的 API 密钥部分下找到您的 OpenAI API 密钥。 您只需要提供一次 API 密钥。 Get inference API 不会返回您的 API 密钥。
  3. 要使用的嵌入模型的名称。 您可以在 此处找到 OpenAI 嵌入模型列表。
注意

当使用此模型时,建议在 dense_vector 字段映射中使用的相似度度量是 dot_product。 在 OpenAI 模型的情况下,嵌入已归一化为单位长度,在这种情况下,dot_productcosine 度量是等效的。

 PUT _inference/text_embedding/azure_openai_embeddings <1> {
    "service": "azureopenai",
    "service_settings": {
        "api_key": "<api_key>",
        "resource_name": "<resource_name>",
        "deployment_id": "<deployment_id>",
        "api_version": "2024-02-01"
    }
}
  1. 任务类型是路径中的 text_embedding,推理端点的唯一标识符 inference_idazure_openai_embeddings
  2. 用于访问您的 Azure OpenAI 服务的 API 密钥。 或者,您可以在此处提供 entra_id 而不是 api_keyGet inference API 不会返回此信息。
  3. 您的 Azure 资源的名称。
  4. 您的已部署模型的 ID。
注意

您的模型的部署可能需要几分钟才能在创建后变为可用。 如果您尝试如上所示创建模型并收到 404 错误消息,请等待几分钟然后重试。 此外,当使用此模型时,建议在 dense_vector 字段映射中使用的相似度度量是 dot_product。 在 Azure OpenAI 模型的情况下,嵌入已归一化为单位长度,在这种情况下,dot_productcosine 度量是等效的。

 PUT _inference/text_embedding/azure_ai_studio_embeddings <1> {
    "service": "azureaistudio",
    "service_settings": {
        "api_key": "<api_key>",
        "target": "<target_uri>",
        "provider": "<provider>",
        "endpoint_type": "<endpoint_type>"
    }
}
  1. 任务类型是路径中的 text_embedding,推理端点的唯一标识符 inference_idazure_ai_studio_embeddings
  2. 用于访问您的 Azure AI Studio 已部署模型的 API 密钥。 您可以在模型部署的概述页面上找到它。
  3. 用于访问您的 Azure AI Studio 已部署模型的目标 URI。 您可以在模型部署的概述页面上找到它。
  4. 模型提供商,例如 cohereopenai
  5. 已部署的端点类型。 这可以是 token(对于“按需付费”部署)或 realtime(对于实时部署端点)。
注意

您的模型的部署可能需要几分钟才能在创建后变为可用。 如果您尝试如上所示创建模型并收到 404 错误消息,请等待几分钟然后重试。 此外,当使用此模型时,建议在 dense_vector 字段映射中使用的相似度度量是 dot_product

 PUT _inference/text_embedding/google_vertex_ai_embeddings <1> {
    "service": "googlevertexai",
    "service_settings": {
        "service_account_json": "<service_account_json>",
        "model_id": "text-embedding-004",
        "location": "<location>",
        "project_id": "<project_id>"
    }
}
  1. 任务类型是根据路径的 text_embeddinggoogle_vertex_ai_embeddings 是推理端点的唯一标识符(其 inference_id)。
  2. Google Vertex AI API 的 JSON 格式的有效服务帐户。
  3. 有关可用模型的列表,请参阅 文本嵌入 API 页面。
  4. 用于推理任务的位置名称。有关可用位置,请参阅 Vertex AI 上的生成式 AI 位置
  5. 用于推理任务的项目名称。
 PUT _inference/text_embedding/mistral_embeddings <1> {
    "service": "mistral",
    "service_settings": {
        "api_key": "<api_key>",
        "model": "<model_id>"
    }
}
  1. 任务类型在路径中为 text_embedding,推理端点的唯一标识符 inference_idmistral_embeddings
  2. 用于访问 Mistral API 的 API 密钥。您可以在您的 Mistral 账户的 API 密钥页面中找到它。
  3. Mistral 嵌入模型名称,例如 mistral-embed
 PUT _inference/text_embedding/amazon_bedrock_embeddings <1> {
    "service": "amazonbedrock",
    "service_settings": {
        "access_key": "<aws_access_key>",
        "secret_key": "<aws_secret_key>",
        "region": "<region>",
        "provider": "<provider>",
        "model": "<model_id>"
    }
}
  1. 任务类型在路径中为 text_embedding,推理端点的唯一标识符 inference_idamazon_bedrock_embeddings
  2. 访问密钥可以在您的 AWS IAM 管理页面上找到,用于访问 Amazon Bedrock 的用户帐户。
  3. 密钥应为指定访问密钥的配对密钥。
  4. 指定您的模型托管的区域。
  5. 指定模型提供商。
  6. 要使用的模型的模型 ID 或 ARN。
 PUT _inference/text_embedding/alibabacloud_ai_search_embeddings <1> {
    "service": "alibabacloud-ai-search",
    "service_settings": {
        "api_key": "<api_key>",
        "service_id": "<service_id>",
        "host": "<host>",
        "workspace": "<workspace>"
    }
}
  1. 任务类型在路径中为 text_embedding,推理端点的唯一标识符 inference_idalibabacloud_ai_search_embeddings
  2. 用于访问 AlibabaCloud AI 搜索 API 的 API 密钥。 您可以在 AlibabaCloud 帐户的 API 密钥部分下找到您的 API 密钥。 您只需提供一次 API 密钥。 获取推理 API 不会返回您的 API 密钥。
  3. AlibabaCloud AI 搜索嵌入模型名称,例如 ops-text-embedding-zh-001
  4. AlibabaCloud AI 搜索主机地址的名称。
  5. AlibabaCloud AI 搜索工作区的名称。

必须创建目标索引的映射 - 包含模型将根据您的输入文本创建的嵌入的索引。 对于大多数模型,目标索引必须具有 dense_vector 字段类型的字段,对于稀疏向量模型,例如 elasticsearch 服务中的模型,则必须具有 sparse_vector 字段类型,以索引所用模型的输出。

 PUT cohere-embeddings {
  "mappings": {
    "properties": {
      "content_embedding": {
        "type": "dense_vector",
        "dims": 1024,
        "element_type": "byte"
      },
      "content": {
        "type": "text"
      }
    }
  }
}
  1. 包含生成的令牌的字段的名称。它必须在下一步的推理管道配置中被引用。
  2. 包含令牌的字段是一个 dense_vector 字段。
  3. 模型的输出维度。 在您使用的模型的 Cohere 文档中找到此值。
  4. 从中创建密集向量表示的字段的名称。 在此示例中,字段的名称是 content。 它必须在下一步的推理管道配置中被引用。
  5. 字段类型,在本示例中为文本。
 PUT elser-embeddings {
  "mappings": {
    "properties": {
      "content_embedding": {
        "type": "sparse_vector"
      },
      "content": {
        "type": "text"
      }
    }
  }
}
  1. 包含生成的令牌的字段的名称。它必须在下一步的推理管道配置中被引用。
  2. 包含令牌的字段是 ELSER 的 sparse_vector 字段。
  3. 从中创建密集向量表示的字段的名称。 在此示例中,字段的名称是 content。 它必须在下一步的推理管道配置中被引用。
  4. 字段类型,在本示例中为文本。
 PUT hugging-face-embeddings {
  "mappings": {
    "properties": {
      "content_embedding": {
        "type": "dense_vector",
        "dims": 768,
        "element_type": "float"
      },
      "content": {
        "type": "text"
      }
    }
  }
}
  1. 包含生成的令牌的字段的名称。它必须在下一步的推理管道配置中被引用。
  2. 包含令牌的字段是一个 dense_vector 字段。
  3. 模型的输出维度。 在 HuggingFace 模型文档中查找此值。
  4. 从中创建密集向量表示的字段的名称。 在此示例中,字段的名称是 content。 它必须在下一步的推理管道配置中被引用。
  5. 字段类型,在本示例中为文本。
 PUT openai-embeddings {
  "mappings": {
    "properties": {
      "content_embedding": {
        "type": "dense_vector",
        "dims": 1536,
        "element_type": "float",
        "similarity": "dot_product"
      },
      "content": {
        "type": "text"
      }
    }
  }
}
  1. 包含生成的令牌的字段的名称。它必须在下一步的推理管道配置中被引用。
  2. 包含令牌的字段是一个 dense_vector 字段。
  3. 模型的输出维度。 在您使用的模型的 OpenAI 文档中查找此值。
  4. 更快的 dot_product 函数可用于计算相似度,因为 OpenAI 嵌入已归一化为单位长度。 您可以查看 OpenAI 文档,了解应使用哪种相似度函数。
  5. 从中创建密集向量表示的字段的名称。 在此示例中,字段的名称是 content。 它必须在下一步的推理管道配置中被引用。
  6. 字段类型,在本示例中为文本。
 PUT azure-openai-embeddings {
  "mappings": {
    "properties": {
      "content_embedding": {
        "type": "dense_vector",
        "dims": 1536,
        "element_type": "float",
        "similarity": "dot_product"
      },
      "content": {
        "type": "text"
      }
    }
  }
}
  1. 包含生成的令牌的字段的名称。它必须在下一步的推理管道配置中被引用。
  2. 包含令牌的字段是一个 dense_vector 字段。
  3. 模型的输出维度。 在您使用的模型的 Azure OpenAI 文档中查找此值。
  4. 对于 Azure OpenAI 嵌入,应使用 dot_product 函数来计算相似度,因为 Azure OpenAI 嵌入已归一化为单位长度。 有关模型规范的更多信息,请参阅 Azure OpenAI 嵌入 文档。
  5. 从中创建密集向量表示的字段的名称。 在此示例中,字段的名称是 content。 它必须在下一步的推理管道配置中被引用。
  6. 字段类型,在本示例中为文本。
 PUT azure-ai-studio-embeddings {
  "mappings": {
    "properties": {
      "content_embedding": {
        "type": "dense_vector",
        "dims": 1536,
        "element_type": "float",
        "similarity": "dot_product"
      },
      "content": {
        "type": "text"
      }
    }
  }
}
  1. 包含生成的令牌的字段的名称。它必须在下一步的推理管道配置中被引用。
  2. 包含令牌的字段是一个 dense_vector 字段。
  3. 模型的输出维度。 可以在 Azure AI Studio 部署中的模型卡上找到此值。
  4. 对于 Azure AI Studio 嵌入,应使用 dot_product 函数来计算相似度。
  5. 从中创建密集向量表示的字段的名称。 在此示例中,字段的名称是 content。 它必须在下一步的推理管道配置中被引用。
  6. 字段类型,在本示例中为文本。
 PUT google-vertex-ai-embeddings {
  "mappings": {
    "properties": {
      "content_embedding": {
        "type": "dense_vector",
        "dims": 768,
        "element_type": "float",
        "similarity": "dot_product"
      },
      "content": {
        "type": "text"
      }
    }
  }
}
  1. 包含生成的嵌入的字段的名称。它必须在下一步的推理管道配置中被引用。
  2. 包含嵌入的字段是一个 dense_vector 字段。
  3. 模型的输出维度。 可以在 Google Vertex AI 模型参考中找到此值。 如果未指定 dims,则推理 API 会尝试自动计算输出维度。
  4. 对于 Google Vertex AI 嵌入,应使用 dot_product 函数来计算相似度。
  5. 从中创建密集向量表示的字段的名称。 在此示例中,字段的名称是 content。 它必须在下一步的推理管道配置中被引用。
  6. 字段类型,在本示例中为 text
 PUT mistral-embeddings {
  "mappings": {
    "properties": {
      "content_embedding": {
        "type": "dense_vector",
        "dims": 1024,
        "element_type": "float",
        "similarity": "dot_product"
      },
      "content": {
        "type": "text"
      }
    }
  }
}
  1. 包含生成的令牌的字段的名称。它必须在下一步的推理管道配置中被引用。
  2. 包含令牌的字段是一个 dense_vector 字段。
  3. 模型的输出维度。 可以在 Mistral 模型参考中找到此值。
  4. 对于 Mistral 嵌入,应使用 dot_product 函数来计算相似度。
  5. 从中创建密集向量表示的字段的名称。 在此示例中,字段的名称是 content。 它必须在下一步的推理管道配置中被引用。
  6. 字段类型,在本示例中为文本。
 PUT amazon-bedrock-embeddings {
  "mappings": {
    "properties": {
      "content_embedding": {
        "type": "dense_vector",
        "dims": 1024,
        "element_type": "float",
        "similarity": "dot_product"
      },
      "content": {
        "type": "text"
      }
    }
  }
}
  1. 包含生成的令牌的字段的名称。它必须在下一步的推理管道配置中被引用。
  2. 包含令牌的字段是一个 dense_vector 字段。
  3. 模型的输出维度。 此值可能因所使用的基础模型而异。 请参阅 Amazon Titan 模型Cohere 嵌入模型文档。
  4. 对于 Amazon Bedrock 嵌入,对于 Amazon Titan 模型,应使用 dot_product 函数来计算相似度,对于 Cohere 模型,应使用 cosine 函数。
  5. 从中创建密集向量表示的字段的名称。 在此示例中,字段的名称是 content。 它必须在下一步的推理管道配置中被引用。
  6. 字段类型,在本示例中为文本。
 PUT alibabacloud-ai-search-embeddings {
  "mappings": {
    "properties": {
      "content_embedding": {
        "type": "dense_vector",
        "dims": 1024,
        "element_type": "float"
      },
      "content": {
        "type": "text"
      }
    }
  }
}
  1. 包含生成的令牌的字段的名称。它必须在下一步的推理管道配置中被引用。
  2. 包含令牌的字段是一个 dense_vector 字段。
  3. 模型的输出维度。 此值可能因所使用的基础模型而异。 请参阅 AlibabaCloud AI 搜索嵌入模型 文档。
  4. 从中创建密集向量表示的字段的名称。 在此示例中,字段的名称是 content。 它必须在下一步的推理管道配置中被引用。
  5. 字段类型,在本示例中为文本。

创建一个带有 推理处理器采集管道,并使用您上面创建的模型来推断管道中正在采集的数据。

 PUT _ingest/pipeline/cohere_embeddings_pipeline {
  "processors": [
    {
      "inference": {
        "model_id": "cohere_embeddings",
        "input_output": {
          "input_field": "content",
          "output_field": "content_embedding"
        }
      }
    }
  ]
}
  1. 您使用 创建推理 API 创建的推理端点的名称,在该步骤中称为 inference_id
  2. 配置对象,用于定义推理过程的 input_field 和包含推理结果的 output_field
 PUT _ingest/pipeline/elser_embeddings_pipeline {
  "processors": [
    {
      "inference": {
        "model_id": "elser_embeddings",
        "input_output": {
          "input_field": "content",
          "output_field": "content_embedding"
        }
      }
    }
  ]
}
  1. 您使用 创建推理 API 创建的推理端点的名称,在该步骤中称为 inference_id
  2. 配置对象,用于定义推理过程的 input_field 和包含推理结果的 output_field
 PUT _ingest/pipeline/hugging_face_embeddings_pipeline {
  "processors": [
    {
      "inference": {
        "model_id": "hugging_face_embeddings",
        "input_output": {
          "input_field": "content",
          "output_field": "content_embedding"
        }
      }
    }
  ]
}
  1. 您使用 创建推理 API 创建的推理端点的名称,在该步骤中称为 inference_id
  2. 配置对象,用于定义推理过程的 input_field 和包含推理结果的 output_field
 PUT _ingest/pipeline/openai_embeddings_pipeline {
  "processors": [
    {
      "inference": {
        "model_id": "openai_embeddings",
        "input_output": {
          "input_field": "content",
          "output_field": "content_embedding"
        }
      }
    }
  ]
}
  1. 您使用 创建推理 API 创建的推理端点的名称,在该步骤中称为 inference_id
  2. 配置对象,用于定义推理过程的 input_field 和包含推理结果的 output_field
 PUT _ingest/pipeline/azure_openai_embeddings_pipeline {
  "processors": [
    {
      "inference": {
        "model_id": "azure_openai_embeddings",
        "input_output": {
          "input_field": "content",
          "output_field": "content_embedding"
        }
      }
    }
  ]
}
  1. 您使用 创建推理 API 创建的推理端点的名称,在该步骤中称为 inference_id
  2. 配置对象,用于定义推理过程的 input_field 和包含推理结果的 output_field
 PUT _ingest/pipeline/azure_ai_studio_embeddings_pipeline {
  "processors": [
    {
      "inference": {
        "model_id": "azure_ai_studio_embeddings",
        "input_output": {
          "input_field": "content",
          "output_field": "content_embedding"
        }
      }
    }
  ]
}
  1. 您使用 创建推理 API 创建的推理端点的名称,在该步骤中称为 inference_id
  2. 配置对象,用于定义推理过程的 input_field 和包含推理结果的 output_field
 PUT _ingest/pipeline/google_vertex_ai_embeddings_pipeline {
  "processors": [
    {
      "inference": {
        "model_id": "google_vertex_ai_embeddings",
        "input_output": {
          "input_field": "content",
          "output_field": "content_embedding"
        }
      }
    }
  ]
}
  1. 您使用 创建推理 API 创建的推理端点的名称,在该步骤中称为 inference_id
  2. 配置对象,用于定义推理过程的 input_field 和包含推理结果的 output_field
 PUT _ingest/pipeline/mistral_embeddings_pipeline {
  "processors": [
    {
      "inference": {
        "model_id": "mistral_embeddings",
        "input_output": {
          "input_field": "content",
          "output_field": "content_embedding"
        }
      }
    }
  ]
}
  1. 您使用 创建推理 API 创建的推理端点的名称,在该步骤中称为 inference_id
  2. 配置对象,用于定义推理过程的 input_field 和包含推理结果的 output_field
 PUT _ingest/pipeline/amazon_bedrock_embeddings_pipeline {
  "processors": [
    {
      "inference": {
        "model_id": "amazon_bedrock_embeddings",
        "input_output": {
          "input_field": "content",
          "output_field": "content_embedding"
        }
      }
    }
  ]
}
  1. 您使用 创建推理 API 创建的推理端点的名称,在该步骤中称为 inference_id
  2. 配置对象,用于定义推理过程的 input_field 和包含推理结果的 output_field
 PUT _ingest/pipeline/alibabacloud_ai_search_embeddings_pipeline {
  "processors": [
    {
      "inference": {
        "model_id": "alibabacloud_ai_search_embeddings",
        "input_output": {
          "input_field": "content",
          "output_field": "content_embedding"
        }
      }
    }
  ]
}
  1. 您使用 创建推理 API 创建的推理端点的名称,在该步骤中称为 inference_id
  2. 配置对象,用于定义推理过程的 input_field 和包含推理结果的 output_field

在此步骤中,您加载稍后在推理采集管道中使用的数据,以从中创建嵌入。

使用 msmarco-passagetest2019-top1000 数据集,它是 MS MARCO Passage Ranking 数据集的子集。 它由 200 个查询组成,每个查询都附带一个相关文本段落列表。 所有唯一段落及其 ID 已从该数据集中提取并编译到 tsv 文件中。

下载该文件并使用 Machine Learning UI 中的 数据可视化工具 将其上传到您的集群。 分析您的数据后,单击覆盖设置。 在编辑字段名称下,将 id 分配给第一列,将 content 分配给第二列。 单击应用,然后单击导入。 将索引命名为 test-data,然后单击导入。 上传完成后,您将看到一个名为 test-data 的索引,其中包含 182,469 个文档。

通过重新索引通过使用您选择的模型的推理管道的数据,从文本创建嵌入。 此步骤使用 reindex API 来模拟通过管道的数据采集。

 POST _reindex?wait_for_completion=false {
  "source": {
    "index": "test-data",
    "size": 50
  },
  "dest": {
    "index": "cohere-embeddings",
    "pipeline": "cohere_embeddings_pipeline"
  }
}
  1. 重新索引的默认批处理大小为 1000。 将 size 减小到一个较小的数字可以更快地更新重新索引过程,使您可以密切关注进度并尽早检测到错误。
注意

您的 Cohere 账户的速率限制 可能会影响重新索引过程的吞吐量。

 POST _reindex?wait_for_completion=false {
  "source": {
    "index": "test-data",
    "size": 50
  },
  "dest": {
    "index": "elser-embeddings",
    "pipeline": "elser_embeddings_pipeline"
  }
}
  1. 重新索引的默认批处理大小为 1000。 将 size 减小到一个较小的数字可以更快地更新重新索引过程,使您可以密切关注进度并尽早检测到错误。
 POST _reindex?wait_for_completion=false {
  "source": {
    "index": "test-data",
    "size": 50
  },
  "dest": {
    "index": "hugging-face-embeddings",
    "pipeline": "hugging_face_embeddings_pipeline"
  }
}
  1. 重新索引的默认批处理大小为 1000。 将 size 减小到一个较小的数字可以更快地更新重新索引过程,使您可以密切关注进度并尽早检测到错误。
 POST _reindex?wait_for_completion=false {
  "source": {
    "index": "test-data",
    "size": 50
  },
  "dest": {
    "index": "openai-embeddings",
    "pipeline": "openai_embeddings_pipeline"
  }
}
  1. 重新索引的默认批处理大小为 1000。 将 size 减小到一个较小的数字可以更快地更新重新索引过程,使您可以密切关注进度并尽早检测到错误。
注意

您的 OpenAI 账户的速率限制 可能会影响重新索引过程的吞吐量。 如果发生这种情况,请将 size 更改为 3 或相似量级的值。

 POST _reindex?wait_for_completion=false {
  "source": {
    "index": "test-data",
    "size": 50
  },
  "dest": {
    "index": "azure-openai-embeddings",
    "pipeline": "azure_openai_embeddings_pipeline"
  }
}
  1. 重新索引的默认批处理大小为 1000。 将 size 减小到一个较小的数字可以更快地更新重新索引过程,使您可以密切关注进度并尽早检测到错误。
注意

您的 Azure OpenAI 账户的速率限制 可能会影响重新索引过程的吞吐量。 如果发生这种情况,请将 size 更改为 3 或相似量级的值。

 POST _reindex?wait_for_completion=false {
  "source": {
    "index": "test-data",
    "size": 50
  },
  "dest": {
    "index": "azure-ai-studio-embeddings",
    "pipeline": "azure_ai_studio_embeddings_pipeline"
  }
}
  1. 重新索引的默认批处理大小为 1000。 将 size 减小到一个较小的数字可以更快地更新重新索引过程,使您可以密切关注进度并尽早检测到错误。
注意

您的 Azure AI Studio 模型部署可能具有速率限制,这可能会影响重新索引过程的吞吐量。 如果发生这种情况,请将 size 更改为 3 或相似量级的值。

 POST _reindex?wait_for_completion=false {
  "source": {
    "index": "test-data",
    "size": 50
  },
  "dest": {
    "index": "google-vertex-ai-embeddings",
    "pipeline": "google_vertex_ai_embeddings_pipeline"
  }
}
  1. 重新索引的默认批处理大小为 1000。 减少 size 将使更新重新索引过程更快。 这使您可以密切关注进度并尽早检测到错误。
 POST _reindex?wait_for_completion=false {
  "source": {
    "index": "test-data",
    "size": 50
  },
  "dest": {
    "index": "mistral-embeddings",
    "pipeline": "mistral_embeddings_pipeline"
  }
}
  1. 重新索引的默认批处理大小为 1000。 将 size 减小到一个较小的数字可以更快地更新重新索引过程,使您可以密切关注进度并尽早检测到错误。
 POST _reindex?wait_for_completion=false {
  "source": {
    "index": "test-data",
    "size": 50
  },
  "dest": {
    "index": "amazon-bedrock-embeddings",
    "pipeline": "amazon_bedrock_embeddings_pipeline"
  }
}
  1. 重新索引的默认批处理大小为 1000。 将 size 减小到一个较小的数字可以更快地更新重新索引过程,使您可以密切关注进度并尽早检测到错误。
 POST _reindex?wait_for_completion=false {
  "source": {
    "index": "test-data",
    "size": 50
  },
  "dest": {
    "index": "alibabacloud-ai-search-embeddings",
    "pipeline": "alibabacloud_ai_search_embeddings_pipeline"
  }
}
  1. 重新索引的默认批处理大小为 1000。 将 size 减小到一个较小的数字可以更快地更新重新索引过程,使您可以密切关注进度并尽早检测到错误。

该调用返回一个任务 ID 以监视进度

 GET _tasks/<task_id> 

重新索引大型数据集可能需要很长时间。 您可以使用数据集的子集来测试此工作流程。 通过取消重新索引过程来实现此目的,并且仅为已重新索引的子集生成嵌入。 以下 API 请求将取消重新索引任务

 POST _tasks/<task_id>/_cancel 

在数据集已使用嵌入进行丰富后,您可以使用 语义搜索 查询数据。 对于密集向量模型,将 query_vector_builder 传递到 k-最近邻 (kNN) 向量搜索 API,并提供查询文本和用于创建嵌入的模型。 对于像 ELSER 这样的稀疏向量模型,请使用 sparse_vector 查询,并提供查询文本以及用于创建嵌入的模型。

注意

如果您取消了重新索引过程,则您仅对部分数据运行查询,这会影响您的结果质量。

 GET cohere-embeddings/_search {
  "knn": {
    "field": "content_embedding",
    "query_vector_builder": {
      "text_embedding": {
        "model_id": "cohere_embeddings",
        "model_text": "Muscles in human body"
      }
    },
    "k": 10,
    "num_candidates": 100
  },
  "_source": [
    "id",
    "content"
  ]
}

结果,您会收到与 cohere-embeddings 索引中与查询的含义最接近的前 10 个文档,这些文档按它们与查询的接近程度排序

"hits": [
      {
        "_index": "cohere-embeddings",
        "_id": "-eFWCY4BECzWLnMZuI78",
        "_score": 0.737484,
        "_source": {
          "id": 1690948,
          "content": "Oxygen is supplied to the muscles via red blood cells. Red blood cells carry hemoglobin which oxygen bonds with as the hemoglobin rich blood cells pass through the blood vessels of the lungs.The now oxygen rich blood cells carry that oxygen to the cells that are demanding it, in this case skeletal muscle cells.ther ways in which muscles are supplied with oxygen include: 1  Blood flow from the heart is increased. 2  Blood flow to your muscles in increased. 3  Blood flow from nonessential organs is transported to working muscles."
        }
      },
      {
        "_index": "cohere-embeddings",
        "_id": "HuFWCY4BECzWLnMZuI_8",
        "_score": 0.7176013,
        "_source": {
          "id": 1692482,
          "content": "The thoracic cavity is separated from the abdominal cavity by the  diaphragm. This is a broad flat muscle.    (muscular) diaphragm The diaphragm is a muscle that separat…e the thoracic from the abdominal cavity. The pelvis is the lowest part of the abdominal cavity and it has no physical separation from it    Diaphragm."
        }
      },
      {
        "_index": "cohere-embeddings",
        "_id": "IOFWCY4BECzWLnMZuI_8",
        "_score": 0.7154432,
        "_source": {
          "id": 1692489,
          "content": "Muscular Wall Separating the Abdominal and Thoracic Cavities; Thoracic Cavity of a Fetal Pig; In Mammals the Diaphragm Separates the Abdominal Cavity from the"
        }
      },
      {
        "_index": "cohere-embeddings",
        "_id": "C-FWCY4BECzWLnMZuI_8",
        "_score": 0.695313,
        "_source": {
          "id": 1691493,
          "content": "Burning, aching, tenderness and stiffness are just some descriptors of the discomfort you may feel in the muscles you exercised one to two days ago.For the most part, these sensations you experience after exercise are collectively known as delayed onset muscle soreness.urning, aching, tenderness and stiffness are just some descriptors of the discomfort you may feel in the muscles you exercised one to two days ago."
        }
      },
      (...)
    ]
 GET elser-embeddings/_search {
  "query":{
    "sparse_vector":{
      "field": "content_embedding",
      "inference_id": "elser_embeddings",
      "query": "How to avoid muscle soreness after running?"
    }
  },
  "_source": [
    "id",
    "content"
  ]
}

结果,您会收到与 cohere-embeddings 索引中与查询的含义最接近的前 10 个文档,这些文档按它们与查询的接近程度排序

"hits": [
      {
        "_index": "elser-embeddings",
        "_id": "ZLGc_pABZbBmsu5_eCoH",
        "_score": 21.472063,
        "_source": {
          "id": 2258240,
          "content": "You may notice some muscle aches while you are exercising. This is called acute soreness. More often, you may begin to feel sore about 12 hours after exercising, and the discomfort usually peaks at 48 to 72 hours after exercise. This is called delayed-onset muscle soreness.It is thought that, during this time, your body is repairing the muscle, making it stronger and bigger.You may also notice the muscles feel better if you exercise lightly. This is normal.his is called delayed-onset muscle soreness. It is thought that, during this time, your body is repairing the muscle, making it stronger and bigger. You may also notice the muscles feel better if you exercise lightly. This is normal."
        }
      },
      {
        "_index": "elser-embeddings",
        "_id": "ZbGc_pABZbBmsu5_eCoH",
        "_score": 21.421381,
        "_source": {
          "id": 2258242,
          "content": "Photo Credit Jupiterimages/Stockbyte/Getty Images. That stiff, achy feeling you get in the days after exercise is a normal physiological response known as delayed onset muscle soreness. You can take it as a positive sign that your muscles have felt the workout, but the pain may also turn you off to further exercise.ou are more likely to develop delayed onset muscle soreness if you are new to working out, if you’ve gone a long time without exercising and start up again, if you have picked up a new type of physical activity or if you have recently boosted the intensity, length or frequency of your exercise sessions."
        }
      },
      {
        "_index": "elser-embeddings",
        "_id": "ZrGc_pABZbBmsu5_eCoH",
        "_score": 20.542095,
        "_source": {
          "id": 2258248,
          "content": "They found that stretching before and after exercise has no effect on muscle soreness. Exercise might cause inflammation, which leads to an increase in the production of immune cells (comprised mostly of macrophages and neutrophils). Levels of these immune cells reach a peak 24-48 hours after exercise.These cells, in turn, produce bradykinins and prostaglandins, which make the pain receptors in your body more sensitive. Whenever you move, these pain receptors are stimulated.hey found that stretching before and after exercise has no effect on muscle soreness. Exercise might cause inflammation, which leads to an increase in the production of immune cells (comprised mostly of macrophages and neutrophils). Levels of these immune cells reach a peak 24-48 hours after exercise."
        }
      },
    (...)
  ]
 GET hugging-face-embeddings/_search {
  "knn": {
    "field": "content_embedding",
    "query_vector_builder": {
      "text_embedding": {
        "model_id": "hugging_face_embeddings",
        "model_text": "What's margin of error?"
      }
    },
    "k": 10,
    "num_candidates": 100
  },
  "_source": [
    "id",
    "content"
  ]
}

结果,您会收到与 hugging-face-embeddings 索引中与查询的含义最接近的前 10 个文档,这些文档按它们与查询的接近程度排序

"hits": [
      {
        "_index": "hugging-face-embeddings",
        "_id": "ljEfo44BiUQvMpPgT20E",
        "_score": 0.8522128,
        "_source": {
          "id": 7960255,
          "content": "The margin of error can be defined by either of the following equations. Margin of error = Critical value x Standard deviation of the statistic. Margin of error = Critical value x Standard error of the statistic. If you know the standard deviation of the statistic, use the first equation to compute the margin of error. Otherwise, use the second equation. Previously, we described how to compute the standard deviation and standard error."
        }
      },
      {
        "_index": "hugging-face-embeddings",
        "_id": "lzEfo44BiUQvMpPgT20E",
        "_score": 0.7865497,
        "_source": {
          "id": 7960259,
          "content": "1 y ou are told only the size of the sample and are asked to provide the margin of error for percentages which are not (yet) known. 2  This is typically the case when you are computing the margin of error for a survey which is going to be conducted in the future."
        }
      },
      {
        "_index": "hugging-face-embeddings1",
        "_id": "DjEfo44BiUQvMpPgT20E",
        "_score": 0.6229427,
        "_source": {
          "id": 2166183,
          "content": "1. In general, the point at which gains equal losses. 2. In options, the market price that a stock must reach for option buyers to avoid a loss if they exercise. For a call, it is the strike price plus the premium paid. For a put, it is the strike price minus the premium paid."
        }
      },
      {
        "_index": "hugging-face-embeddings1",
        "_id": "VzEfo44BiUQvMpPgT20E",
        "_score": 0.6034223,
        "_source": {
          "id": 2173417,
          "content": "How do you find the area of a circle? Can you measure the area of a circle and use that to find a value for Pi?"
        }
      },
      (...)
    ]
 GET openai-embeddings/_search {
  "knn": {
    "field": "content_embedding",
    "query_vector_builder": {
      "text_embedding": {
        "model_id": "openai_embeddings",
        "model_text": "Calculate fuel cost"
      }
    },
    "k": 10,
    "num_candidates": 100
  },
  "_source": [
    "id",
    "content"
  ]
}

结果,您会收到与 openai-embeddings 索引中与查询的含义最接近的前 10 个文档,这些文档按它们与查询的接近程度排序

"hits": [
      {
        "_index": "openai-embeddings",
        "_id": "DDd5OowBHxQKHyc3TDSC",
        "_score": 0.83704096,
        "_source": {
          "id": 862114,
          "body": "How to calculate fuel cost for a road trip. By Tara Baukus Mello • Bankrate.com. Dear Driving for Dollars, My family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost.It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes.y family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost. It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes."
        }
      },
      {
        "_index": "openai-embeddings",
        "_id": "ajd5OowBHxQKHyc3TDSC",
        "_score": 0.8345704,
        "_source": {
          "id": 820622,
          "body": "Home Heating Calculator. Typically, approximately 50% of the energy consumed in a home annually is for space heating. When deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important.This calculator can help you estimate the cost of fuel for different heating appliances.hen deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important. This calculator can help you estimate the cost of fuel for different heating appliances."
        }
      },
      {
        "_index": "openai-embeddings",
        "_id": "Djd5OowBHxQKHyc3TDSC",
        "_score": 0.8327426,
        "_source": {
          "id": 8202683,
          "body": "Fuel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel.If you are paying $4 per gallon, the trip would cost you $200.Most boats have much larger gas tanks than cars.uel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel."
        }
      },
      (...)
    ]
 GET azure-openai-embeddings/_search {
  "knn": {
    "field": "content_embedding",
    "query_vector_builder": {
      "text_embedding": {
        "model_id": "azure_openai_embeddings",
        "model_text": "Calculate fuel cost"
      }
    },
    "k": 10,
    "num_candidates": 100
  },
  "_source": [
    "id",
    "content"
  ]
}

结果,您会收到与 azure-openai-embeddings 索引中与查询的含义最接近的前 10 个文档,这些文档按它们与查询的接近程度排序

"hits": [
      {
        "_index": "azure-openai-embeddings",
        "_id": "DDd5OowBHxQKHyc3TDSC",
        "_score": 0.83704096,
        "_source": {
          "id": 862114,
          "body": "How to calculate fuel cost for a road trip. By Tara Baukus Mello • Bankrate.com. Dear Driving for Dollars, My family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost.It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes.y family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost. It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes."
        }
      },
      {
        "_index": "azure-openai-embeddings",
        "_id": "ajd5OowBHxQKHyc3TDSC",
        "_score": 0.8345704,
        "_source": {
          "id": 820622,
          "body": "Home Heating Calculator. Typically, approximately 50% of the energy consumed in a home annually is for space heating. When deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important.This calculator can help you estimate the cost of fuel for different heating appliances.hen deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important. This calculator can help you estimate the cost of fuel for different heating appliances."
        }
      },
      {
        "_index": "azure-openai-embeddings",
        "_id": "Djd5OowBHxQKHyc3TDSC",
        "_score": 0.8327426,
        "_source": {
          "id": 8202683,
          "body": "Fuel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel.If you are paying $4 per gallon, the trip would cost you $200.Most boats have much larger gas tanks than cars.uel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel."
        }
      },
      (...)
    ]
 GET azure-ai-studio-embeddings/_search {
  "knn": {
    "field": "content_embedding",
    "query_vector_builder": {
      "text_embedding": {
        "model_id": "azure_ai_studio_embeddings",
        "model_text": "Calculate fuel cost"
      }
    },
    "k": 10,
    "num_candidates": 100
  },
  "_source": [
    "id",
    "content"
  ]
}

结果,您会收到与 azure-ai-studio-embeddings 索引中与查询的含义最接近的前 10 个文档,这些文档按它们与查询的接近程度排序

"hits": [
      {
        "_index": "azure-ai-studio-embeddings",
        "_id": "DDd5OowBHxQKHyc3TDSC",
        "_score": 0.83704096,
        "_source": {
          "id": 862114,
          "body": "How to calculate fuel cost for a road trip. By Tara Baukus Mello • Bankrate.com. Dear Driving for Dollars, My family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost.It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes.y family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost. It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes."
        }
      },
      {
        "_index": "azure-ai-studio-embeddings",
        "_id": "ajd5OowBHxQKHyc3TDSC",
        "_score": 0.8345704,
        "_source": {
          "id": 820622,
          "body": "Home Heating Calculator. Typically, approximately 50% of the energy consumed in a home annually is for space heating. When deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important.This calculator can help you estimate the cost of fuel for different heating appliances.hen deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important. This calculator can help you estimate the cost of fuel for different heating appliances."
        }
      },
      {
        "_index": "azure-ai-studio-embeddings",
        "_id": "Djd5OowBHxQKHyc3TDSC",
        "_score": 0.8327426,
        "_source": {
          "id": 8202683,
          "body": "Fuel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel.If you are paying $4 per gallon, the trip would cost you $200.Most boats have much larger gas tanks than cars.uel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel."
        }
      },
      (...)
    ]
 GET google-vertex-ai-embeddings/_search {
  "knn": {
    "field": "content_embedding",
    "query_vector_builder": {
      "text_embedding": {
        "model_id": "google_vertex_ai_embeddings",
        "model_text": "Calculate fuel cost"
      }
    },
    "k": 10,
    "num_candidates": 100
  },
  "_source": [
    "id",
    "content"
  ]
}

结果,您会收到与 mistral-embeddings 索引中与查询的含义最接近的前 10 个文档,这些文档按它们与查询的接近程度排序

"hits": [
      {
        "_index": "google-vertex-ai-embeddings",
        "_id": "Ryv0nZEBBFPLbFsdCbGn",
        "_score": 0.86815524,
        "_source": {
          "id": 3041038,
          "content": "For example, the cost of the fuel could be 96.9, the amount could be 10 pounds, and the distance covered could be 80 miles. To convert between Litres per 100KM and Miles Per Gallon, please provide a value and click on the required button.o calculate how much fuel you'll need for a given journey, please provide the distance in miles you will be covering on your journey, and the estimated MPG of your vehicle. To work out what MPG you are really getting, please provide the cost of the fuel, how much you spent on the fuel, and how far it took you."
        }
      },
      {
        "_index": "google-vertex-ai-embeddings",
        "_id": "w4j0nZEBZ1nFq1oiHQvK",
        "_score": 0.8676357,
        "_source": {
          "id": 1541469,
          "content": "This driving cost calculator takes into consideration the fuel economy of the vehicle that you are travelling in as well as the fuel cost. This road trip gas calculator will give you an idea of how much would it cost to drive before you actually travel.his driving cost calculator takes into consideration the fuel economy of the vehicle that you are travelling in as well as the fuel cost. This road trip gas calculator will give you an idea of how much would it cost to drive before you actually travel."
        }
      },
      {
        "_index": "google-vertex-ai-embeddings",
        "_id": "Hoj0nZEBZ1nFq1oiHQjJ",
        "_score": 0.80510974,
        "_source": {
          "id": 7982559,
          "content": "What's that light cost you? 1  Select your electric rate (or click to enter your own). 2  You can calculate results for up to four types of lights. 3  Select the type of lamp (i.e. 4  Select the lamp wattage (lamp lumens). 5  Enter the number of lights in use. 6  Select how long the lamps are in use (or click to enter your own; enter hours on per year). 7  Finally, ..."
        }
      },
      (...)
    ]
 GET mistral-embeddings/_search {
  "knn": {
    "field": "content_embedding",
    "query_vector_builder": {
      "text_embedding": {
        "model_id": "mistral_embeddings",
        "model_text": "Calculate fuel cost"
      }
    },
    "k": 10,
    "num_candidates": 100
  },
  "_source": [
    "id",
    "content"
  ]
}

结果,您会收到与 mistral-embeddings 索引中与查询的含义最接近的前 10 个文档,这些文档按它们与查询的接近程度排序

"hits": [
      {
        "_index": "mistral-embeddings",
        "_id": "DDd5OowBHxQKHyc3TDSC",
        "_score": 0.83704096,
        "_source": {
          "id": 862114,
          "body": "How to calculate fuel cost for a road trip. By Tara Baukus Mello • Bankrate.com. Dear Driving for Dollars, My family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost.It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes.y family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost. It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes."
        }
      },
      {
        "_index": "mistral-embeddings",
        "_id": "ajd5OowBHxQKHyc3TDSC",
        "_score": 0.8345704,
        "_source": {
          "id": 820622,
          "body": "Home Heating Calculator. Typically, approximately 50% of the energy consumed in a home annually is for space heating. When deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important.This calculator can help you estimate the cost of fuel for different heating appliances.hen deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important. This calculator can help you estimate the cost of fuel for different heating appliances."
        }
      },
      {
        "_index": "mistral-embeddings",
        "_id": "Djd5OowBHxQKHyc3TDSC",
        "_score": 0.8327426,
        "_source": {
          "id": 8202683,
          "body": "Fuel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel.If you are paying $4 per gallon, the trip would cost you $200.Most boats have much larger gas tanks than cars.uel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel."
        }
      },
      (...)
    ]
 GET amazon-bedrock-embeddings/_search {
  "knn": {
    "field": "content_embedding",
    "query_vector_builder": {
      "text_embedding": {
        "model_id": "amazon_bedrock_embeddings",
        "model_text": "Calculate fuel cost"
      }
    },
    "k": 10,
    "num_candidates": 100
  },
  "_source": [
    "id",
    "content"
  ]
}

结果,您会收到与 amazon-bedrock-embeddings 索引中与查询的含义最接近的前 10 个文档,这些文档按它们与查询的接近程度排序

"hits": [
      {
        "_index": "amazon-bedrock-embeddings",
        "_id": "DDd5OowBHxQKHyc3TDSC",
        "_score": 0.83704096,
        "_source": {
          "id": 862114,
          "body": "How to calculate fuel cost for a road trip. By Tara Baukus Mello • Bankrate.com. Dear Driving for Dollars, My family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost.It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes.y family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost. It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes."
        }
      },
      {
        "_index": "amazon-bedrock-embeddings",
        "_id": "ajd5OowBHxQKHyc3TDSC",
        "_score": 0.8345704,
        "_source": {
          "id": 820622,
          "body": "Home Heating Calculator. Typically, approximately 50% of the energy consumed in a home annually is for space heating. When deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important.This calculator can help you estimate the cost of fuel for different heating appliances.hen deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important. This calculator can help you estimate the cost of fuel for different heating appliances."
        }
      },
      {
        "_index": "amazon-bedrock-embeddings",
        "_id": "Djd5OowBHxQKHyc3TDSC",
        "_score": 0.8327426,
        "_source": {
          "id": 8202683,
          "body": "Fuel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel.If you are paying $4 per gallon, the trip would cost you $200.Most boats have much larger gas tanks than cars.uel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel."
        }
      },
      (...)
    ]
 GET alibabacloud-ai-search-embeddings/_search {
  "knn": {
    "field": "content_embedding",
    "query_vector_builder": {
      "text_embedding": {
        "model_id": "alibabacloud_ai_search_embeddings",
        "model_text": "Calculate fuel cost"
      }
    },
    "k": 10,
    "num_candidates": 100
  },
  "_source": [
    "id",
    "content"
  ]
}

因此,您会收到与查询语义最接近的 10 个文档,这些文档来自 alibabacloud-ai-search-embeddings 索引,并按照与查询的接近程度排序。

"hits": [
      {
        "_index": "alibabacloud-ai-search-embeddings",
        "_id": "DDd5OowBHxQKHyc3TDSC",
        "_score": 0.83704096,
        "_source": {
          "id": 862114,
          "body": "How to calculate fuel cost for a road trip. By Tara Baukus Mello • Bankrate.com. Dear Driving for Dollars, My family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost.It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes.y family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost. It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes."
        }
      },
      {
        "_index": "alibabacloud-ai-search-embeddings",
        "_id": "ajd5OowBHxQKHyc3TDSC",
        "_score": 0.8345704,
        "_source": {
          "id": 820622,
          "body": "Home Heating Calculator. Typically, approximately 50% of the energy consumed in a home annually is for space heating. When deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important.This calculator can help you estimate the cost of fuel for different heating appliances.hen deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important. This calculator can help you estimate the cost of fuel for different heating appliances."
        }
      },
      {
        "_index": "alibabacloud-ai-search-embeddings",
        "_id": "Djd5OowBHxQKHyc3TDSC",
        "_score": 0.8327426,
        "_source": {
          "id": 8202683,
          "body": "Fuel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel.If you are paying $4 per gallon, the trip would cost you $200.Most boats have much larger gas tanks than cars.uel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel."
        }
      },
      (...)
    ]

您还可以使用 Elasticsearch Python 客户端以交互式 Colab notebook 格式找到教程。

© . All rights reserved.