AIxiv專欄是本站發布學術、技術內容的欄位。過去數年,本站AIxiv專欄接收通報了2,000多篇內容,涵蓋全球各大專院校與企業的頂尖實驗室,有效促進了學術交流與傳播。如果您有優秀的工作想要分享,歡迎投稿或聯絡報道。投稿信箱:liyazhou@jiqizhixin.com;zhaoyunfeng@jiqizhixin.com
本文作者是來自 OpenSearch 中國研發團隊的機器學習負責人楊揚博士以及機器學習工程師志超志超和管聰。 OpenSearch 是一個由亞馬遜雲端科技發起的純開源搜尋和即時分析引擎專案。目前軟體超過 5 億下載量,社群在全球擁有 70 個以上的企業合作夥伴。
Relevance Demo
吧OpenSearch 中可以採用原生的Lucene 索引去儲存文檔稀疏編碼。相較於 k-NN 搜尋引擎,原生的 Luence 引擎會更加輕便,佔用的資源也較少。 下表展示了採用 Lucene 進行文本匹配,採用 k-NN 引擎存儲稠密編碼以及採用 Lucene 存儲稀疏編碼的磁碟消耗以及運行時內存(runtime RAM)消耗的比較。
根據BEIR 文章中提及的,由於目前絕大部分的稠密編碼模型都是基於MSMARCO 資料集上精調(fine-tune)得到,模型在該資料集上表現非常優越。然而在其他的 BEIR 的資料集上進行 zero-shot 的測試時,稠密編碼模型在大約有 60%~70% 的資料集上的相關性無法超越 BM25。這一點也可以從我們自己復現的對比實驗中間看出(見下表)。
用5 步在OpenSearch 中搭建Neural Sparse語意檢索應用
PUT /_cluster/settings{"transient" : {"plugins.ml_commons.allow_registering_model_via_url" : true,"plugins.ml_commons.only_run_on_ml_node" : false,"plugins.ml_commons.native_memory_threshold" : 99}}
Opensearch 目前開源了 3 個模型。相關註冊資訊都可以在官方文件中取得。我們以amazon/neural-sparse/opensearch-neural-sparse-encoding-v1 為例,首先使用register API 來註冊:
POST /_plugins/_ml/models/_register?deploy=true{ "name": "amazon/neural-sparse/opensearch-neural-sparse-encoding-v1", "version": "1.0.1", "model_format": "TORCH_SCRIPT"}在集群的返回中,可以看到task_id
{"task_id": "<task_id>","status": "CREATED"}
GET /_plugins/_ml/tasks/
{"model_id": "<model_id>","task_type": "REGISTER_MODEL","function_name": "SPARSE_TOKENIZE","state": "COMPLETED","worker_node": ["wubXZX7xTIC7RW2z8nzhzw"], "create_time":1701390988405,"last_update_time": 1701390993724,"is_async": true}在API 回傳中,我們可以拿到具體的model_id:
PUT /_ingest/pipeline/neural-sparse-pipeline{ "description": "An example neural sparse encoding pipeline", "processors" : [ { "sparse_encoding": { "model_id": "<model_id>", "field_map": { "passage_text": "passage_embedding" } } } ]}
PUT /_search/pipeline/two_phase_search_pipeline{ "request_processors": [ { "neural_sparse_two_phase_processor": { "tag": "neural-sparse", "description": "This processor is making two-phase processor." } } ]}如果需要開啟兩階段加速功能(非必需功能),則需要建立一個兩階段搜尋管線,並在索引建立之後設定為默認的搜尋管線。 建立一個預設參數的兩階段加速搜尋管線方式如下,更詳細的參數設定和意義請參考 2.15 及以後版本的 OpenSearch 官方文件。
PUT /my-neural-sparse-index{ "settings": { "ingest":{ "default_pipeline":"neural-sparse-pipeline" }, "search":{ "default_pipeline":"two_phase_search_pipeline" } }, "mappings": { "properties": { "passage_embedding": { "type": "rank_features" }, "passage_text": { "type": "text" } } }}
4. 設定索引
🎜神经稀疏搜索利用 rank_features 字段类型来存储编码得到的词元和相对应的权重。索引将使用上述预处理器来编码文本。我们可以按以下方式创建索一个包含两阶段搜索加速管线的索引(如果不想开启此功能,可把 `two_phase_search_pipeline` 替换为 `_none` 或删除 `settings.search` 这一配置单元)。
PUT /my-neural-sparse-index{ "settings": { "ingest":{ "default_pipeline":"neural-sparse-pipeline" }, "search":{ "default_pipeline":"two_phase_search_pipeline" } }, "mappings": { "properties": { "passage_embedding": { "type": "rank_features" }, "passage_text": { "type": "text" } } }}
PUT /my-neural-sparse-index/_doc/{ "passage_text": "Hello world"}
在索引中进行稀疏语义搜索的接口如下,将
GET my-neural-sparse-index/_search{ "query":{ "neural_sparse":{ "passage_embedding":{ "query_text": "Hi world", "model_id": <model_id> } } }}
以上是亞馬遜雲端創新「神經稀疏檢索」:只需要文字匹配就能實現語意搜索的詳細內容。更多資訊請關注PHP中文網其他相關文章!