本記事はこちらのブログを参考にしています。
翻訳にはアリババクラウドのModelStudio(Qwen)を使用しております。
Elasticsearch Open Inference API Adds Support for Alibaba Cloud AI Search
前回の投稿Elasticsearch Open Inference API Adds Support for Alibaba Cloud AI Searchでは、Elastic推論APIを使用してAlisの密集ベクトルモデル、疎ベクトルモデル、再ランキング、および補完を表示する方法について詳しく説明しました。その記事では、多くの英語の例を使用していましたが、Alisのモデルは中国語での表示に適しています。Elasticの標準の疎ベクトルモデルであるELSERは英語のみに対応しており、現在中国語はサポートされていません。Alisの疎ベクトルモデルはこのギャップを埋めています。疎ベクトルはそのまま使用できます。AIに詳しくない多くの開発者にとって、これは間違いなく恩恵であり、リソースの使用も非常に少ないです。詳細については、ElasticsearchのAliCloud AI Search Inference Serviceをご覧ください。
疎ベクトル
ドキュメントによると、以下のようなコマンドを使用して疎ベクトルの推論APIエンドポイントを作成します:
PUT _inference/sparse_embedding/alibabacloud_ai_search_sparse
{
"service": "alibabacloud-ai-search",
"service_settings": {
"api_key": "",
"service_id": "ops-text-sparse-embedding-001",
"host": "default-j01.platform-cn-shanghai.opensearch.aliyuncs.com",
"workspace": "default"
}
}
また、これを実行するにはAliCloudからapi_key
を取得する必要があります。上記のコマンドを実行します:
次に、以下のコマンドでテストできます(以下の情報はアドレスから取得されます):
POST _inference/alibabacloud_ai_search_sparse
{
"input": "阿里巴巴(中国)有限公司成立于2007年3月26日,法定代表人为江芳"
}
上記のコマンドの結果は以下のようになります:
上記の表示結果から、以前のElastic ELSERの出力とは異なることがわかります。ここではUnicode形式です:
上記のコマンドは以下のコマンドと同じです:
POST _inference/sparse_embedding/alibabacloud_ai_search_sparse
{
"input": "阿里巴巴(中国)有限公司成立于2007年3月26日,法定代表人为江芳"
}
Elasticsearchによって作成された各エンドポイントは、それがどのようなタイプのモデルかを自動的に検出および認識するため、パス上のsparse_embedding
は省略可能です。
密集ベクトル
同様に、以下のようなコマンドを使用して密集ベクトルの推論APIエンドポイントを作成します:
PUT _inference/text_embedding/alibabacloud_ai_search_embeddings
{
"service": "alibabacloud-ai-search",
"service_settings": {
"api_key": "",
"service_id": "ops-text-embedding-001",
"host": "default-j01.platform-cn-shanghai.opensearch.aliyuncs.com",
"workspace": "default"
}
}
上記のコマンドを実行すると、以下のようになります:
以下のようなコマンドを使用して密集ベクトルを生成できます:
POST _inference/alibabacloud_ai_search_embeddings
{
"input": "阿里巴巴(中国)有限公司成立于2007年3月26日,法定代表人为江芳"
}
密集ベクトルは浮動小数点数の配列です。生成時にスカラ量子化することも可能で、これによりメモリ消費量が削減され、検索速度が向上します。
補完
さらに、大きなモデルを検索結果に適用して補完の結果を得ることもできます。例えば、以下のようなコマンドを使用して補完の推論APIエンドポイントを生成します:
PUT _inference/completion/alibabacloud_ai_search_completion
{
"service": "alibabacloud-ai-search",
"service_settings": {
"host": "default-j01.platform-cn-shanghai.opensearch.aliyuncs.com",
"api_key": "{{API_KEY}}",
"service_id": "ops-qwen-turbo",
"workspace": "default"
}
}
以下のような例で補完を示すことができます:
POST _inference/completion/alibabacloud_ai_search_completion
{
"input": "阿里巴巴(中国)有限公司是什么时候成立的?"
}
この結果は大きなモデルと組み合わせて生成されます。大きなモデルは、訓練中に得られた結果に基づいて結果を提供します。
再ランキング
同様に、以下のようなコマンドを使用して再ランキングの推論APIエンドポイントを生成できます:
PUT _inference/rerank/alibabacloud_ai_search_rerank
{
"service": "alibabacloud-ai-search",
"service_settings": {
"api_key": "",
"service_id": "ops-bge-reranker-larger",
"host": "default-j01.platform-cn-shanghai.opensearch.aliyuncs.com",
"workspace": "default"
}
}
上記の入力では、2つの文書をリストしています。これらの2つの文書を再ランキングエンドポイントを使用して再順位付けすることができます。例えば、検索したいテキストが「阿里巴巴(中国)有限公司是什么时候成立的?」の場合、再ランキングは以下のような結果を返します:
上記の結果から、2番目の文書の方が1番目の文書よりも関連性が高いことがわかります。
RAGアプリケーション
多くの場合、組織には定期的に大量の業務データやプライベートデータが生成されます。大きなモデルの知識は生成時点でのものに制限されるため、多くの知識が大きなモデルには存在しません。大きなモデルの回答を制限しない場合、間違った答えを提供し、幻想を生む可能性があります。実際には、通常は業務
以下のコマンドで検索を行います:plaintext
GET alibaba_sparse/_search
{
query: {
semantic: {
field: inference_field,
query: when was Aliyun founded?
}
}
}
上記の検索結果は以下の通りです:
Alibaba Cloudが1位に表示されます。
2009年に設立され、本社を杭州に置くAlibaba Cloud Computing Co. Ltd(別名:Alibaba Cloud Computing Co. Ltd)は、アリババグループのデジタルテクノロジーとインテリジェンスの基盤であり、世界中の顧客に対して独自のサーバー、弾性コンピューティング、ストレージ、ネットワークセキュリティ、データベース、ビッグデータを含む全範囲のクラウドサービスを提供しています。Alibabaは2位に表示されます。
Alibaba (China) Limitedは2007年3月26日に設立され、法定代理人は江方です。
Alibaba Cloudを含む文書が1位に表示されます。これがベクトル検索と呼ばれるものです。実際には、多くの場合、ユニークな回答を得たい、あるいはその回答が推論されたものであり、元の文書ではないこともあります。このときには大規模モデルを使用する必要があります。つまり、推論エンドポイントを使用します。以下のような検索を行ってみましょう:plaintext
GET alibaba_sparse/search
{
query: {
semantic: {
field: inference_field,
query: Who is the legal person of Alibaba?
}
}
}

今回は1つの文書のみが表示されます。以下のように完成エンドポイントを使用します:plaintext
POST _inference/completion/alibabacloud_ai_search_completion
{
input: <|system|>
You are a knowledgeable person.
<|user|>
CONTEXT:
Alibaba (China) Limited was founded on March 26, 2007, legal representative Jiang Fang
QUESTION:
Who is the legal person of Alibaba?</s>
<|assistant|>
}
上記では、検索結果である「Alibaba (China) Limited was founded on March 26, 2007, legal representative Jiang Fang」を文書の一部として記録し、それと一緒に検索質問を提出します。完成エンドポイントAPIを使用して結果を確認します:
結果は「Alibabas legal representative is Jiang Fang」になります。明らかに、以前の方法(コンテキストなしでの完成)とは異なります:plaintext
POST _inference/completion/alibabacloud_ai_search_completion
{
input: Who is the legal person of Alibaba? }
このように理解できます。Elasticsearchベクトルデータベースから検索した(リアルタイムビジネスデータまたはプライベートデータ)結果を大規模モデルに提供することで、大規模モデルはこれらのコンテキストに基づいてより正確な検索結果を得ることができます。これは実際には幻覚を避けるために使用されます!プロンプトの構築方法
プロンプトの構築方法に従って、密ベクトルのインデックスを作成しましょう:plaintext
PUT alibaba_dense
{
mappings: {
properties: {
inference_field: {
type: semantic_text,
inference_id: alibabacloud_ai_search_embeddings
}
}
}
}
文書の書き込みも同じ方法で行います:plaintext
PUT alibaba_dense/_bulk
{index": {_id": 1"}}
{inference_field": Alibaba (China) Limited was founded on March 26, 2007, legal representative Jiang Fang"}
{index": {_id": 2"}}
{inference_field": Aliyun (aka: Aliyun Computing Co., Ltd.) was founded in 2009, headquartered in Hangzhou, is the digital technology and intelligence backbone of Alibaba Group, providing a full range of cloud services to customers around the world."}
この密ベクトルインデックスalibaba_denseを検索してみましょう:plaintext
GET alibaba_dense/_search
{
query: {
semantic: {
field: inference_field,
query: Who is the legal person of Alibaba? }
}
}
GET alibaba_dense/search
{
query: {
semantic: {
field: inference_field,
query: What kind of company is Aliyun? }
}
}
上記の検索結果は以下の通りです:

明らかに、Aliyunを含む文書が1位に表示されています。自動分割
semantic_textフィールドを使用すると、大きなテキストを手動で分割することなく自動的に分割することができます。これはsemantic_textの大きな利点の一つです。alibaba_dense_large_textというインデックスを作成しましょう:plaintext
PUT alibaba_dense_large_text
{
mappings: {
properties: {
inference_field: {
type: semantic_text,
inference_id: alibabacloud_ai_search_embeddings
}
}
}
}
このインデックス用に大きな文書を作成します:plaintext
PUT alibaba_dense_large_text/_doc/1
{
inference_field: "
About Alibaba Group
Alibaba Group (Alibaba Group) is a globally recognized technology company headquartered in Hangzhou, Zhejiang Province, China, founded in 1999 by Jack Ma and his team. As a technology-driven company, Alibaba has a wide range of businesses in e-commerce, cloud computing, financial technology, digital media, logistics and other fields, and has become a key player in the global Internet industry. Background and Early Development
The birth of Alibaba began in 1999, when the Internet was just emerging in China. With the vision of empowering small and medium-sized enterprises (SMEs) through the Internet, Jack Ma and his team launched Alibaba.com, a global wholesale marketplace. Initially, the platform provided SMEs with the opportunity to showcase their products and find international buyers, helping Chinese manufacturers reach out to the global market. After several years of development, Alibaba quickly emerged as the worlds leading B2B e-commerce platform. In 2003, Alibaba launched Taobao, a C2C platform for individual consumers, which quickly attracted a large number of users. With its free store” model, Taobao competed with other e-commerce platforms in a short period of time and achieved success. To enhance the user experience, Alibaba launched Alipay, a third-party payment platform, in 2004, solving the trust problem of online payment, an innovation that laid the foundation for the rapid development of e-commerce in China. Business Ecology and Strategic Layout
Alibaba has gradually built a diversified ecosystem covering e-commerce, finance, logistics and cloud computing through continuous business expansion. E-commerce
As Alibabas core business, e-commerce includes Taobao, Tmall and AliExpress. Among them, Taobao focuses on meeting the needs of individual consumers, while Tmall caters to brands and enterprises, providing high-quality goods and services. Global Express is dedicated to connecting overseas buyers with Chinese sellers, and is gaining influence in the international market. Cloud Computing and Big Data
Alibaba Cloud, the core technology division of Alibaba Group, was founded in 2009 to provide cloud computing services, artificial intelligence solutions and big data technical support. Today, Alibaba Cloud has become the worlds leading cloud service provider, supporting the digital transformation of enterprises. Financial Technology
Ant Group, the parent company of Alipay, is an important part of Alibabas fintech layout. Through Alipay, Alibaba provides users with online payment, wealth management, loans and other services, promoting the development of a cashless society in China. Logistics and Supply Chain
Founded in 2013, Cainiao Network (Cainiao) is committed to optimizing logistics efficiency and building an intelligent logistics network with global coverage. Cainiaos technology and platform capabilities enhance the speed and reliability of e-commerce logistics services. Digital Media and Entertainment
Alibaba has also been actively laying out in the digital media sector, including Youku, AliFilm and Shrimp Music, to promote the construction of a content ecosystem. In addition, the Group has further enriched its brand by investing in cultural and creative industries and expanding its sports business. Internationalization and Innovation
In recent years, Alibaba has been accelerating its pace of internationalization, aiming to become a bridge between global consumers and businesses. The Group has expanded its business in markets such as Southeast Asia, Europe and North America through mergers and acquisitions and partnerships. For example, through the acquisition of Lazada, Alibaba has enhanced its e-commerce presence in Southeast Asia. In addition, Alibaba has been actively exploring new technologies
アリババの社会貢献と未来展望
例えば、アリババ財団は環境保護、教育発展、貧困削減を支援し、社会に長期的な価値を創造しています。課題と将来の展望
目覚ましい成果を上げているにもかかわらず、アリババは国際競争の激化、業界規制の増加、技術革新への圧力などの課題に直面しています。その先頭を維持するためには、アリババはグローバルでの継続的な革新を続けながら、異なる市場の規制や文化に積極的に適応する必要があります。今後、アリババはテクノロジーと商業の統合を推進し、中小企業と消費者がより多くの価値を実現できるようにします。同時に、技術開発とグローバル化を通じて、アリババは世界のデジタル経済の発展においてより重要な役割を果たすことが期待されています。結論
中国および世界で最も影響力のあるインターネット企業の一つであるアリババの成長歴史は、ビジネスモデルに対する技術の深い変革を示しています。継続的な革新と拡大により、アリババは世界経済に新たな活力を注入し、無数の企業と消費者にとって前例のない機会を創出しています。将来、アリババは引き続き技術と商業によって駆動され、より便利で効率的なデジタル世界を構築することを目指します。
上記の記事は約4500語です。以下の方法で書かれた文書を確認できます。
GET alibaba_dense_large_text/_search
上記から、semantic_textフィールドが非常に長いテキスト文書を自動的に分割し、それぞれをベクトル化することがわかります。この記事があなたがAliCloudとElasticsearchを使用したベクトル検索の探求において貴重な参考とインスピレーションを提供できることを願っています。将来的には、技術が進化するにつれて、セマンティック理解に基づくよりスマートなアプリケーションが登場し、検索技術をさらに高めることが期待されます。ベクトル検索のニーズに対応するために、Alibaba Cloud Elasticsearchの力を活用してください。堅牢なインフラとAI機能により、AIを活用して検索結果を改善したいと考えている企業にとって最適な選択肢となります。Alibaba Cloud上のElasticsearchを使用して始める準備はできていますか? カスタマイズされたクラウドソリューションとサービスを探索し、データを視覚的な傑作に変える最初の一歩を踏み出しましょう。こちらをクリックして、30日間無料トライアルを開始。