国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Elasticsearch:使用 ELSER v2 進行語義搜索

這篇具有很好參考價值的文章主要介紹了Elasticsearch:使用 ELSER v2 進行語義搜索。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

Elasticsearch:使用 ELSER v2 進行語義搜索,Elasticsearch,AI,Elastic,elasticsearch,大數(shù)據(jù),搜索引擎,人工智能,全文檢索

在我之前的文章 “Elasticsearch:使用 ELSER 進行語義搜索”,我們展示了如何使用 ELESR v1 來進行語義搜索。在使用 ELSER 之前,我們必須注意的是:

重要:雖然 ELSER V2 已正式發(fā)布,但 ELSER V1 仍處于 [預(yù)覽] 狀態(tài)。此功能處于技術(shù)預(yù)覽階段,可能會在未來版本中更改或刪除。 Elastic 將努力解決任何問題,但技術(shù)預(yù)覽版中的功能不受官方 GA 功能的支持 SLA 的約束,并將保留在技術(shù)預(yù)覽版中。

也就是說 ELSER v1 不建議在生產(chǎn)環(huán)境中使用。在生產(chǎn)的環(huán)境中,我們建議使用 ELSER v2。由于兩個版本中的使用方法稍有不同。在今天的文章中,我們以 ELSER v2 為例來進行展示。

簡介

Elastic Learned Sparse EncodeR(或 ELSER)是由 Elastic 訓練的 NLP 模型,使你能夠使用稀疏向量表示來執(zhí)行語義搜索。 語義搜索不是根據(jù)搜索詞進行字面匹配,而是根據(jù)搜索查詢的意圖和上下文含義來檢索結(jié)果。

本教程中的說明向你展示如何使用 ELSER 對數(shù)據(jù)執(zhí)行語義搜索。

注意:在使用 ELSER 進行語義搜索期間,僅考慮每個字段提取的前 512 個標記。 請參閱此頁面了解更多信息。

要求

要使用 ELSER 執(zhí)行語義搜索,你必須在集群中部署 NLP 模型。 請參閱 ELSER 文檔以了解如何下載和部署模型。

注意:如果關(guān)閉部署自動擴展,則 Elasticsearch Service 中用于部署和使用 ELSER 模型的最小專用 ML 節(jié)點大小為 4 GB。 建議打開自動擴展功能,因為它允許你的部署根據(jù)需求動態(tài)調(diào)整資源。 通過使用更多分配或每次分配更多線程可以實現(xiàn)更好的性能,這需要更大的 ML 節(jié)點。 自動擴展可在需要時提供更大的節(jié)點。 如果關(guān)閉自動擴展,你必須自己提供適當大小的節(jié)點。

創(chuàng)建索引映射

首先,必須創(chuàng)建目標索引的映射 - 包含模型根據(jù)你的文本創(chuàng)建的 token 的索引。 目標索引必須具有?sparse_vector?或?rank_features?字段類型的字段才能對 ELSER 輸出進行索引。

注意:ELSER 輸出必須攝取到具有 sparse_vector 或? rank_features 字段類型的字段中。 否則,Elasticsearch 會將 token 權(quán)重對解釋為文檔中的大量字段。 如果你收到類似于 “Limit of total fields [1000] has been exceeded while adding new fields” 的錯誤,則 ELSER 輸出字段未正確映射,并且其字段類型不同于 sparse_vector 或 rank_features。

PUT my-index
{
  "mappings": {
    "properties": {
      "content_embedding": { 
        "type": "sparse_vector" 
      },
      "content": { 
        "type": "text" 
      }
    }
  }
}
  • content_embedding 包含生成的 token 的字段的名稱。 必須在下一步的推理管道配置中引用它。
  • sparse_vector 定義字段是 sparse_vector 字段。
  • 用于創(chuàng)建稀疏向量表示的字段的名稱。 在此示例中,字段的名稱是 content。 必須在下一步的推理管道配置中引用它。
  • text 定義字段類型為文本。

使用推理處理器創(chuàng)建攝取管道

創(chuàng)建帶有 inference processor 的 ingest pipeline,以使用 ELSER 來推理管道中攝取的數(shù)據(jù)。

PUT _ingest/pipeline/elser-v2-test
{
  "processors": [
    {
      "inference": {
        "model_id": ".elser_model_2",
        "input_output": [ 
          {
            "input_field": "content",
            "output_field": "content_embedding"
          }
        ]
      }
    }
  ]
}
  • input_output:配置對象,定義推理過程的輸入字段和包含推理結(jié)果的輸出字段。

加載數(shù)據(jù)

在此步驟中,你將加載稍后在推理攝取管道中使用的數(shù)據(jù),以從中提取 token。

使用 msmarco-passagetest2019-top1000 數(shù)據(jù)集,該數(shù)據(jù)集是 MS MARCO Passage Ranking 數(shù)據(jù)集的子集。 它由 200 個查詢組成,每個查詢都附有相關(guān)文本段落的列表。 所有獨特的段落及其 ID 均已從該數(shù)據(jù)集中提取并編譯到 tsv 文件中。

下載文件并使用機器學習 UI 中的數(shù)據(jù)可視化工具將其上傳到集群。 將名稱 id 分配給第一列,將內(nèi)容分配給第二列。 索引名稱是 test-data。 上傳完成后,你可以看到名為 test-data 的索引,其中包含 182469 個文檔。

關(guān)于如何加載這個數(shù)據(jù),請詳細閱讀文章 “Elasticsearch:如何部署 NLP:文本嵌入和向量搜索”。

Elasticsearch:使用 ELSER v2 進行語義搜索,Elasticsearch,AI,Elastic,elasticsearch,大數(shù)據(jù),搜索引擎,人工智能,全文檢索

Elasticsearch:使用 ELSER v2 進行語義搜索,Elasticsearch,AI,Elastic,elasticsearch,大數(shù)據(jù),搜索引擎,人工智能,全文檢索

Elasticsearch:使用 ELSER v2 進行語義搜索,Elasticsearch,AI,Elastic,elasticsearch,大數(shù)據(jù),搜索引擎,人工智能,全文檢索

Elasticsearch:使用 ELSER v2 進行語義搜索,Elasticsearch,AI,Elastic,elasticsearch,大數(shù)據(jù),搜索引擎,人工智能,全文檢索

Elasticsearch:使用 ELSER v2 進行語義搜索,Elasticsearch,AI,Elastic,elasticsearch,大數(shù)據(jù),搜索引擎,人工智能,全文檢索

我們可以在 Discover 中進行查看:

Elasticsearch:使用 ELSER v2 進行語義搜索,Elasticsearch,AI,Elastic,elasticsearch,大數(shù)據(jù),搜索引擎,人工智能,全文檢索

Elasticsearch:使用 ELSER v2 進行語義搜索,Elasticsearch,AI,Elastic,elasticsearch,大數(shù)據(jù),搜索引擎,人工智能,全文檢索

通過推理攝取管道攝取數(shù)據(jù)

通過使用 ELSER 作為推理模型的推理管道重新索引數(shù)據(jù),從文本創(chuàng)建標記。

POST _reindex?wait_for_completion=false
{
  "source": {
    "index": "test-data",
    "size": 50 
  },
  "dest": {
    "index": "my-index",
    "pipeline": "elser-v2-test"
  }
}
  • Reindex 的默認批量大小為 1000。將大小減小到較小的數(shù)字可以使重新索引過程的更新更快,使你能夠密切跟蹤進度并盡早發(fā)現(xiàn)錯誤。

Elasticsearch:使用 ELSER v2 進行語義搜索,Elasticsearch,AI,Elastic,elasticsearch,大數(shù)據(jù),搜索引擎,人工智能,全文檢索

該調(diào)用返回一個任務(wù) ID 以監(jiān)控進度:

Elasticsearch:使用 ELSER v2 進行語義搜索,Elasticsearch,AI,Elastic,elasticsearch,大數(shù)據(jù),搜索引擎,人工智能,全文檢索

我們等到 completed 的狀態(tài)變?yōu)?true:

Elasticsearch:使用 ELSER v2 進行語義搜索,Elasticsearch,AI,Elastic,elasticsearch,大數(shù)據(jù),搜索引擎,人工智能,全文檢索

Elasticsearch:使用 ELSER v2 進行語義搜索,Elasticsearch,AI,Elastic,elasticsearch,大數(shù)據(jù),搜索引擎,人工智能,全文檢索

你還可以打開訓練模型 UI,選擇 ELSER 下的 Pipelines 選項卡來跟蹤進度。

Elasticsearch:使用 ELSER v2 進行語義搜索,Elasticsearch,AI,Elastic,elasticsearch,大數(shù)據(jù),搜索引擎,人工智能,全文檢索

使用 text_expansion 查詢進行語義搜索

要執(zhí)行語義搜索,請使用 text_expansion 查詢,并提供查詢文本和 ELSER 模型 ID。 下面的示例使用查詢文本 “How to avoid muscle soreness after running?”,content_embedding 字段包含生成的 ELSER 輸出:

GET my-index/_search
{
  "_source": false,
  "fields": [
    "content"
  ], 
   "query":{
      "text_expansion":{
         "content_embedding":{
            "model_id":".elser_model_2",
            "model_text":"How to avoid muscle soreness after running?"
         }
      }
   }
}

結(jié)果是 my-index 索引中按相關(guān)性排序的與你的查詢文本含義最接近的前 10 個文檔。 結(jié)果還包含為每個相關(guān)搜索結(jié)果提取的 token 及其權(quán)重。 標記是捕獲相關(guān)性的學習關(guān)聯(lián),它們不是同義詞。 要了解有關(guān) token 是什么的更多信息,請參閱此頁面。 可以從源中排除 token,請參閱下面的章節(jié)以了解更多信息。

{
  "took": 1531,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 10000,
      "relation": "gte"
    },
    "max_score": 25.669455,
    "hits": [
      {
        "_index": "my-index",
        "_id": "fd96yo0BZ-5LgFdRMD7b",
        "_score": 25.669455,
        "fields": {
          "content": [
            "There are a few foods and food groups that will help to fight inflammation and delayed onset muscle soreness (both things that are inevitable after a long, hard workout) when you incorporate them into your postworkout eats, whether immediately after your run or at a meal later in the day. Advertisement. Advertisement."
          ]
        }
      },
      {
        "_index": "my-index",
        "_id": "nt96yo0BZ-5LgFdRLQCy",
        "_score": 23.388044,
        "fields": {
          "content": [
            "What so many out there do not realize is the importance of what you do after you work out. You may have done the majority of the work, but how you treat your body in the minutes and hours after you exercise has a direct effect on muscle soreness, muscle strength and growth, and staying hydrated. Cool Down. After your last exercise, your workout is not over. The first thing you need to do is cool down. Even if running was all that you did, you still should do light cardio for a few minutes. This brings your heart rate down at a slow and steady pace, which helps you avoid feeling sick after a workout."
          ]
        }
      },
      {
        "_index": "my-index",
        "_id": "ot96yo0BZ-5LgFdRLzD0",
        "_score": 22.550915,
        "fields": {
          "content": [
            "If you’ve been exercising more, you may be suffering from the aches and pains of having overdone it at the gym. I’ve been there. Making sure your workout is challenging without overdoing it is one way to prevent muscle soreness. But research also points to some foods and beverages that can help ward off and minimize exercise-related muscle soreness, which we’ve reported on in EatingWell Magazine. Related: Foods to Eat to Improve Your Workout Post-Workout Breakfast Recipes What to Drink Before, During and After You Exercise. Blueberries."
          ]
        }
      }
 ...

將語義搜索與其他查詢相結(jié)合

你可以將 text_expansion 與復合查詢中的其他查詢結(jié)合起來。 例如,在布爾查詢或全文查詢中使用過濾子句,該查詢可能會或可能不會使用與 text_expansion 查詢相同的查詢文本。 這使你能夠合并兩個查詢的搜索結(jié)果。

text_expansion 查詢的搜索命中得分往往高于其他 Elasticsearch 查詢。 可以通過使用 boost 參數(shù)增加或減少每個查詢的相關(guān)性分數(shù)來對這些分數(shù)進行正則化。 當存在不太相關(guān)的結(jié)果時,text_expansion 查詢的召回率可能很高。 使用 min_score 參數(shù)來修剪那些不太相關(guān)的文檔。

GET my-index/_search
{
  "query": {
    "bool": { 
      "should": [
        {
          "text_expansion": {
            "content_embedding": {
              "model_text": "How to avoid muscle soreness after running?",
              "model_id": ".elser_model_2",
              "boost": 1 
            }
          }
        },
        {
          "query_string": {
            "query": "toxins",
            "boost": 4 
          }
        }
      ]
    }
  },
  "min_score": 10 
}
  • text_expansion 和 query_string 查詢都位于 bool 查詢的 should 子句中。
  • text_expansion 查詢的 boost 值為 1,這是默認值。 這意味著該查詢結(jié)果的相關(guān)性得分不會提高。
  • query_string 查詢的提升值為 4。 該查詢結(jié)果的相關(guān)性得分增加,導致它們在搜索結(jié)果中排名更高。
  • 僅顯示分數(shù)等于或高于 10 的結(jié)果。

優(yōu)化性能

通過從文檔源中排除 ELSER token 來節(jié)省磁盤空間

必須對 ELSER 生成的 token 進行索引,以便在 text_expansion 查詢中使用。 但是,沒有必要在文檔源中保留這些術(shù)語。 你可以通過使用 source exclude 映射從文檔源中刪除 ELSER 術(shù)語來節(jié)省磁盤空間。

警告:重新索引使用文檔源來填充目標索引。 一旦 ELSER 術(shù)語從源中排除,就無法通過重新索引來恢復它們。 從源中排除 token 是一種節(jié)省空間的優(yōu)化,只有在你確定將來不需要重新索引時才應(yīng)應(yīng)用該優(yōu)化! 仔細考慮這種權(quán)衡并確保從源中排除 ELSER 術(shù)語符合你的特定要求和用例,這一點很重要。 仔細查看禁用 _source 字段和從 _source 中包含/排除字段部分,以詳細了解從 _source 中排除 token 可能產(chǎn)生的后果。

可以通過以下 API 調(diào)用創(chuàng)建從 _source 字段中排除 content_embedding 的映射:

PUT my-index
{
  "mappings": {
    "_source": {
      "excludes": [
        "content_embedding"
      ]
    },
    "properties": {
      "content_embedding": {
        "type": "sparse_vector"
      },
      "content": {
        "type": "text"
      }
    }
  }
}

注意:根據(jù)你的數(shù)據(jù),使用 track_total_hits: false 時文本擴展查詢可能會更快。

更多閱讀:Elasticsearch:使用 ELSER v2 文本擴展進行語義搜索文章來源地址http://www.zghlxwxcb.cn/news/detail-835996.html

到了這里,關(guān)于Elasticsearch:使用 ELSER v2 進行語義搜索的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • Elasticsearch:使用 Transformers 和 Elasticsearch 進行語義搜索

    Elasticsearch:使用 Transformers 和 Elasticsearch 進行語義搜索

    什么語義搜索( semantic search )呢?根據(jù)搜索查詢的意圖和上下文含義(而不僅僅是)檢索結(jié)果。語義/向量搜索是一種強大的技術(shù),可以大大提高搜索結(jié)果的準確性和相關(guān)性。 與傳統(tǒng)的基于的搜索方法不同,語義搜索使用單詞的含義和上下文來理解查詢背后的意

    2024年02月08日
    瀏覽(24)
  • 使用 Elasticsearch、OpenAI 和 LangChain 進行語義搜索

    使用 Elasticsearch、OpenAI 和 LangChain 進行語義搜索

    在本教程中,我將引導您使用 Elasticsearch、OpenAI、LangChain 和 FastAPI 構(gòu)建語義搜索服務(wù)。 LangChain 是這個領(lǐng)域的新酷孩子。 它是一個旨在幫助你與大型語言模型 (LLM) 交互的庫。 LangChain 簡化了與 LLMs 相關(guān)的許多日常任務(wù),例如從文檔中提取文本或在向量數(shù)據(jù)庫中對它們建立索引

    2024年02月08日
    瀏覽(21)
  • Elasticsearch:部署 ELSER - Elastic Learned Sparse EncoderR

    Elasticsearch:部署 ELSER - Elastic Learned Sparse EncoderR

    警告 :此功能處于技術(shù)預(yù)覽階段,可能會在未來的版本中更改或刪除。 Elastic 將盡最大努力修復任何問題,但技術(shù)預(yù)覽中的功能不受官方 GA 功能的支持 SLA 約束。 Elastic Learned Sparse EncodeR - 或 ELSER - 是由 Elastic 訓練的檢索模型,使你能夠執(zhí)行語義搜索以檢索更相關(guān)的搜索結(jié)果

    2024年02月09日
    瀏覽(23)
  • Elastic 發(fā)布 Elasticsearch Relevance Engine? — 為 AI 革命提供高級搜索能力

    Elastic 發(fā)布 Elasticsearch Relevance Engine? — 為 AI 革命提供高級搜索能力

    作者:Matt Riley 今天我們將向大家介紹 Elasticsearch Relevance Engine?(ESRE?) ,這是一種創(chuàng)建高度相關(guān)的 AI 搜索應(yīng)用程序的新功能。ESRE 建立在 Elastic 在搜索領(lǐng)域的領(lǐng)導地位以及超過兩年的機器學習研究和開發(fā)基礎(chǔ)之上。Elasticsearch Relevance Engine 結(jié)合了 AI 的最佳實踐和 Elastic 的文

    2024年02月06日
    瀏覽(64)
  • Elasticsearch:升級索引以使用 ELSER 最新的模型

    Elasticsearch:升級索引以使用 ELSER 最新的模型

    在此 notebook 中,我們將看到有關(guān)如何使用 Reindex API 將索引升級到 ELSER 模型 .elser_model_2 的示例。 注意:或者,你也可以通過 update_by_query 來更新索引以使用 ELSER。 在本筆記本中,我們將看到使用 Reindex API 的示例。 我們將在本筆記本中看到的場景: 將未生成 text_expansion 字段

    2024年02月03日
    瀏覽(23)
  • Elasticsearch:如何在 Elastic 中實現(xiàn)圖片相似度搜索

    Elasticsearch:如何在 Elastic 中實現(xiàn)圖片相似度搜索

    作者:Radovan Ondas 在本文章,我們將了解如何通過幾個步驟在 Elastic 中實施相似圖像搜索。 開始設(shè)置應(yīng)用程序環(huán)境,然后導入 NLP 模型,最后完成為你的圖像集生成嵌入。 Elastic 圖像相似性搜索概覽 Elasticsearch:如何在 Elastic 中實現(xiàn)圖片相似度搜索 第一步是為你的應(yīng)用程序設(shè)

    2024年01月22日
    瀏覽(30)
  • Elasticsearch:多語言語義搜索

    Elasticsearch:多語言語義搜索

    在此示例中,我們將使用多語言嵌入模型 multilingual-e5-base 對混合語言文檔的 toy 數(shù)據(jù)集執(zhí)行搜索。 使用這個模型,我們可以通過兩種方式進行搜索: 跨語言,例如使用德語查詢來查找英語文檔 在非英語語言中,例如使用德語查詢來查找德語文檔 雖然此示例僅使用密集檢索,

    2024年02月08日
    瀏覽(26)
  • Elasticsearch:語義搜索即服務(wù)處于卓越搜索的中心

    Elasticsearch:語義搜索即服務(wù)處于卓越搜索的中心

    作者:來自 Elastic?Sherry Ger, Stephen Brown 對于許多企業(yè)來說,搜索卓越中心(center of excellence - COE)向其用戶提供搜索服務(wù),從不同的數(shù)據(jù)源中整理知識,并將搜索功能集成到其內(nèi)部和外部應(yīng)用程序中。Elasticsearch,這個 “支撐著互聯(lián)網(wǎng)上大約 90% 的搜索欄” 的分布式搜索平臺,

    2024年04月11日
    瀏覽(21)
  • Elasticsearch:使用 fuzziness 來進行搜索

    在我之前的文章 “Elasticsearch:fuzzy 搜索 (模糊搜索)”,我詳細描述了模糊搜索。盡管那篇文章已經(jīng)很詳盡了,但是還是有 auto 這個配置沒有完全覆蓋到。在今天的文章中,我們來進一步對這個進行講解一下。 Fuzziness 參數(shù)存在于某些查詢中,使用它時,你將受益于根據(jù)術(shù)

    2024年02月08日
    瀏覽(23)
  • Django中使用Elasticsearch進行搜索

    Django是一個流行的Python Web框架,Elasticsearch是一個流行的開源搜索引擎。結(jié)合Django和Elasticsearch,可以構(gòu)建一個強大的搜索引擎。 下面是如何在Django中使用Elasticsearch進行搜索的步驟: 安裝Elasticsearch和elasticsearch-py 首先,需要在本地安裝Elasticsearch和elasticsearch-py。可以通過官網(wǎng)

    2024年02月11日
    瀏覽(33)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包