Elasticsearch 开放推理 API 增加对 IBM watsonx.ai rerank 模型的支持

作者:来自 Elastic Saikat Sarkar

探索在构建 Elasticsearch 向量数据库中的搜索体验时如何使用 IBM watsonx™ reranking。

Elasticsearch 原生集成了业界领先的生成式 AI 工具和提供商。你可以观看我们的网络研讨会,了解如何超越 RAG 基础,或如何在 Elastic Vector Database 上构建可用于生产的应用。

为了构建最适合你用例的搜索解决方案,现在就开始免费的云试用,或在本地机器上体验 Elastic。


Elastic 于 2024 年 12 月发布了 Elastic Rerank,带来了强大的语义搜索能力,无需重新索引即可实现高相关性、卓越性能和高效率。Elastic 提供的核心功能现更加灵活,开发者可以使用来自 Cohere、Vertex AI、Hugging Face、Jina AI,以及现在的 IBM watsonx.ai 的自有模型。借助开放的 Inference API,你可以按需集成、测试并优化 reranking。

除了支持 IBM watsonx™ Slate 嵌入模型外,Elasticsearch 向量数据库还为 watsonx Assistant 提供对话式搜索能力,并通过语义 reranking 提升答案质量。

Reranking 通过先进的评分方法对最相关文档进行优先排序,从而优化大语言模型的响应。这种多阶段检索方式可适用于无需重新索引或重映射的数据集。

IBM watsonx 提供高质量的 reranker 模型,能根据查询相关性准确评分和排序段落,帮助优化搜索结果的精度。这些模型增强了语义搜索、文档对比等任务,是构建 AI 驱动检索系统中高相关性答案的关键。

在本博客中,我们将探索在 Elasticsearch 向量数据库中使用 IBM watsonx™ reranking 的方法,通过语义方式重新排序搜索结果,让你获得更精准、更有上下文的答案,而无需更改已有索引。

重新排序如何打造强大的搜索体验

语义重新排序至关重要,因为用户期望最好的答案出现在最上方,而生成式 AI 模型也需要准确的结果来避免生成错误信息。语义重新排序提供一致的评分,确保 AI 模型使用最相关的文档,并实现有效的截断点以防止幻觉。

前提条件与推理端点创建

创建一个 Elasticsearch Serverless 项目

Elasticsearch Cloud Serverless 提供快速的查询执行和与开放 Inference API 的无缝集成,非常适合在无需基础设施负担的情况下部署重新排序。

在 IBM Cloud 中生成 API 密钥

前往 IBM watsonx.ai Cloud 并使用你的凭证登录。你将进入欢迎页面。

  • 进入 API 密钥页面。
  • 创建一个 API 密钥。

Elasticsearch 中的步骤

在 Kibana 的 DevTools 中,使用 watsonxai 服务创建一个用于重新排序的推理端点。此示例使用 IBM 支持的 MS Marco MiniLM L-12 v2 模型,以确保段落检索的高相关性。

PUT _inference/rerank/ibm_watsonx_rerank
{
    "service": "watsonxai",
    "service_settings": {
        "api_key": "<api_key>",
        "url": "xxx.ml.cloud.ibm.com",
        "model_id": "cross-encoder/ms-marco-minilm-l-12-v2",
        "project_id": "<project_id>",
        "api_version": "2024-05-02"
    }
}

成功创建推理端点后,你将收到以下响应:

{
  "inference_id": "ibm_watsonx_rerank",
  "task_type": "rerank",
  "service": "watsonxai",
  "service_settings": {
    "url": "xxx.ml.cloud.ibm.com",
    "api_version": "2024-05-02",
    "model_id": "cross-encoder/ms-marco-minilm-l-12-v2",
    "project_id": "<project_id>",
    "rate_limit": {
      "requests_per_minute": 120
    }
  }
}

现在让我们创建一个索引。

PUT quotes-index
{
  "mappings": { 
    "properties": {
      "movie_title": {
        "type": "text"
      },
      "quotes": {
        "type": "text"
      }
    }
  }
}

接下来,将数据插入到已创建的索引中。

PUT quotes-index/_doc/1
{
  "movie_title": "The Big Lebowski",
  "quotes": [
    "That rug really tied the room together",
    "Yeah, well, you know, that's just like, uh, your opinion, man"
  ]
}

PUT quotes-index/_doc/2
{
  "movie_title": "Star Wars",
  "quotes": [
    "These are not the droids you're looking for",
    "I have a bad feeling about this",
    "Do. Or do not. There is no try."
  ]
}

PUT quotes-index/_doc/3
{
  "movie_title": "The Avengers",
  "quotes": [
    "What's the matter, scared of a little lightning?",
    "Superheroes? In New York? Give me a break!"
  ]
}

接下来,让我们使用 text_similarity_reranker 检索器进行搜索。它通过使用机器学习模型,根据与指定推理文本的语义相似度重新排序文档,从而提升搜索结果。

该检索器帮助你在一次 API 调用中配置搜索结果的检索和重新排序。

POST quotes-index/_search
{
  "retriever": {
    "text_similarity_reranker": {
      "retriever": {
        "standard": {
          "query": {
            "match": {
              "quotes": "feeling lightning"
            }
          }
        }
      },
      "field": "quotes",
      "inference_id": "ibm_watsonx_rerank",
      "inference_text": "feeling lightning",
      "rank_window_size": 50
    }
  },
  "size": 50
}

接下来,让我们验证返回的结果。

{
  "took": 718,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 2,
      "relation": "eq"
    },
    "max_score": 0.003072956,
    "hits": [
      {
        "_index": "quotes-index",
        "_id": "3",
        "_score": 0.003072956,
        "_source": {
          "movie_title": "The Avengers",
          "quotes": [
            "What's the matter, scared of a little lightning?",
            "Superheroes? In New York? Give me a break!"
          ]
        }
      },
      {
        "_index": "quotes-index",
        "_id": "2",
        "_score": 0.000024473073,
        "_source": {
          "movie_title": "Star Wars",
          "quotes": [
            "These are not the droids you're looking for",
            "I have a bad feeling about this",
            "Do. Or do not. There is no try."
          ]
        }
      }
    ]
  }
}

段落现在被重新排序,得分最高的段落排在最前面。在此示例中,基于词匹配的词汇检索最初选中了《The Avengers - 复仇者联盟》(_id: 3)和《Star Wars - 星球大战》(_id: 2),因为一个段落包含 “lightning”,另一个包含 “feeling”。这种方法只考虑表面重叠和关键词。

IBM watsonx.ai rerank 根据上下文重新评估结果,将《复仇者联盟》排在更前面,因为“lightning”与查询“feeling lightning”直接相关。这表明通过优先考虑语义而非简单关键词匹配,reranking 能确保更相关的搜索结果。

今天就试试结合 watsonx 和 Elasticsearch 的语义重新排序吧

借助 IBM watsonx™ rerank 模型的集成,Elasticsearch 开放推理 API 继续为开发者提供更强大、更灵活的 AI 驱动搜索体验能力。探索更多可在 watsonx.ai 中使用的支持编码器基础模型

此外,立即使用 IBM watsonx Assistant 的新对话式搜索功能和 IBM watsonx Discovery。访问 IBM watsonx Discovery,了解基于 Elasticsearch 的这一新能力。你可以按照这些步骤完成与 IBM watsonx Assistant 的设置和集成。

原文:Elasticsearch open inference API adds support for IBM watsonx.ai rerank models - Elasticsearch Labs

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值