本ラボでは、テキスト検索、ベクトル検索、スパース検索を組み合わせたハイブリッド検索を実装していきます。
本ラボの実施にあたっては、以下のラボを事前に完了している必要があります。これらのラボで作成したインデックスを元にハイブリッド検索を実装するためです。まだ未実施の場合は、項番に沿ってラボを完了させてください。
ハイブリッド検索は、複数の検索を実行し、各結果をマージ、スコアを平準化したうえでランク付けを行う機能です。
OpenSearch では Hybrid query と Normalization processor を組み合わせることでハイブリッド検索を実装することができます。
Hybrid query は複数のクエリを実行した結果を組み合わせるものです。単に Hybrid query を実行するだけでは、個々のクエリごとのスコア計算方法やベースのスコア値が大きく異なることで偏った結果となるため、Normalization processor によりスコアの平準化を行います。
以下はハイブリッド検索の処理フローです
!pip install opensearch-py requests-aws4auth --quiet
import boto3
import json
import time
import logging
import pandas as pd
import numpy as np
from opensearchpy import OpenSearch, RequestsHttpConnection, AWSV4SignerAuth
以降の処理を実行する際に必要なヘルパー関数を定義しておきます。
def search_cloudformation_output(stackname, key):
cloudformation_client = boto3.client("cloudformation", region_name=default_region)
for output in cloudformation_client.describe_stacks(StackName=stackname)["Stacks"][0]["Outputs"]:
if output["OutputKey"] == key:
return output["OutputValue"]
raise ValueError(f"{key} is not found in outputs of {stackname}.")
def search_sagemaker_inference_endpoint(model_id, region):
sagemaker_client = boto3.client("sagemaker", region_name=region)
response = sagemaker_client.search(
Resource="Endpoint",
SearchExpression={
"Filters": [
{
"Name": "EndpointName",
"Operator": "Contains",
"Value": model_id
},
],
},
SortBy="LastModifiedTime",
SortOrder="Descending",
MaxResults=1,
)
return response["Results"]
default_region = boto3.Session().region_name
logging.getLogger().setLevel(logging.ERROR)
ハイブリッド検索を行うにあたって Normalization Processor を呼び出す search pipeline の作成が必要となります。以下で作成を行います。
ドメイン(クラスター)に接続するためのエンドポイント情報を CloudFormation スタックの出力から取得し、OpenSearch クライアントを作成します。
cloudformation_stack_name = "search-lab-jp"
opensearch_cluster_endpoint = search_cloudformation_output(cloudformation_stack_name, "OpenSearchDomainEndpoint")
credentials = boto3.Session().get_credentials()
service_code = "es"
auth = AWSV4SignerAuth(credentials=credentials, region=default_region, service=service_code)
opensearch_client = OpenSearch(
hosts=[{"host": opensearch_cluster_endpoint, "port": 443}],
http_compress=True,
http_auth=auth,
use_ssl=True,
verify_certs=True,
connection_class = RequestsHttpConnection
)
opensearch_client
<OpenSearch([{'host': 'vpc-opensearchservi-lsy27q89mdpe-ldw2ctnzym3u7iqqrmq36zwftu.us-east-1.es.amazonaws.com', 'port': 443}])>
OpenSearch クラスターへのネットワーク接続性が確保されており、OpenSearch の Security 機能により API リクエストが許可されているかを確認します。 レスポンスに cluster_name や cluster_uuid が含まれていれば、接続確認が無事完了したと判断できます
opensearch_client.info()
{'name': '37fa7880d30e6918860bdb0e18c8e91d', 'cluster_name': '123456789012:opensearchservi-lsy27q89mdpe', 'cluster_uuid': 'yHC8ufTTRdWZqY-0J9kE9A', 'version': {'distribution': 'opensearch', 'number': '2.17.0', 'build_type': 'tar', 'build_hash': 'unknown', 'build_date': '2025-02-14T09:38:50.023788640Z', 'build_snapshot': False, 'lucene_version': '9.11.1', 'minimum_wire_compatibility_version': '7.10.0', 'minimum_index_compatibility_version': '7.0.0'}, 'tagline': 'The OpenSearch Project: https://opensearch.org/'}
各検索のスコアの重みづけは weights 要素内で実施しています。ここで定義した weights は Hybrid query 実行時に指定する queries 内の各検索条件と対応しています。
まずは、Neural search の実装 (Amazon SageMaker 編) で作成した検索パイプラインをベースに Normalization processor を含むパイプラインを作成します。作成にあたって、過去のパイプラインの設定を流用します。
embedding_model_id_on_hf = "BAAI/bge-m3"
embedding_model_name = embedding_model_id_on_hf.lower().replace("/", "-")
neural_search_pipeline_id = f"{embedding_model_name}_neural_search_query"
response = opensearch_client.http.get("/_search/pipeline/" + neural_search_pipeline_id)
request_processors = response[neural_search_pipeline_id]["request_processors"]
embedding_model_id = request_processors[0]["neural_query_enricher"]["default_model_id"]
print(f"embedding model id: {embedding_model_id}")
sparse_encoding_model_id_on_hf = "hotchpotch/japanese-splade-v2"
sparse_encoding_model_name = sparse_encoding_model_id_on_hf.lower().replace("/", "-")
neural_sparse_search_pipeline_id = f"{sparse_encoding_model_name}_neural_sparse_search_query"
response = opensearch_client.http.get("/_search/pipeline/" + neural_sparse_search_pipeline_id)
request_processors = response[neural_sparse_search_pipeline_id]["request_processors"]
sparse_encoding_model_id = request_processors[1]["neural_query_enricher"]["default_model_id"]
print(f"sparse encoding model id: {sparse_encoding_model_id}")
neural_sparse_two_phase_processor = request_processors[0]
embedding model id: 6s6ig5UB_gYfju7duOPf sparse encoding model id: Mc6kg5UB_gYfju7dMOSG
sparse_encoding_model_id_on_hf = "hotchpotch/japanese-splade-v2"
sparse_encoding_model_name = sparse_encoding_model_id_on_hf.lower().replace("/", "-")
neural_sparse_search_pipeline_id = f"{sparse_encoding_model_name}_neural_sparse_search_query"
response = opensearch_client.http.get("/_search/pipeline/" + neural_sparse_search_pipeline_id)
print(response)
#request_processors = response[neural_sparse_search_pipeline_id]["request_processors"]
#sparse_encoding_model_id = request_processors[1]["neural_query_enricher"]["default_model_id"]
#print(f"sparse encoding model id: {sparse_encoding_model_id}")
#neural_sparse_two_phase_processor = request_processors[0]
{'hotchpotch-japanese-splade-v2_neural_sparse_search_query': {'request_processors': [{'neural_sparse_two_phase_processor': {'tag': 'neural-sparse', 'description': 'Creates a two-phase processor for neural sparse search.'}}, {'neural_query_enricher': {'default_model_id': 'Mc6kg5UB_gYfju7dMOSG'}}]}}
上記で取得したモデル ID に加えて、Phase results processors に Normalization processor を追加します。
payload={
"request_processors": [
neural_sparse_two_phase_processor,
{
"neural_query_enricher" : {
"default_model_id": embedding_model_id,
"neural_field_default_id": {
"question_sparse_embedding" : sparse_encoding_model_id,
"context_sparse_embedding" : sparse_encoding_model_id
}
}
}
],
"phase_results_processors": [
{
"normalization-processor": {
"normalization": {
"technique": "min_max"
},
"combination": {
"technique": "arithmetic_mean",
"parameters": {
"weights": [
0.7,
0.3
]
}
}
}
}
]
}
# パイプライン ID の指定
hybrid_search_pipeline_id = f"{embedding_model_name}_{sparse_encoding_model_name}_hybrid_search"
# パイプライン作成 API の呼び出し
response = opensearch_client.http.put("/_search/pipeline/" + hybrid_search_pipeline_id, body=payload)
print(response)
response = opensearch_client.http.get("/_search/pipeline/" + hybrid_search_pipeline_id)
print(response)
{'acknowledged': True} {'baai-bge-m3_hotchpotch-japanese-splade-v2_hybrid_search': {'request_processors': [{'neural_sparse_two_phase_processor': {'tag': 'neural-sparse', 'description': 'Creates a two-phase processor for neural sparse search.'}}, {'neural_query_enricher': {'default_model_id': '6s6ig5UB_gYfju7duOPf', 'neural_field_default_id': {'question_sparse_embedding': 'Mc6kg5UB_gYfju7dMOSG', 'context_sparse_embedding': 'Mc6kg5UB_gYfju7dMOSG'}}}], 'phase_results_processors': [{'normalization-processor': {'normalization': {'technique': 'min_max'}, 'combination': {'technique': 'arithmetic_mean', 'parameters': {'weights': [0.7, 0.3]}}}}]}}
テキスト検索はクエリに厳密にマッチするドキュメントを取得可能です。一方でクエリに厳密にマッチしないものの、意図としては近いドキュメントまでは拾うことができません。
index_name = "jsquad-neural-search"
query = "日本で梅雨がない地域は?"
payload = {
"query": {
"match": {
"question": {
"query": query,
"operator": "and"
}
}
},
"_source": False,
"fields": ["question", "answers", "context"],
"size": 10
}
response = opensearch_client.search(
index=index_name,
body=payload
)
pd.json_normalize(response["hits"]["hits"])
_index | _id | _score | fields.question | fields.answers | fields.context | |
---|---|---|---|---|---|---|
0 | jsquad-neural-search | a10336p24q1 | 19.678131 | [梅雨が日本の中でない地域はどこか。] | [北海道, 東北地方] | [梅雨 [SEP] 年によっては梅雨明けの時期が特定できなかったり、あるいは発表がされないこ... |
他方、ベクトル検索は意味的に近いドキュメントを検索することに長けています
index_name = "jsquad-neural-search"
query = "日本で梅雨がない地域は?"
payload = {
"size": 10,
"query": {
"neural": {
"question_embedding": {
"query_text": query,
"k": 10
}
}
},
"_source" : False,
"fields": ["question", "answers", "context"]
}
response = opensearch_client.search(
index=index_name,
body=payload,
search_pipeline = hybrid_search_pipeline_id
)
pd.json_normalize(response["hits"]["hits"])
_index | _id | _score | fields.question | fields.answers | fields.context | |
---|---|---|---|---|---|---|
0 | jsquad-neural-search | a10336p32q3 | 0.834003 | [梅雨がないとされている都道府県はどこ?] | [北海道] | [梅雨 [SEP] 実際の気象としては北海道にも道南を中心に梅雨前線がかかることはあるが、平... |
1 | jsquad-neural-search | a10336p24q1 | 0.830656 | [梅雨が日本の中でない地域はどこか。] | [北海道, 東北地方] | [梅雨 [SEP] 年によっては梅雨明けの時期が特定できなかったり、あるいは発表がされないこ... |
2 | jsquad-neural-search | a10336p32q2 | 0.790335 | [気候学的には梅雨はないとされている場所は?] | [北海道] | [梅雨 [SEP] 実際の気象としては北海道にも道南を中心に梅雨前線がかかることはあるが、平... |
3 | jsquad-neural-search | a10336p0q0 | 0.784383 | [日本で梅雨がないのは北海道とどこか。] | [小笠原諸島, 小笠原諸島を除く日本] | [梅雨 [SEP] 梅雨(つゆ、ばいう)は、北海道と小笠原諸島を除く日本、朝鮮半島南部、中国... |
4 | jsquad-neural-search | a10336p18q0 | 0.783382 | [日本の地域で本格的な長雨に突入しない場所はどこか。] | [北海道] | [梅雨 [SEP] 次に梅雨前線は中国の江淮(長江流域・淮河流域)に北上する。6月下旬には華... |
5 | jsquad-neural-search | a10336p42q2 | 0.680094 | [梅雨の期間中ほとんど雨が降らない場合をなんという?] | [空梅雨, 空梅雨(からつゆ)] | [梅雨 [SEP] 梅雨の期間中ほとんど雨が降らない場合がある。このような梅雨のことを空梅雨... |
6 | jsquad-neural-search | a10336p42q4 | 0.678591 | [ほとんど雨が降らない梅雨を何という?] | [空梅雨, 空梅雨(からつゆ)] | [梅雨 [SEP] 梅雨の期間中ほとんど雨が降らない場合がある。このような梅雨のことを空梅雨... |
7 | jsquad-neural-search | a10336p42q1 | 0.675261 | [梅雨の期間中ほとんど雨が降らない場合を何と呼ぶ?] | [空梅雨, 空梅雨(からつゆ)] | [梅雨 [SEP] 梅雨の期間中ほとんど雨が降らない場合がある。このような梅雨のことを空梅雨... |
8 | jsquad-neural-search | a10336p42q3 | 0.668726 | [ほとんど雨が降らない梅雨を何と呼ぶか] | [空梅雨, 空梅雨(からつゆ)] | [梅雨 [SEP] 梅雨の期間中ほとんど雨が降らない場合がある。このような梅雨のことを空梅雨... |
9 | jsquad-neural-search | a10336p42q0 | 0.668302 | [梅雨の期間中ほとんど雨が降らない場合がある。このような梅雨のことをなんというか?] | [空梅雨, 空梅雨(からつゆ)] | [梅雨 [SEP] 梅雨の期間中ほとんど雨が降らない場合がある。このような梅雨のことを空梅雨... |
両者を組み合わせることで、意味的に近い検索結果もフォローしつつ、テキスト検索でマッチするドキュメントについてはよりスコアを上げる = 上位にランク付けすることが可能となります。
%%time
index_name = "jsquad-neural-search"
query = "日本で梅雨がない地域は?"
payload = {
"size": 10,
"query": {
"hybrid": {
"queries": [
{
"match": {
"question": {
"query": query,
"operator": "and"
}
}
},
{
"neural": {
"question_embedding": {
"query_text": query, # テキストをベクトルに変換し
"k": 10 # クエリベクトルに近いベクトルのうち上位 10 件を返却
}
}
}
]
}
},
"_source" : False,
"fields": ["question", "answers", "context"]
}
# 検索 API を実行
response = opensearch_client.search(
body = payload,
index = index_name,
filter_path = "hits.hits",
search_pipeline = hybrid_search_pipeline_id
)
# 結果を表示
pd.json_normalize(response["hits"]["hits"])
CPU times: user 4.12 ms, sys: 9 μs, total: 4.13 ms Wall time: 67.3 ms
_index | _id | _score | fields.question | fields.answers | fields.context | |
---|---|---|---|---|---|---|
0 | jsquad-neural-search | a10336p24q1 | 0.993941 | [梅雨が日本の中でない地域はどこか。] | [北海道, 東北地方] | [梅雨 [SEP] 年によっては梅雨明けの時期が特定できなかったり、あるいは発表がされないこ... |
1 | jsquad-neural-search | a10336p32q3 | 0.300000 | [梅雨がないとされている都道府県はどこ?] | [北海道] | [梅雨 [SEP] 実際の気象としては北海道にも道南を中心に梅雨前線がかかることはあるが、平... |
2 | jsquad-neural-search | a10336p32q2 | 0.220940 | [気候学的には梅雨はないとされている場所は?] | [北海道] | [梅雨 [SEP] 実際の気象としては北海道にも道南を中心に梅雨前線がかかることはあるが、平... |
3 | jsquad-neural-search | a10336p0q0 | 0.210164 | [日本で梅雨がないのは北海道とどこか。] | [小笠原諸島, 小笠原諸島を除く日本] | [梅雨 [SEP] 梅雨(つゆ、ばいう)は、北海道と小笠原諸島を除く日本、朝鮮半島南部、中国... |
4 | jsquad-neural-search | a10336p18q0 | 0.208351 | [日本の地域で本格的な長雨に突入しない場所はどこか。] | [北海道] | [梅雨 [SEP] 次に梅雨前線は中国の江淮(長江流域・淮河流域)に北上する。6月下旬には華... |
5 | jsquad-neural-search | a10336p42q2 | 0.021349 | [梅雨の期間中ほとんど雨が降らない場合をなんという?] | [空梅雨, 空梅雨(からつゆ)] | [梅雨 [SEP] 梅雨の期間中ほとんど雨が降らない場合がある。このような梅雨のことを空梅雨... |
6 | jsquad-neural-search | a10336p42q4 | 0.018628 | [ほとんど雨が降らない梅雨を何という?] | [空梅雨, 空梅雨(からつゆ)] | [梅雨 [SEP] 梅雨の期間中ほとんど雨が降らない場合がある。このような梅雨のことを空梅雨... |
7 | jsquad-neural-search | a10336p42q1 | 0.012599 | [梅雨の期間中ほとんど雨が降らない場合を何と呼ぶ?] | [空梅雨, 空梅雨(からつゆ)] | [梅雨 [SEP] 梅雨の期間中ほとんど雨が降らない場合がある。このような梅雨のことを空梅雨... |
8 | jsquad-neural-search | a10336p42q3 | 0.000768 | [ほとんど雨が降らない梅雨を何と呼ぶか] | [空梅雨, 空梅雨(からつゆ)] | [梅雨 [SEP] 梅雨の期間中ほとんど雨が降らない場合がある。このような梅雨のことを空梅雨... |
9 | jsquad-neural-search | a10336p42q0 | 0.000300 | [梅雨の期間中ほとんど雨が降らない場合がある。このような梅雨のことをなんというか?] | [空梅雨, 空梅雨(からつゆ)] | [梅雨 [SEP] 梅雨の期間中ほとんど雨が降らない場合がある。このような梅雨のことを空梅雨... |
ベクトル検索によって意図しない結果が付与されてしまう場合は、別のラボで解説するリランキングや、k ではなく min_score によるフィルタリングが有効です
%%time
index_name = "jsquad-neural-search"
query = "日本で梅雨がない地域は?"
payload = {
"size": 10,
"query": {
"hybrid": {
"queries": [
{
"match": {
"question": {
"query": query,
"operator": "and"
}
}
},
{
"neural": {
"question_embedding": {
"query_text": query, # テキストをベクトルに変換し
"min_score": 0.7
}
}
}
]
}
},
"_source" : False,
"fields": ["question", "answers", "context"]
}
# 検索 API を実行
response = opensearch_client.search(
body = payload,
index = index_name,
filter_path = "hits.hits",
search_pipeline = hybrid_search_pipeline_id
)
# 結果を表示
pd.json_normalize(response["hits"]["hits"])
CPU times: user 4.01 ms, sys: 0 ns, total: 4.01 ms Wall time: 26.6 ms
_index | _id | _score | fields.question | fields.answers | fields.context | |
---|---|---|---|---|---|---|
0 | jsquad-neural-search | a10336p24q1 | 0.980166 | [梅雨が日本の中でない地域はどこか。] | [北海道, 東北地方] | [梅雨 [SEP] 年によっては梅雨明けの時期が特定できなかったり、あるいは発表がされないこ... |
1 | jsquad-neural-search | a10336p32q3 | 0.300000 | [梅雨がないとされている都道府県はどこ?] | [北海道] | [梅雨 [SEP] 実際の気象としては北海道にも道南を中心に梅雨前線がかかることはあるが、平... |
2 | jsquad-neural-search | a10336p32q2 | 0.041208 | [気候学的には梅雨はないとされている場所は?] | [北海道] | [梅雨 [SEP] 実際の気象としては北海道にも道南を中心に梅雨前線がかかることはあるが、平... |
3 | jsquad-neural-search | a10336p0q0 | 0.005937 | [日本で梅雨がないのは北海道とどこか。] | [小笠原諸島, 小笠原諸島を除く日本] | [梅雨 [SEP] 梅雨(つゆ、ばいう)は、北海道と小笠原諸島を除く日本、朝鮮半島南部、中国... |
4 | jsquad-neural-search | a10336p18q0 | 0.000300 | [日本の地域で本格的な長雨に突入しない場所はどこか。] | [北海道] | [梅雨 [SEP] 次に梅雨前線は中国の江淮(長江流域・淮河流域)に北上する。6月下旬には華... |
ベクトル検索は意味的に近い文書を検索することに長けていますが、反面厳密なマッチングができないケースがあります。例えば、製品の型番などの業務固有のパラメーターでの検索は不得手です。
以下のように "M" だけを検索対象としてみると、ベクトル検索は無関係の結果を返却します。
%%time
index_name = "jsquad-neural-search"
query = "M"
payload = {
"size": 10,
"query": {
"neural": {
"question_embedding": {
"query_text": query,
"k": 10,
}
}
},
"_source" : False,
"fields": ["question", "answers", "context"]
}
# 検索 API を実行
response = opensearch_client.search(
body = payload,
index = index_name,
filter_path = "hits.hits",
search_pipeline = hybrid_search_pipeline_id
)
# 結果を表示
pd.json_normalize(response["hits"]["hits"])
CPU times: user 4.11 ms, sys: 8 μs, total: 4.12 ms Wall time: 48.7 ms
_index | _id | _score | fields.question | fields.answers | fields.context | |
---|---|---|---|---|---|---|
0 | jsquad-neural-search | a22392p4q2 | 0.541772 | [この文章のタイトルは?] | [建築家] | [建築家 [SEP] 古くから中世の歴史を通して、多くの建築設計と建設は、石造りの石工や大工... |
1 | jsquad-neural-search | a14985p34q1 | 0.473036 | [反発してたのは] | [日本共産党] | [日本共産党 [SEP] 一方、破壊活動防止法に基づく調査活動を行っている公安調査庁では、現... |
2 | jsquad-neural-search | a4596p54q0 | 0.468327 | [ポルトガルのバンド] | [MOONSPELL, デス] | [ポルトガル [SEP] また、ポルトガルは近来、デス、ブラック、シンフォニックメタルなどの... |
3 | jsquad-neural-search | a384286p2q0 | 0.463754 | [題名の末尾は?] | [法] | [出入国管理及び難民認定法 [SEP] 形式は政令だが効力は法律同等、題名の末尾は「法」では... |
4 | jsquad-neural-search | a73860p8q2 | 0.463178 | [日本の市を一つ挙げよ] | [京都市] | [住居表示 [SEP] 世界各国での住居表示は、街路名、通り名を含む道路表記が(中国も含め)... |
5 | jsquad-neural-search | a20898p16q3 | 0.459966 | [上式の根を答えよ] | [σ1、σ2、σ3] | [応力 [SEP] となる。一方、上式の根はσ1、σ2、σ3となるので、上式は以下のようも書... |
6 | jsquad-neural-search | a2664357p8q2 | 0.458288 | [いつ開始されたか] | [2012年10月29日, 2012年10月29日に開始した] | [ウィキデータ [SEP] ウィキデータは、ウィキメディア財団の2006年以降初めての新規プ... |
7 | jsquad-neural-search | a17703p19q1 | 0.457102 | [この文中で争われた権利は何か?] | [労働基本権] | [労働基本権 [SEP] 全農林労働組合の役員たる被告人が、警察官職務執行法の改正に反対する... |
8 | jsquad-neural-search | a14985p79q1 | 0.456164 | [首相は誰ですか] | [安倍晋三, 安倍晋三首相] | [日本共産党 [SEP] また、公安調査庁発刊資料である内外情勢の回顧と展望の平成29年度版... |
9 | jsquad-neural-search | a113522p19q0 | 0.455970 | [何が増大するか] | [軍需品の複雑性] | [国際連合平和維持活動 [SEP] 兵站は平和維持軍の編成の段階から重大な事項である。何故な... |
一方、テキスト検索の方は M を含む結果を返します。
index_name = "jsquad-neural-search"
query = "M"
payload = {
"query": {
"match": {
"question": {
"query": query,
"operator": "and"
}
}
},
"_source": False,
"fields": ["question", "answers", "context"],
"size": 10
}
response = opensearch_client.search(
index=index_name,
body=payload
)
pd.json_normalize(response["hits"]["hits"])
_index | _id | _score | fields.question | fields.answers | fields.context | |
---|---|---|---|---|---|---|
0 | jsquad-neural-search | a258209p4q3 | 8.453966 | [m5Cとは何か] | [5-メチルシトシン] | [核酸塩基 [SEP] DNAとRNAには、核酸の鎖が形成された後に修飾が行われた、非標準的... |
1 | jsquad-neural-search | a379233p6q1 | 7.834435 | [ケプラーの式を導き出す際、Mが主星の質量、mが伴星の質量であるとするとき、mの影響は通常無... | [Mはmよりもずっと大きいため, ここでGは重力定数、Mは主星の質量、mは伴星の質量である。... | [軌道長半径 [SEP] ここでGは重力定数、Mは主星の質量、mは伴星の質量である。通常、M... |
2 | jsquad-neural-search | a2164640p12q0 | 6.325707 | [I'm Feeling Lucky と書かれたボタンがあるホームページは] | [Google] | [Google_検索 [SEP] Googleのホームページには I'm Feeling L... |
3 | jsquad-neural-search | a379233p6q2 | 6.022480 | [軌道長半径において、Gは重力定数とするとMは] | [主星の質量, 伴星の質量] | [軌道長半径 [SEP] ここでGは重力定数、Mは主星の質量、mは伴星の質量である。通常、M... |
4 | jsquad-neural-search | a10336p44q3 | 5.984784 | [地上付近では周囲から空気を吸い上げる一方、上空数千m-1万mの対流圏上層では吸い上げた空気... | [台風や熱帯低気圧, 水蒸気, 豪雨] | [梅雨 [SEP] 台風や熱帯低気圧は地上付近では周囲から空気を吸い上げる一方、上空数千m-... |
5 | jsquad-neural-search | a59579p8q0 | 4.858095 | [最高峰は島の北部にあるディアブロティン山で高さ1,447mである山がある国は?] | [ドミニカ国] | [ドミニカ国 [SEP] ドミニカ島はカリブ海は小アンティル諸島にあり、北はグアドループ海峡... |
6 | jsquad-neural-search | a18783p7q1 | 4.353117 | [地表から h だけ高い質量 m の物体の位置エネルギーを考える。地球の中心から地表までの距... | [R+h] | [位置エネルギー [SEP] 今、地表から h だけ高い質量 m の物体の位置エネルギーを考... |
7 | jsquad-neural-search | a18783p7q0 | 3.943234 | [地表から h だけ高い質量 m の物体の位置エネルギーを考えた場合、地球の中心から地表まで... | [R+h] | [位置エネルギー [SEP] 今、地表から h だけ高い質量 m の物体の位置エネルギーを考... |
ベクトル検索単体からハイブリッド検索に切り替えることで、検索精度の向上を達成できました。
%%time
index_name = "jsquad-neural-search"
query = "M"
payload = {
"size": 10,
"query": {
"hybrid": {
"queries": [
{
"match": {
"question": {
"query": query,
"operator": "and"
}
}
},
{
"neural": {
"question_embedding": {
"query_text": query, # テキストをベクトルに変換し
"min_score": 0.7
}
}
}
]
}
},
"_source" : False,
"fields": ["question", "answers", "context"]
}
# 検索 API を実行
response = opensearch_client.search(
body = payload,
index = index_name,
filter_path = "hits.hits",
search_pipeline = hybrid_search_pipeline_id
)
# 結果を表示
pd.json_normalize(response["hits"]["hits"])
CPU times: user 2.97 ms, sys: 247 μs, total: 3.22 ms Wall time: 25.2 ms
_index | _id | _score | fields.question | fields.answers | fields.context | |
---|---|---|---|---|---|---|
0 | jsquad-neural-search | a258209p4q3 | 0.700000 | [m5Cとは何か] | [5-メチルシトシン] | [核酸塩基 [SEP] DNAとRNAには、核酸の鎖が形成された後に修飾が行われた、非標準的... |
1 | jsquad-neural-search | a379233p6q1 | 0.603858 | [ケプラーの式を導き出す際、Mが主星の質量、mが伴星の質量であるとするとき、mの影響は通常無... | [Mはmよりもずっと大きいため, ここでGは重力定数、Mは主星の質量、mは伴星の質量である。... | [軌道長半径 [SEP] ここでGは重力定数、Mは主星の質量、mは伴星の質量である。通常、M... |
2 | jsquad-neural-search | a2164640p12q0 | 0.369725 | [I'm Feeling Lucky と書かれたボタンがあるホームページは] | [Google] | [Google_検索 [SEP] Googleのホームページには I'm Feeling L... |
3 | jsquad-neural-search | a379233p6q2 | 0.322669 | [軌道長半径において、Gは重力定数とするとMは] | [主星の質量, 伴星の質量] | [軌道長半径 [SEP] ここでGは重力定数、Mは主星の質量、mは伴星の質量である。通常、M... |
4 | jsquad-neural-search | a10336p44q3 | 0.316819 | [地上付近では周囲から空気を吸い上げる一方、上空数千m-1万mの対流圏上層では吸い上げた空気... | [台風や熱帯低気圧, 水蒸気, 豪雨] | [梅雨 [SEP] 台風や熱帯低気圧は地上付近では周囲から空気を吸い上げる一方、上空数千m-... |
5 | jsquad-neural-search | a59579p8q0 | 0.141973 | [最高峰は島の北部にあるディアブロティン山で高さ1,447mである山がある国は?] | [ドミニカ国] | [ドミニカ国 [SEP] ドミニカ島はカリブ海は小アンティル諸島にあり、北はグアドループ海峡... |
6 | jsquad-neural-search | a18783p7q1 | 0.063608 | [地表から h だけ高い質量 m の物体の位置エネルギーを考える。地球の中心から地表までの距... | [R+h] | [位置エネルギー [SEP] 今、地表から h だけ高い質量 m の物体の位置エネルギーを考... |
7 | jsquad-neural-search | a18783p7q0 | 0.000700 | [地表から h だけ高い質量 m の物体の位置エネルギーを考えた場合、地球の中心から地表まで... | [R+h] | [位置エネルギー [SEP] 今、地表から h だけ高い質量 m の物体の位置エネルギーを考... |
ベクトル検索の代わりに、スパース検索でテキスト検索を補完することも可能です。
%%time
index_name = "jsquad-neural-sparse-search"
query = "日本で梅雨がない地域は?"
payload = {
"size": 10,
"query": {
"hybrid": {
"queries": [
{
"match": {
"question": {
"query": query,
"operator": "and"
}
}
},
{
"neural_sparse": {
"question_sparse_embedding": {
"query_text": query
}
}
}
]
}
},
"_source" : False,
"fields": ["question", "answers", "context"]
}
# 検索 API を実行
response = opensearch_client.search(
body = payload,
index = index_name,
filter_path = "hits.hits",
search_pipeline = hybrid_search_pipeline_id
)
# 結果を表示
pd.json_normalize(response["hits"]["hits"])
CPU times: user 4.3 ms, sys: 0 ns, total: 4.3 ms Wall time: 65.6 ms
_index | _id | _score | fields.question | fields.answers | fields.context | |
---|---|---|---|---|---|---|
0 | jsquad-neural-sparse-search | a10336p24q1 | 1.000000 | [梅雨が日本の中でない地域はどこか。] | [北海道, 東北地方] | [梅雨 [SEP] 年によっては梅雨明けの時期が特定できなかったり、あるいは発表がされないこ... |
1 | jsquad-neural-sparse-search | a10336p0q0 | 0.219713 | [日本で梅雨がないのは北海道とどこか。] | [小笠原諸島, 小笠原諸島を除く日本] | [梅雨 [SEP] 梅雨(つゆ、ばいう)は、北海道と小笠原諸島を除く日本、朝鮮半島南部、中国... |
2 | jsquad-neural-sparse-search | a10336p18q0 | 0.217360 | [日本の地域で本格的な長雨に突入しない場所はどこか。] | [北海道] | [梅雨 [SEP] 次に梅雨前線は中国の江淮(長江流域・淮河流域)に北上する。6月下旬には華... |
3 | jsquad-neural-sparse-search | a10336p32q2 | 0.182510 | [気候学的には梅雨はないとされている場所は?] | [北海道] | [梅雨 [SEP] 実際の気象としては北海道にも道南を中心に梅雨前線がかかることはあるが、平... |
4 | jsquad-neural-sparse-search | a10336p32q3 | 0.110161 | [梅雨がないとされている都道府県はどこ?] | [北海道] | [梅雨 [SEP] 実際の気象としては北海道にも道南を中心に梅雨前線がかかることはあるが、平... |
5 | jsquad-neural-sparse-search | a10336p42q4 | 0.042885 | [ほとんど雨が降らない梅雨を何という?] | [空梅雨, 空梅雨(からつゆ)] | [梅雨 [SEP] 梅雨の期間中ほとんど雨が降らない場合がある。このような梅雨のことを空梅雨... |
6 | jsquad-neural-sparse-search | a10336p42q3 | 0.013767 | [ほとんど雨が降らない梅雨を何と呼ぶか] | [空梅雨, 空梅雨(からつゆ)] | [梅雨 [SEP] 梅雨の期間中ほとんど雨が降らない場合がある。このような梅雨のことを空梅雨... |
7 | jsquad-neural-sparse-search | a10336p31q2 | 0.009527 | [日本付近の梅雨期の雨量が最も多い地区は] | [九州南部] | [梅雨 [SEP] 梅雨の期間はどの地方でも40日から50日前後と大差はないが、期間中の降水... |
8 | jsquad-neural-sparse-search | a10336p42q2 | 0.006727 | [梅雨の期間中ほとんど雨が降らない場合をなんという?] | [空梅雨, 空梅雨(からつゆ)] | [梅雨 [SEP] 梅雨の期間中ほとんど雨が降らない場合がある。このような梅雨のことを空梅雨... |
9 | jsquad-neural-sparse-search | a10336p35q2 | 0.000300 | [中国のどこの地域で梅雨がみられるか。] | [中国中部・南部, 中部・南部] | [梅雨 [SEP] 中国中部・南部でも梅雨がみられる。中国では各都市の気象台が、梅雨入りと梅... |
ベクトル検索とスパース検索を組み合わせることも可能です。
現時点ではベクトルとトークンリスト両方のデータを持つインデックスが存在しないため、jsquad-hybrid-search というインデックスを作成し、jsquad-neural-search からデータを jsquad-hybrid-search に Reindex API で移行します。移行中に、Ingestion pipeline を使用した Sparse encoding の作成と埋め込みも合わせて実施します。
payload = {
"mappings": {
"properties": {
"id": {"type": "keyword"},
"question": {"type": "text", "analyzer": "custom_sudachi_analyzer"},
"context": {"type": "text", "analyzer": "custom_sudachi_analyzer"},
"answers": {"type": "text", "analyzer": "custom_sudachi_analyzer"},
"question_embedding": {
"type": "knn_vector",
"dimension": 1024,
"space_type": "l2",
"method": {
"name": "hnsw",
"engine": "faiss",
}
},
"context_embedding": {
"type": "knn_vector",
"dimension": 1024,
"space_type": "l2",
"method": {
"name": "hnsw",
"engine": "faiss",
},
},
"question_sparse_embedding": {
"type": "rank_features"
},
"context_sparse_embedding": {
"type": "rank_features"
},
}
},
"settings": {
"index.knn": True,
"index.number_of_shards": 1,
"index.number_of_replicas": 0,
"analysis": {
"analyzer": {
"custom_sudachi_analyzer": {
"char_filter": ["icu_normalizer"],
"filter": [
"sudachi_normalizedform",
"custom_sudachi_part_of_speech"
],
"tokenizer": "sudachi_tokenizer",
"type": "custom"
}
},
"filter": {
"custom_sudachi_part_of_speech": {
"type": "sudachi_part_of_speech",
"stoptags": ["感動詞,フィラー","接頭辞","代名詞","副詞","助詞","助動詞","動詞,一般,*,*,*,終止形-一般","名詞,普通名詞,副詞可能"]
}
}
}
}
}
# インデックス名を指定
index_name = "jsquad-hybrid-search"
try:
# 既に同名のインデックスが存在する場合、いったん削除を行う
print("# delete index")
response = opensearch_client.indices.delete(index=index_name)
print(json.dumps(response, indent=2))
except Exception as e:
print(e)
# インデックスを作成
response = opensearch_client.indices.create(index_name, body=payload)
response
# delete index NotFoundError(404, 'index_not_found_exception', 'no such index [jsquad-hybrid-search]', jsquad-hybrid-search, index_or_alias)
{'acknowledged': True, 'shards_acknowledged': True, 'index': 'jsquad-hybrid-search'}
ingestion_pipeline_id = f"{sparse_encoding_model_name}_neural_sparse_search_ingestion"
response = opensearch_client.http.get("/_ingest/pipeline/" + ingestion_pipeline_id)
print(response)
{'hotchpotch-japanese-splade-v2_neural_sparse_search_ingestion': {'processors': [{'sparse_encoding': {'model_id': 'Mc6kg5UB_gYfju7dMOSG', 'field_map': {'question': 'question_sparse_embedding', 'context': 'context_sparse_embedding'}}}]}}
payload = {
"source":{
"index":"jsquad-neural-search",
"size": 20
},
"dest":{
"index":"jsquad-hybrid-search",
"pipeline": ingestion_pipeline_id
}
}
response = opensearch_client.reindex(body=payload, slices="1", wait_for_completion=False)
task_id = response["task"]
print(json.dumps(response, indent=2, ensure_ascii=False))
{ "task": "kdnLueFaT0quni1aPfT5-g:407777" }
response = opensearch_client.tasks.get(task_id=task_id)
while response["completed"] == False:
time.sleep(1)
response = opensearch_client.tasks.get(task_id=task_id)
print(json.dumps(response, indent=2, ensure_ascii=False))
{ "completed": true, "task": { "node": "kdnLueFaT0quni1aPfT5-g", "id": 407777, "type": "transport", "action": "indices:data/write/reindex", "status": { "total": 4442, "updated": 0, "created": 4442, "deleted": 0, "batches": 223, "version_conflicts": 0, "noops": 0, "retries": { "bulk": 0, "search": 0 }, "throttled_millis": 0, "requests_per_second": -1.0, "throttled_until_millis": 0 }, "description": "reindex from [jsquad-neural-search] to [jsquad-hybrid-search]", "start_time_in_millis": 1741670537454, "running_time_in_nanos": 116586963197, "cancellable": true, "cancelled": false, "headers": {} }, "response": { "took": 116586, "timed_out": false, "total": 4442, "updated": 0, "created": 4442, "deleted": 0, "batches": 223, "version_conflicts": 0, "noops": 0, "retries": { "bulk": 0, "search": 0 }, "throttled": "0s", "throttled_millis": 0, "requests_per_second": -1.0, "throttled_until": "0s", "throttled_until_millis": 0, "failures": [] } }
ドキュメントを 1 件取得し、Sparse encoding により生成されたトークンリストとベクトルの両方が格納されていることを確認します。
%%time
index_name = "jsquad-hybrid-search"
payload = {
"size": 1,
"query": {
"match_all": {}
},
}
# 検索 API を実行
response = opensearch_client.search(
body = payload,
index = index_name,
)
print(json.dumps(response, indent=2, ensure_ascii=False))
{ "took": 3131, "timed_out": false, "_shards": { "total": 1, "successful": 1, "skipped": 0, "failed": 0 }, "hits": { "total": { "value": 4442, "relation": "eq" }, "max_score": 1.0, "hits": [ { "_index": "jsquad-hybrid-search", "_id": "a111367p18q4", "_score": 1.0, "_source": { "context_sparse_embedding": { "堀": 0.4260254, "起こし": 0.0048713684, "教え": 0.0087509155, "ため": 0.08331299, "##層": 0.041137695, "項": 0.2763672, "原始": 0.12817383, "##ネル": 0.31201172, "##物": 0.18811035, "上": 0.50439453, "融合": 0.31274414, "ポリス": 0.18811035, "##陳": 0.13928223, "役割": 0.07702637, "人間": 0.5214844, "易": 0.10028076, "身体": 0.019348145, "生体": 0.059692383, "初": 0.27416992, "勃発": 0.19702148, "法則": 0.17272949, "作者": 0.57958984, "オリジナル": 0.05230713, "##マー": 0.7753906, "有名": 0.19140625, "バー": 0.33666992, "am": 0.021255493, "現象": 0.12646484, "設立": 0.26000977, "##次郎": 0.0949707, "やすい": 0.5175781, "水": 0.110839844, "ヴェ": 0.6699219, "制": 0.18493652, "根": 0.04953003, "グリ": 0.78564453, "創造": 0.62646484, "##イ": 0.06793213, "原理": 0.12561035, "##説": 0.121276855, "主張": 0.09136963, "顔": 0.09851074, "こう": 0.077941895, "ヒュ": 0.005844116, "空間": 0.07159424, "塗": 0.01838684, "酵素": 0.95166016, "由来": 0.15771484, "ツァ": 0.24780273, "た": 0.49145508, "基礎": 0.33325195, "発見": 0.29541016, "34": 0.40405273, "層": 0.04675293, "仕組み": 0.26367188, "で": 0.061553955, "表": 0.02029419, "物": 0.066101074, "cl": 0.04019165, "エドガー": 0.1038208, "##ター": 0.51953125, "##滑": 0.31713867, "##ヒ": 0.31347656, "機能": 0.46606445, "こと": 0.18811035, "年": 0.7426758, "提案": 0.30200195, "側": 0.094055176, "水中": 0.06518555, "創": 0.22241211, "有機": 0.72753906, "##ホ": 0.6796875, "アミ": 0.4387207, "この": 0.4411621, "乾": 0.016464233, "湿": 0.24938965, "イヤー": 0.062469482, "詳しく": 0.013580322, "場所": 0.056030273, "ら": 0.02029419, "##リ": 0.033599854, "##ル": 0.546875, "##グリ": 0.34155273, "代謝": 1.0253906, "源": 0.12298584, "オットー": 0.011650085, "粘": 0.20812988, "述べ": 0.0541687, "弁護": 0.12902832, "クレイ": 0.12036133, "自然": 0.042999268, "溝": 0.11340332, "語": 0.07519531, "これ": 0.12561035, "バード": 0.09051514, "バート": 0.07702637, "バーナ": 1.2314453, "ウェス": 0.08959961, "##チン": 0.047668457, "アイデア": 0.042999268, "作り": 0.1459961, "基づい": 0.31201172, "ターナー": 0.21533203, "考え": 0.19055176, "説": 0.8598633, "主要": 0.029830933, "いの": 0.005844116, "皮": 0.068847656, "都市": 0.52978516, "趣旨": 0.4020996, "具体": 0.1038208, "結合": 0.18737793, "成立": 0.15185547, "よう": 0.00097608566, "自体": 0.031707764, "源流": 0.08874512, "祖先": 0.13586426, "63": 0.0949707, "概念": 0.17346191, "よく": 0.14099121, "カイザー": 0.1418457, "主義": 0.29760742, "アンモ": 0.0541687, "石灰": 0.08691406, "法": 0.30639648, "論": 0.14855957, "地球": 0.25463867, "ベ": 0.2770996, "発明": 0.6791992, "1959": 0.5629883, "ホ": 0.34033203, "1958": 0.15771484, "神話": 0.045806885, "内容": 0.043945312, "生成": 0.4260254, "メカニズム": 0.023162842, "形成": 0.107299805, "泥": 0.0345459, "人物": 0.4794922, "瓦": 0.1038208, "##界": 0.060638428, "研究": 0.08514404, "時代": 0.06976318, "人類": 0.26000977, "##ヤー": 0.18249512, "##urn": 0.30126953, "そもそも": 0.066101074, "歴史": 0.07159424, "説明": 0.01550293, "ルター": 0.34228516, "1960": 0.08605957, "プラスチック": 0.2553711, "バーン": 0.35205078, "プラン": 0.08605957, "能": 0.111694336, "製": 0.053253174, "1967": 0.101135254, "生き": 0.29101562, "弁": 0.4951172, "合成": 0.13671875, "##面": 0.9404297, "有": 0.03265381, "最初": 0.09136963, "発展": 0.05230713, "化": 0.2763672, "ジョン": 0.7915039, "化学": 0.70947266, "導入": 0.06793213, "土": 0.23168945, "生": 0.033599854, "発表": 0.2578125, "生物": 0.6904297, "原因": 0.082458496, "きっかけ": 0.21533203, "ホイ": 0.11254883, "生命": 1.0664062, "地": 0.0077819824, "地表": 0.18737793, "##ラーゼ": 0.017425537, "ベル": 0.10992432, "進化": 0.5439453, "バーナード": 0.5878906, "爆発": 0.066101074, "誕生": 0.32836914, "唱え": 0.07434082, "1988": 0.42236328, "中心": 0.017425537, "平面": 0.25317383, "定義": 0.17016602, "当時": 0.033599854, "作用": 0.072509766, "意味": 0.068847656, "##ンター": 0.49023438, "知ら": 0.2763672, "界": 0.8666992, "アミノ": 1.0214844, "出現": 0.11694336, "体": 0.12561035, "する": 0.0513916, "何": 0.1427002, "四郎": 0.7871094, "目的": 0.22241211, "一体": 0.005844116, "確立": 0.07519531, "論文": 0.36621094, "面": 0.39379883, "赤": 0.6328125, "学": 0.37426758, "##シン": 0.78271484, "文明": 0.1694336, "提唱": 0.49023438, "##ザー": 0.94873047, "仮説": 0.3479004, "部位": 0.21374512, "先駆": 0.07159424, "古代": 0.13671875, "起": 0.17016602, "議論": 0.13757324, "酸": 0.37158203, "触媒": 1.0654297, "出版": 0.009719849, "内": 0.10992432, "主な": 0.25390625, "粘土": 1.2070312, "##旨": 0.06335449, "##ナード": 0.10028076, "持っ": 0.08062744, "##zy": 0.12384033, "有する": 0.0513916, "ドイツ": 0.47460938, "##cin": 0.014541626, "から": 0.005844116, "##トン": 0.029830933, "理論": 0.6933594, "##リヒ": 0.047668457, "##堀": 0.92089844, "膠": 0.038330078, "反応": 0.73876953, "##理": 0.02029419, "起き": 0.41186523, "##合": 0.50927734, "##四郎": 0.24328613, "産物": 0.079711914, "見解": 0.041137695, "##上": 0.053253174, "ポリ": 0.9970703, "人生": 0.39379883, "物質": 0.043945312, "開始": 0.08154297, "液": 0.0087509155, "##ドル": 0.028869629, "科学": 0.39160156, "綿": 0.1694336, "##ナー": 0.4387207, "始": 0.2644043, "重": 0.53759766, "行わ": 0.1459961, "##場": 0.12817383, "##ナル": 0.19702148, "線": 0.14343262, "モデル": 0.19946289, "カーン": 0.18896484, "理由": 0.20654297, "ライフ": 0.15527344, "起源": 0.9667969, "表面": 1.1328125, "発生": 0.6298828, "ボーン": 0.0541687, "三郎": 0.30566406, "ギュ": 0.5932617, "生活": 0.4267578, "史": 0.05508423, "基": 0.25317383, "バナ": 0.24169922, "創始": 0.15185547, "世界": 0.021255493 }, "question_sparse_embedding": { "88": 0.6542969, "弁": 0.5541992, "陰謀": 0.05230713, "be": 0.026977539, "##イ": 0.13415527, "##ンター": 0.3395996, "##説": 0.53808594, "ドイツ": 0.6381836, "1991": 0.00097608566, "##ス": 0.5253906, "ベ": 0.33544922, "弁護": 0.2998047, "ホ": 0.26586914, "物語": 0.15356445, "法律": 0.11340332, "理論": 0.32617188, "語": 0.06976318, "た": 0.34643555, "論文": 0.98046875, "発表": 0.6533203, "作者": 0.11254883, "##理": 0.044891357, "考え": 0.105529785, "##ター": 0.87402344, "説": 1.8847656, "##ザー": 1.5400391, "ギュ": 0.44873047, "1986": 0.2763672, "##ヒ": 0.47875977, "報告": 0.0513916, "ヴェ": 0.6074219, "ルター": 0.27416992, "v": 0.066101074, "##ホ": 0.74902344, "63": 0.76464844, "1989": 0.18811035, "1988": 1.4072266 }, "question": "1988年にドイツの弁理士ギュンター・ヴェヒタースホイザーが論文で発表したのは何説?", "question_embedding": [ -0.045015093, 0.018668344, -0.05644172, 0.04155799, -0.0032160135, 0.016539497, -0.0165304, 0.039993197, 0.015356805, 0.012782175, -0.017012576, 0.0145016285, -0.032933433, -0.023071598, 0.009698077, 0.012463758, 0.064047344, -0.002215274, 0.0025427886, -0.034807548, -0.014001259, -0.0019207379, -0.0065411986, 0.0068459692, 0.014328773, 0.047562428, 0.005808839, -0.025582546, 0.016848817, 0.0009165866, 0.017230919, 0.050036985, 0.008742826, -0.0021299834, 0.024454439, 0.011754143, 0.003952922, -0.069105625, -0.051347043, -0.005081028, 0.030531658, -0.043923374, 0.022380179, -0.039738465, 0.019978404, -0.029694676, -0.025728108, -0.024454439, 0.049636688, 0.012017974, -0.0349895, 0.006313758, 0.039738465, 0.02356287, -0.009943713, 0.035171453, -0.009070341, 0.0060180845, -0.025127664, -0.045087874, 0.005199298, 0.0054312875, -0.07787574, -0.039884027, 0.021998078, 0.021706954, -0.0002669587, 0.050728407, 0.0073099486, -0.037664205, 0.03406154, 0.024654588, 0.061099708, 0.027693197, -0.022634912, -0.011190089, 0.0020640257, -0.021907102, -0.006577589, 0.0081878705, 0.034771156, -0.023617458, 0.02241657, 0.01972367, -0.055495564, 0.066594675, -0.013091495, -0.01910503, -0.0269108, -0.023471896, -0.021233877, 0.005485873, 0.019778255, -0.040429883, 0.0011576739, -0.004410078, -0.09010296, 0.012127146, 0.02245296, 0.008897486, 0.039738465, 0.017385578, -0.035044085, -0.04978225, 0.036117606, -0.0020412817, 0.007009727, 0.059607696, -0.022634912, 0.01803151, 0.007246265, -0.0072417166, 0.0036390536, 0.01841361, -0.041012134, -0.010917161, -0.009525223, -0.026164794, 0.04163077, -0.041012134, -0.016048227, 0.010207545, 0.06553935, -0.012873151, -0.04348669, -0.041776333, 0.05436746, 0.0105350595, -0.048836097, -0.020032989, -0.031696156, 0.008565422, -0.010653329, 0.008365274, -0.010116569, 0.00091146916, 0.047962725, 0.018140681, -0.02611021, -0.040320713, 0.031204883, -0.022616718, 0.010717013, -0.008983913, -0.027820563, -0.030458877, -0.042722486, 0.038719527, -0.005172005, -0.028784912, 0.027347486, -0.055422783, 0.024035947, 0.0073099486, -0.07540119, -0.034898523, -0.004187186, 0.0034502775, 0.0062000374, -0.0025268677, -0.031623375, 0.02483654, -0.041412428, -0.03710015, -0.02272589, 0.027256511, -0.040393494, 0.0020174002, -0.006177293, -0.04017515, -0.0043691387, -0.027711391, -0.007914941, -0.03025873, 0.01549327, 0.023435505, -0.02929438, -0.0010871672, -0.0296037, -0.021706954, 0.0024085985, -0.028330032, -0.021270268, -0.0036276814, -0.0403571, -0.01572071, 0.011626775, -0.032278404, 0.0152385365, 0.04090296, -0.0054494827, -0.016075518, -0.033588465, 0.02210725, -0.0012486503, -0.048617754, 0.01699438, 0.0029976703, 0.019851036, -0.0131824715, -0.021561392, 0.03022234, 0.025273226, 0.048654146, -0.007778477, -0.018095193, -0.015274927, 0.017631214, 0.0136919385, -0.008824704, -0.0035708211, -0.04224941, -0.010962648, 0.010453181, 0.0075055477, -0.042467754, 0.025291422, 0.0041553443, 0.054767754, -0.019996598, 0.0023426407, 0.027820563, -0.07620178, 0.090248525, 0.034170713, 0.0026337649, 0.021706954, 0.048836097, -0.0073099486, -0.060990535, -0.0373003, -0.008256103, 0.018704735, -0.007896746, -0.008124187, 0.008979364, 0.009916421, 0.005940755, 0.019669084, 0.025455179, -0.0076101706, 0.031186689, 0.007860355, -0.01672145, -0.02065163, 0.021543197, 0.022962427, -0.0027019973, 0.01934157, 0.0013635078, 0.045233436, -0.035353404, -0.052875448, 0.055568345, 0.016666865, -0.0023380918, -0.019396154, 0.02145222, 0.0815148, 0.021197487, 0.052584324, 0.008337981, 0.0041530696, 0.020888167, 0.045124263, 0.010962648, 0.005094675, -0.010371302, 0.020851776, -0.04355947, 0.0330608, 0.056332547, -0.026055623, 0.00838347, 0.025946451, -0.0057224114, 0.0043077297, 0.031113908, 0.01687611, 0.04355947, 0.010789794, -0.04203107, -0.025436984, 0.015102072, -0.006204586, 0.02760222, 0.007273558, -0.008192419, -0.017321894, -0.050036985, 0.034734767, -0.017149039, 0.06128166, -0.00957071, -0.07511006, 0.015420489, -0.0037459508, -0.12816747, 0.019250592, 0.03233299, 0.04283166, -0.02141583, -0.027056362, -0.027456658, 0.0100255925, -0.03187811, -0.013309838, -0.03637234, -0.050801188, -0.06171835, -0.010771599, -0.078312434, 0.013337131, -0.010089275, -0.037736986, 0.0315142, -0.020469675, -0.0050491868, -0.005840681, -0.020160357, 0.033388317, 0.052693494, 0.0036617976, 0.004025703, 0.024145119, -0.03948373, -0.028348226, -0.034625594, -0.052839056, 0.006027182, -0.0017683526, 0.024163315, -0.0015875371, -0.0033115386, -0.022907842, 0.045015093, -0.03433447, 0.026856214, 0.03095015, -0.0001471258, 0.012882249, -0.022343788, -0.036572486, 0.011362945, 0.0024267938, 0.028493788, 0.015129365, -0.014920119, 0.0634287, 0.010052885, -0.04679823, 0.004089386, -0.016366644, 0.0014169564, 0.03710015, 0.00741912, -0.0076329145, 0.021033728, 0.01580259, -0.012491051, -0.0046625375, -0.0063774413, 0.037081953, 0.033097193, -0.027511245, -0.012864054, -0.024054144, 0.006336502, 0.00722807, 0.03095015, 0.0211429, 0.029476333, -0.026947191, -0.0511287, -0.021634173, -0.008055954, -0.041739944, 0.03755503, 0.0073144976, 0.028621156, 0.04559734, -0.02272589, -0.013901184, -0.021907102, 0.04363225, 0.008474446, 0.18675622, -0.027929734, 0.050837576, -0.0484358, -0.031150298, -0.03737308, 0.019905623, 0.012400075, 0.023362724, 0.007523743, -0.016939795, -0.02783876, 0.022980623, 0.015893565, -0.0005174279, 0.016548596, -0.02656509, 0.0073827296, 0.06466598, 1.0927822e-05, 0.02967648, -0.023471896, 0.07634734, 0.03271509, -0.009525223, 0.005886169, 0.04559734, 0.05735148, -0.022998817, -0.0036117607, 0.020087576, 0.009452442, 0.0125183435, 0.052111246, -0.0055495566, 0.011972486, -0.06288284, -0.024163315, 0.0075100968, 0.04679823, -0.030495267, -0.044760358, -0.01411043, -0.03413432, 0.010789794, -0.050764795, -0.037991717, 0.017321894, -0.0319145, 0.021597782, -0.053967163, -0.011735948, -0.02591006, 0.059607696, -0.05309379, 0.0019457564, -0.027620416, 0.011626775, -0.0002442146, 0.035808288, 0.029822044, -0.028766718, 0.024709173, 0.038573965, 0.023235356, -0.023326334, -0.035626333, -0.050000593, -0.037736986, 0.01968728, 0.04221302, 0.028821303, -0.036900003, -0.011872412, 0.016020933, 0.074018344, -0.01799512, 0.0476716, -0.003943824, 0.0063228556, 0.007569231, -0.010671524, 0.04759882, -0.028421007, 0.028930476, 0.02580089, -0.048581365, 0.031932693, 0.0034957658, -0.06608521, 0.029057842, -0.006013536, -0.028475594, 0.00930233, -0.00033803395, -0.010362205, -0.055495564, -0.0078831, 0.01122648, -0.0015784395, -0.034552813, -0.028075298, 0.0057678996, -0.029003257, 0.031859912, 0.028111689, 0.045415387, 0.035007693, 0.004282711, -0.004917271, -0.026019232, 0.017094454, -0.0207608, -0.030367902, 0.057933733, 0.06244616, 0.0010405418, 0.02711095, -0.020032989, 0.07998639, -0.0122272195, -0.03817367, -0.0005947578, 0.060335506, -0.017076258, 0.040429883, 0.014747264, -0.023107989, -0.037736986, 0.011990681, -0.022889646, -0.008779217, -0.021033728, 0.010753403, 0.044141717, -0.019905623, 0.012936835, 0.036317755, -0.03160518, 0.017039867, 0.03437086, -0.002472282, -0.028402813, -0.023690239, 0.006341051, -0.015866274, -0.010835282, -0.017503846, -0.007328144, 0.015966346, -0.030167753, 0.003563998, -0.04563373, -0.014874631, -0.020560652, 0.00016972773, 0.00033689674, -0.0049718567, 0.06142722, 0.0020617512, 0.002126572, -0.0017171784, 0.017449262, 0.010162056, 0.0075373896, 0.031550594, -0.0071188984, 0.015939055, 0.02045148, -0.01088077, -0.018586466, 0.009943713, 0.008606361, 0.06510267, 0.06284645, 0.02714734, -0.04483314, 0.03602663, 0.010562353, -0.0029521822, 0.030113168, 0.037882548, 0.005558654, -0.0010644231, -0.014374261, 0.020123966, 0.048472192, -0.038392015, 0.01160858, -0.0027747783, -0.070342906, 0.05567752, 0.011053625, -0.034006953, 0.010917161, 0.004567012, -0.010871672, 0.027456658, 0.030204143, -0.020506067, -0.010980844, -0.017722191, 0.02480015, 0.036008433, -0.02587367, -0.0030931954, 0.007896746, 0.026201185, 0.000325809, -0.0024995748, -0.02168876, 0.04355947, -0.042649705, -0.027820563, 0.007082508, 0.02452722, -0.021943493, 0.03233299, -0.0361358, -0.036281362, 0.07005178, -0.028730327, 0.0007931999, -0.05247515, 0.0053767017, 0.06877811, -0.026237575, 0.005212944, -0.01295503, -0.0053767017, 0.012718492, 0.01295503, 0.003814183, -0.0026087465, -0.0069869827, 0.0073827296, 0.008196968, -0.007778477, 0.055495564, 0.019396154, 0.00695969, -0.008483543, -0.018995859, 0.04617959, 0.046689056, -0.052875448, 0.058879886, -0.004967308, 0.028330032, 0.04818107, -0.016084617, 0.020524262, -0.01649401, 0.021634173, 0.02587367, -0.022161836, -0.0021095139, 0.018795712, 0.009256843, -0.04770799, -0.001347587, 0.022907842, 0.022616718, -0.022325592, 0.015538759, 0.004694379, 0.044068936, 0.019796452, -0.028530179, -0.053603258, 0.0013635078, 0.012390977, -0.049563907, -0.047380477, -0.029239794, 0.0015659302, -0.03588107, 0.0037823413, -0.0035549004, 0.044578403, 0.034152515, 0.063501485, -0.020597043, -0.0015943603, -0.021051925, 0.08202427, 0.0442145, 0.007555585, 0.018213462, -0.012281805, 0.028166274, 0.018850297, -0.023126185, 0.016621377, -0.03675444, 0.057060357, -0.029803848, -0.041667163, -0.027402073, 0.038428403, -0.00849719, -0.008829254, -0.04836302, -0.04083018, 0.010453181, 0.019614499, 0.025746303, -0.0008415311, 0.035171453, 0.0070870565, -0.0016853366, 0.024035947, 0.021361243, 0.0422858, -0.06972426, -0.02248935, 0.025746303, -0.03195089, 0.010262131, -0.02825725, 0.02476376, 0.039956808, 0.0074100224, 0.04363225, -0.02218003, -0.019050445, 0.0010240524, 0.018513685, -0.0565145, -0.06936036, -0.023362724, -0.018095193, -0.0442145, -0.011808729, 0.036990978, 0.052038465, -0.0476716, -0.029367162, 0.03395237, 0.0067322487, -0.012172634, -0.085590534, 0.01361006, -0.015293122, -0.0037527739, 0.0014431122, -0.011672264, -0.022998817, -0.062264204, 0.0054494827, 0.032041866, 0.047416866, -0.027693197, -0.03633595, -0.01914142, 0.06943314, -0.056769233, -0.016348448, 0.04337752, 0.0016489461, 0.011745045, 0.016776036, -0.002093593, 0.063137576, -0.03213284, 0.06131805, -0.003664072, -0.008538129, -0.012909542, -0.0019002683, -0.012118048, 0.009243196, -0.027893344, -0.015748003, -0.008374372, 0.013983063, -0.0011320867, 0.021743344, -0.011672264, -0.004739867, -0.008174224, 0.008569971, -0.023672042, -1.5938627e-05, 0.00082163006, -0.016011836, 0.0123000005, -0.03180533, 0.0017467457, -0.01633935, -0.010626036, 0.059680477, -0.022653108, 0.012627516, -0.17278226, -0.07030651, 0.03195089, -0.02480015, -0.048690535, -0.021361243, -0.00061067863, 0.055422783, -0.03475296, -0.04359586, -0.0173037, 0.04763521, 0.041121304, -0.004655714, -0.02449083, 0.006682212, -0.027056362, 0.010498669, -0.029530918, -0.076711245, -0.0034389056, 0.0034980401, -0.054258287, 0.0086245565, -0.00865185, 0.031095712, 0.012118048, -0.02994941, -0.024345268, -0.024690978, 0.010116569, 0.007837611, 0.016739646, 0.03353388, 0.010553255, 0.0014374261, -0.016075518, 0.017112648, 0.003859671, -0.0080013685, 0.018295342, 0.029130623, 0.01341901, -0.041121304, 0.0042122044, 0.00595895, 0.0005720137, -0.0010974021, -0.03540799, -0.0044965055, -0.0044851336, 0.011317456, 0.027383877, -0.018331733, 0.009370563, -0.01972367, -0.021670563, -0.04879971, -0.019505326, 0.05094675, -0.0001163502, -0.0009785643, -0.008642752, 0.003748225, -0.017167235, 0.009743566, -0.03740947, -0.006181842, -0.015556954, 0.034389056, -0.050655626, 0.04417811, 0.04825385, -0.060844973, 0.011817826, -0.04879971, 0.031841718, 0.0053494084, -0.030804588, -0.010971746, -0.014665386, 0.0073144976, -0.025891865, -0.04625237, 0.024891125, 0.019632693, 0.0020958674, 0.03828284, 0.034661986, -0.010962648, -0.050801188, -0.016512206, -0.044469234, -0.038501184, -0.062264204, 0.0052083954, 0.007732989, -0.0044669383, -0.024126925, -0.07474616, -0.046543494, -0.020742605, -0.0008819019, -0.043814205, -0.00407574, 0.07027012, 0.04698018, -0.034425445, 0.03413432, -0.008529032, -0.036900003, 0.0039051592, 0.003452552, 0.055422783, -0.029476333, -0.008806509, -0.03955651, -0.012145341, 0.0022994268, -0.026073817, -0.014419749, 0.074527815, 0.014692678, -0.04679823, 0.0045192493, 0.020578848, 0.022361984, -0.0024313426, 0.018195268, -0.040684618, 0.004858136, 0.04770799, -0.020633433, -0.013855696, -0.0062682694, -0.0021902553, 0.010125666, 0.034734767, -0.0065184543, -0.025200445, -0.031113908, -0.0046284213, -0.03548077, 0.0069960803, -0.018240755, 0.0043850592, 0.031859912, -0.017285503, -0.03287885, -0.0062682694, 0.017385578, 0.0054039946, -0.03129586, -0.015411392, -0.01803151, -0.015356805, 0.04894527, -0.04013876, 0.0056723747, 0.020287722, -0.0065184543, -0.06328314, -0.011899705, -0.02314438, 0.0026337649, 0.00972537, 0.009998299, -0.021124706, -0.009643491, 0.024581807, 0.02587367, -0.00021166213, -0.04479675, 0.010198447, 0.039592903, 0.005140163, 0.01572071, -0.0013521358, 0.025327813, -0.024345268, 0.070888765, -0.022689499, -0.028129883, 0.018040607, 0.032897044, 0.027092753, -0.00849719, -0.029330771, 0.0016466717, -0.0077875745, -0.0058998154, 0.009238647, 0.0010740893, 0.01872293, 0.009934616, -0.010989942, 0.002902145, -0.009425148, 0.029330771, 0.037882548, -0.08770119, -0.032114647, -0.020869972, -0.01818617, -0.043159176, -0.019305179, 0.00915222, 0.007155289, 0.0051629073, 0.029021451, 0.0045965794, -0.007892197, -0.038464796, 0.011053625, 0.041594382, -0.021888906, 0.031150298, 0.021506807, -0.02017855, -0.04486953, 0.017240016, 0.045888465, -0.056259766, 0.00542219, 0.018440904, -0.030185949, -0.006472966, -0.0054722265, -0.028093493, -0.022616718, 0.03437086, -0.0026928997, 0.0028907731, -0.011845119, 0.030931955, -0.04745326, -0.0058179367, 0.017594824, -0.035171453, -0.004482859, 0.046616275, 0.0139102815, -0.005585947, 0.004255418 ], "context": "生命の起源 [SEP] 1959年、ジョン・バーナルによって「粘土の界面上でアミノ酸重合反応が起きる」とした「粘土説」が提唱された。何らかの界面は化学反応が起き易くなっており、化学反応の触媒としての機能を界面が有することは当時から良く知られていた(詳しくは酵素の項を参照)。この説自体は、赤堀四郎によって提唱された「ポリグリシン説」を基にしている。こうした界面上で有機物が発生し、それらがポリマーに進化していく様子をさらに具体的に論じたのが、ドイツの弁理士ギュンター・ヴェヒタースホイザー(Günter Wächtershäuser)が1988年に論文で発表した「表面代謝説」である。主な趣旨は以下の通り。", "answers": [ "表面代謝説" ], "id": "a111367p18q4", "context_embedding": [ -0.017300418, -0.007605975, -0.035993148, 0.0012241527, -0.014995577, -0.037366647, -0.03958682, -0.0061619217, 0.0013782008, 0.016444335, 0.0036689304, 0.04873092, -0.0539615, 0.027281791, 0.0035630958, 0.033058003, 0.013857268, -0.016566632, -0.003156221, 0.001354682, -0.00120181, -0.04937063, 0.022653293, 0.034074016, 0.021505577, 0.071308956, 0.012408511, 0.0026176407, 0.00078141165, -0.0052729114, 0.053585198, 0.011919321, -0.007643605, 0.0032855743, -0.0046026264, 0.00034719607, 0.022258177, -0.016858265, -0.03928578, -0.014384089, -0.050838206, -0.03386705, 0.01169354, -0.0058702887, -0.010752789, -0.055353813, 0.022220548, -0.021129277, 0.034732543, 0.017949536, -0.0459463, 0.022239363, 0.049445894, 0.018570432, 0.01910666, 0.011815838, -0.028786993, 0.0024882874, -0.07781895, -0.0068863, -0.020414306, 0.044252947, -0.061412252, -0.028918698, 0.03454439, 0.024309017, -0.0070556356, 0.0097085545, -0.0075918636, -0.036200114, 0.0031515171, 0.026472744, 0.025983553, -0.036388263, -0.02342471, -0.014421719, 0.038119245, -0.014242976, -0.0035819109, 0.042898264, 0.034864247, 0.006637001, 0.00476961, 0.003908822, 0.022578033, 0.02701838, -0.048015952, 0.025061617, -0.0231613, -0.003951156, -0.010527008, 0.00611018, 0.01925718, -0.03000997, -0.015550621, 0.009134696, -0.046548378, 0.050160866, 0.016162109, 0.016707744, 0.01778961, 0.026322223, 0.01650078, -0.04805358, -0.016641892, 0.0033490749, -0.0003889419, 0.024384277, -0.03106361, -0.02013208, 0.0043204008, 0.022991965, 0.03243711, 0.03000997, -0.038401473, -0.019755779, 0.010414118, 0.0010118957, 0.0031797397, 0.006684039, -0.02077179, 0.06389584, 0.0550904, -0.0139513435, -0.0071167843, -0.05339705, 0.018231763, -4.3436256e-05, -0.019021994, 0.011354869, 0.0077282726, 0.014355866, -0.04549474, 0.011947542, -0.043011155, -0.018796213, 0.052418668, 0.019398294, 0.011336055, -0.036726933, -0.023706935, 0.050988726, 0.018758582, -0.026548004, 0.0021131628, -0.08707595, -0.06344427, 0.0021766636, -0.019172514, 0.02444072, 0.010668121, -0.020640086, 0.022126473, 0.025513178, -0.028373063, -0.00758716, 0.034732543, 0.011759393, 0.017121676, -0.038909476, 0.00932755, -0.014242976, -0.012436734, 0.011110274, -0.014769797, 0.052079998, 0.02267211, 0.037460722, -0.050650056, -0.0077376803, -0.0041322503, 0.007304935, 0.0042827707, -0.028147282, -0.027846241, 0.013085852, 0.0023271837, -0.006077254, -0.00917703, -0.002690549, -0.025851848, -0.017695533, 0.0037606538, 0.03578618, -0.049558785, 0.009336958, -0.04116728, 0.042634852, 0.028993959, 0.047526762, -0.005442247, -0.065438665, 0.02664208, 0.03113887, -0.037027974, -0.0348078, 0.051553175, 0.04150595, 0.006839263, -0.001974402, -0.029483149, 0.051289767, 0.028391877, 0.03813806, -0.03988786, 0.004049935, -0.038909476, -0.0031350541, 0.050047975, -0.025720144, 0.042559594, -0.03413046, 0.004680238, -0.0024600648, -0.0058373623, -0.03548514, 0.013151704, 0.0043815495, 0.027714536, 0.018241169, -0.049521152, 0.026886676, -0.04105439, 0.021656098, 0.01619974, -0.037780575, -0.018626878, 0.063293755, 0.010282413, -0.03206081, -0.015861068, 0.042559594, 0.043613236, -0.06536341, -0.009031214, -0.017799016, 0.009050028, 0.022258177, -0.00510828, 0.015926922, 0.005479877, 0.015409508, -0.022032397, -0.027037196, -0.048956703, 0.015936328, -0.019163106, -0.028072022, -0.00031103592, -0.015682327, 0.0070744506, 0.021637281, -0.03663286, -0.014346459, 0.037441906, -0.002129626, 0.024929913, 0.03098835, 0.082936645, -0.01899377, 0.043199304, 0.009534515, 0.018645693, 0.022766184, 0.082936645, -0.0072626006, -0.06762121, 0.005710361, 0.03132702, 0.025663698, 0.04045231, 0.025005173, -5.8172245e-05, -0.020978756, -0.021637281, 0.011147904, 0.0112607945, 0.0037865243, 0.05347231, 0.04763965, 0.012737774, 0.009581553, -0.0016216203, 0.036087222, -0.011166719, -0.051139247, -0.014628684, 0.01604922, -0.017291011, -0.018786805, 0.04658601, 0.019323034, 0.029652484, 0.013979565, -0.09196786, -0.03629419, -0.024628872, -0.15623999, -0.0056209895, -0.017206343, 0.0264163, 0.01747916, -0.009906112, -0.03162806, 0.0043839016, -0.03206081, -0.010649306, -0.024252571, -0.041618843, -0.041957512, 0.025061617, -0.045043178, 0.0109503465, -0.00955333, 0.0019861613, 0.010470563, 0.0049201297, 0.004642608, 0.039699707, 0.034149274, 0.021731358, 0.04790306, -0.024083236, 0.0093651805, 0.009821445, -0.052268147, -0.024534797, -0.04082861, -0.032041993, 0.00224722, 0.03954919, 0.008081054, 0.02349997, -0.028429506, 0.033133265, 0.008236279, -0.044553988, -0.0026976047, 0.05414965, -0.033095635, -0.01335867, 0.006307738, 0.0009042973, -0.011373685, 0.0038194507, -0.018984362, 0.028147282, 0.0118816905, 0.012455548, -0.019191328, -0.057950284, -0.04124254, -0.013179927, 0.02016971, 0.00421927, -0.032756962, 0.018457543, 0.02671734, -0.0018132983, 0.005150614, -0.029520778, -0.020376675, 0.030950721, 0.018833842, -0.01846695, 0.057498727, -0.052644446, 0.011712355, 0.037667684, 0.049333002, 0.01225799, -0.014205346, 0.025588438, -0.07025532, -0.01354682, -0.010423525, -0.07326572, 0.043537974, 0.005080058, -0.00758716, 0.0146475, -0.0319291, 0.0017392142, -0.022220548, 0.023706935, 0.07134659, 0.23330635, 0.01839169, 0.005954956, 0.0009248762, 0.009906112, -0.01021656, 0.028109651, -0.014562831, 0.0043368638, 0.0003424923, -0.0010912716, -0.009205253, 0.021825433, -0.035221733, -0.010367081, 0.0034008163, -0.0046473118, -0.012624884, 0.050010346, 0.0077470876, 0.004835462, 0.019473555, 0.018175317, -0.011439537, -0.057987917, 0.00024680025, 0.04045231, 8.12868e-05, -0.0040781572, -0.0009148807, -0.0107433805, -0.030367455, 0.021975953, -0.0074037137, -0.010574046, -0.0036124852, 0.02652919, 0.0014381737, 0.03196673, 0.076765314, 0.00034954795, -0.034732543, 0.014402904, -0.0018085946, -0.025343843, -0.043575604, -0.023669304, -0.009388699, -0.044177685, -0.009934335, -0.042785373, 0.03463847, 0.00024312544, -0.004934241, -0.005762102, 0.011637094, 0.0129165165, 0.0053152456, -0.006679335, -0.0034407983, 0.050687686, 0.011947542, 0.032305405, -0.0012135693, -0.027432311, -0.05606878, 0.011665317, -0.08271086, 0.0033749456, 0.006994487, 0.08165722, -0.0038547288, -0.0011647678, 0.021580838, 0.072663635, 0.0543378, 0.036726933, 0.049709305, 0.015146097, 0.0170276, -0.035804998, 0.0027822722, -0.03802517, -0.013349262, 0.011213757, -0.00041569452, -0.008866582, 0.006905115, -0.0046284967, -0.056746125, -0.037968725, -0.026359854, 0.0026058813, 0.05418728, -0.01373497, -0.003036275, -0.03576737, -0.0109503465, -0.038683698, -0.044629246, -0.07066924, -0.06118647, 0.010818641, 0.042220924, 0.016246777, -0.0033443712, 0.0045273663, 0.027770981, 0.005611582, -0.0017098157, 0.038758956, 0.015033207, -0.020734161, -0.021825433, 0.0416941, 0.009073547, -0.025419103, 0.029163294, -0.0416941, 0.029652484, 0.022446329, -0.027752167, 0.014741574, 0.04688705, -0.021637281, -0.012765996, 0.03659523, -0.05475173, -0.042145662, 0.0070556356, 0.0070791543, -0.017432123, -0.032644074, -0.019849854, 0.051365025, -0.006905115, 0.036124855, 0.041280173, 0.0024436018, 0.017911907, 0.013528005, 0.0040193605, -0.05287023, -0.007568345, -0.024534797, -0.05448832, 0.020828236, -0.031176502, -0.028504767, 0.034149274, 0.032756962, -0.027488755, -0.014026604, -0.0005529854, 0.014910909, 0.04150595, -0.0048542772, 0.009416921, 0.03954919, -0.014722759, -0.017488569, 0.016190331, 0.0071450067, -0.024779392, -0.003095072, 0.021467946, -0.010357673, 0.011627687, 0.001064225, -0.011411315, 0.04854277, -0.027695721, -0.0081563145, 0.055015143, 0.06272931, 0.104536295, -0.03270052, 0.032681704, 0.03973734, 0.028203728, -0.0012112174, -0.0005591591, 0.030950721, -0.015644696, -0.00097602955, -0.010263598, 0.009426329, -0.033246156, 0.04037705, -0.0021613764, -0.01668893, 0.097687624, 0.06284219, -0.02043312, 0.06784699, -0.03307682, 0.049408264, 0.0006691094, 0.017535606, -0.011486575, 0.017516792, -0.0027822722, 0.017422715, -0.01766731, -0.03019812, -0.022841444, 0.0398126, 0.050123233, -0.0796252, -0.009393402, 0.025607252, -0.023067225, 0.0010501137, 0.020150894, -0.03996312, 0.003483132, -0.0041369544, 0.036425892, -0.020038005, -0.014205346, 0.008800729, -0.011223164, 0.018720953, -0.001354682, -0.0031491653, 0.013349262, 0.0110538285, -0.03273815, -0.038232137, -0.014026604, 0.00060913654, -0.038871847, -0.021467946, -0.047526762, 0.04109202, 0.025475549, -0.011740577, 0.018777398, -0.010818641, -0.0020402547, -0.017526198, -0.0699919, -0.02372575, 0.038420286, -0.017695533, -0.04696231, 0.017018193, 0.008372688, 0.075899825, -0.0016286758, 0.009849668, 0.019849854, 0.015635287, -0.02611526, 0.041731734, 0.011712355, 0.011495982, -0.01017893, -0.016227962, -0.01971815, -0.03177858, 0.016961748, 0.0068251514, -0.017488569, -0.064761326, 0.03548514, 0.03557922, -0.002187247, -0.0045908666, -0.0058749923, -0.022220548, 0.027808612, -0.013687933, -0.039850228, -0.013725563, -0.01362208, -0.007201452, -0.0054328395, 0.031533986, -0.012173323, -0.0011124385, 0.028580027, 0.04711283, -0.00028722317, -0.011533612, 0.0044756248, 0.0010477619, 0.04718809, -0.016735967, -0.03454439, 0.030386271, 0.03132702, -0.014318236, 0.059982307, 0.008292723, 0.05938023, 0.0036360042, 0.044666875, 0.004541477, 0.03390468, -0.014562831, 0.005508099, -0.012888294, -0.029050402, -0.029182108, 0.037291385, -0.014045418, -0.049859826, 0.0023307116, -0.0010318867, 0.0077564954, 0.0056021744, 0.033923496, -0.010893901, -0.01154302, -0.0044403467, 0.011448945, -0.09219363, -0.006420628, 0.008937138, 0.0199063, 0.012210953, -0.007370787, 0.011317239, -0.016434927, 0.013819638, 0.0463226, 0.0073190457, -0.0069756717, 0.0013911361, -0.010301228, -0.044215314, -0.0064582583, 0.0043180487, 0.03277578, 0.0055457293, 0.0022766183, -0.050951097, 0.04075335, -0.016180923, -0.017761387, -0.03341549, 0.049182482, -0.013829046, 0.0070085977, 0.049671672, -0.0017168713, 0.025682513, -0.016848858, -0.0029798301, 0.010498785, 0.021355057, -0.028410692, -0.022483958, -0.0065099997, 0.016519595, -0.019925114, -0.03270052, 0.027996762, 0.005131799, 0.046698898, -0.012267399, -0.009802629, 0.008081054, 0.0019661705, 0.02451598, 0.017601458, -0.029972339, 0.01324578, -0.04827936, 0.024779392, -0.0033843531, 0.001006016, -0.0135374125, 0.01006604, -0.034337427, -0.0029445519, 0.035259362, 0.0016721856, -0.009859075, 0.0053340606, -0.012869479, -0.055843003, -0.034487948, 0.0045979223, 0.009115881, 0.0052540964, 0.0032244255, 0.049483523, 0.032756962, -0.04647312, 0.0058044363, -0.027676906, -0.0005559253, -0.14013433, -0.006575852, 0.006255997, -0.04760202, -0.02970893, -0.019379478, -0.008852471, 0.011533612, 0.011119681, -0.010630491, -0.03988786, 0.04026416, 0.021392686, 0.0061431066, -0.060132828, 0.0011377212, 0.017695533, 0.0011765272, -0.014195939, -0.0604715, 0.008617283, 3.5755904e-05, -0.008048128, -0.023744565, -0.022784999, -0.010414118, 0.007333157, -0.023067225, -0.028768178, -0.002730531, 0.023669304, 0.007859978, -0.019360663, 0.034186907, -0.025343843, -0.063105606, 0.001335867, -0.027714536, 0.06351954, 0.069465086, 0.07597508, 0.033961125, 0.041806992, -0.0062701083, 0.03663286, -0.0005597471, -0.045156065, -0.0032032586, -0.035372254, 0.0021178667, 0.037761763, 0.012860072, 0.03864607, 0.007681235, -0.033885866, -0.01717812, -0.015766993, -0.02372575, -0.029765375, 0.02720653, -0.039059997, -0.007878793, 0.0038994146, -0.018833842, -0.049069595, 0.011204349, -0.055466704, -0.0027775685, 0.0071073766, -0.014515794, -0.045532368, -0.0047202203, 0.0348078, -0.05317127, -0.0026458632, -0.0401889, -0.04124254, 0.007859978, 0.008894805, -0.035974335, -0.0117688, 0.029200923, -0.048467513, -0.028674103, 0.044629246, 0.0056021744, -0.037329014, 0.030216934, 0.03206081, -0.006994487, -0.04120491, 0.012907109, -0.059154447, -0.031007167, -0.073152825, 0.028824624, 0.042070404, -0.021373872, -0.06103595, -0.060772542, -0.028636472, -0.0028128466, 0.014581647, -0.009007694, -0.0037677092, 0.010733973, 0.0010995032, -0.00228485, 0.028410692, 0.03435624, -0.024892282, 0.01695234, -0.014976762, -0.002072005, -0.02795913, 0.00239774, -0.019755779, 0.014440534, -0.059982307, 0.045005545, 0.014101864, 0.056557976, 0.000638535, -0.021656098, 0.0006814568, 0.01369734, 0.0319291, -0.030461531, 0.014694537, -0.009393402, -0.010188337, -0.011862875, 0.03947393, 0.009670924, -0.0042733634, -0.011129089, -0.011063237, 0.02667971, -0.024666501, -0.024478352, -0.006307738, -0.04048994, -0.038401473, -0.0035325214, -0.015936328, -0.03832621, 0.008904212, -0.049107224, 0.0010148356, -0.0047907764, -0.009007694, -0.00092605216, -0.04022653, 0.00503302, 0.0048683886, -0.016246777, 0.008913619, -0.024497166, 0.0042474926, -0.018335246, 0.014741574, -0.03832621, 0.0019320681, -0.057611614, -0.0034337426, -0.010508193, -0.00036277727, -0.021373872, -0.072287336, 0.029069219, 0.025569623, 0.02626578, -0.0011300776, -0.024986356, 0.04199514, -0.02387627, -0.01332104, -0.029652484, 0.051139247, -0.007431936, 0.015418915, 0.0009525108, -0.026284594, 0.023330634, 0.010508193, 0.048015952, -0.0042851227, 0.014205346, 0.03894711, 0.014064234, -0.0009613303, 0.008955954, -0.02084705, 0.01850458, 0.016378481, -0.03640708, 0.009035917, -0.0024153793, 0.010752789, 0.025663698, -0.07089502, -0.03194792, -0.102504276, -0.0048542772, -0.04617208, -0.00039776144, -0.027733352, -0.013603265, -0.018796213, 0.01017893, 0.01597396, -0.00840091, -0.017112268, 0.06833618, 0.0064770733, 0.0026976047, -0.032380663, -0.049897455, -0.022860259, -0.024572426, 0.007982275, 0.06912641, 0.011044421, 0.0019038457, -0.008791322, 0.0049624634, -0.028391877, 0.0002495931, -0.031722136, 0.016726559, -0.07055636, -0.032756962, 0.01683945, 0.025419103, 0.04060283, -0.021844247, -0.01854221, -0.018805621, 0.016209146, 0.044704508, 0.010696343, 0.012690736, 0.05524092, -0.025870664 ] } } ] } } CPU times: user 6.91 ms, sys: 0 ns, total: 6.91 ms Wall time: 3.14 s
ハイブリッドクエリを実際に実行し、Sparse neural search と Sparse search によるハイブリッド検索が実行できることを確認します。
%%time
index_name = "jsquad-hybrid-search"
query = "M"
payload = {
"size": 10,
"query": {
"hybrid": {
"queries": [
{
"neural_sparse": {
"question_sparse_embedding": {
"query_text": query
}
}
},
{
"neural": {
"question_embedding": {
"query_text": query, # テキストをベクトルに変換し
"min_score": 0.7
}
}
}
]
}
},
"_source" : False,
"fields": ["question", "answers", "context"]
}
# 検索 API を実行
response = opensearch_client.search(
body = payload,
index = index_name,
filter_path = "hits.hits",
search_pipeline = hybrid_search_pipeline_id
)
# 結果を表示
pd.json_normalize(response["hits"]["hits"])
CPU times: user 347 μs, sys: 4.05 ms, total: 4.39 ms Wall time: 111 ms
_index | _id | _score | fields.question | fields.answers | fields.context | |
---|---|---|---|---|---|---|
0 | jsquad-hybrid-search | a379233p6q1 | 0.700000 | [ケプラーの式を導き出す際、Mが主星の質量、mが伴星の質量であるとするとき、mの影響は通常無... | [Mはmよりもずっと大きいため, ここでGは重力定数、Mは主星の質量、mは伴星の質量である。... | [軌道長半径 [SEP] ここでGは重力定数、Mは主星の質量、mは伴星の質量である。通常、M... |
1 | jsquad-hybrid-search | a379233p6q2 | 0.626109 | [軌道長半径において、Gは重力定数とするとMは] | [主星の質量, 伴星の質量] | [軌道長半径 [SEP] ここでGは重力定数、Mは主星の質量、mは伴星の質量である。通常、M... |
2 | jsquad-hybrid-search | a258209p4q3 | 0.367423 | [m5Cとは何か] | [5-メチルシトシン] | [核酸塩基 [SEP] DNAとRNAには、核酸の鎖が形成された後に修飾が行われた、非標準的... |
3 | jsquad-hybrid-search | a1468p21q1 | 0.256448 | [ムアンというラオス語の意味は何か] | [「郡」の他に「街」, 郡] | [ラオス [SEP] ヴィエンチャン都と県の下には100前後の村(バーン)から成る郡(ムアン... |
4 | jsquad-hybrid-search | a20898p13q3 | 0.195211 | [σは変換前の座標系における応力テンソル、σ' は変換後の座標系における応力テンソル、A は... | [転置行列] | [応力 [SEP] ここで、 σは変換前の座標系における応力テンソル、σ' は変換後の座標系... |
5 | jsquad-hybrid-search | a1468p21q0 | 0.191809 | [ラオス語でムアンとは、郡という意味の他、どういう意味があるか] | [街] | [ラオス [SEP] ヴィエンチャン都と県の下には100前後の村(バーン)から成る郡(ムアン... |
6 | jsquad-hybrid-search | a1468p21q2 | 0.173720 | [ムアンにはラオス語でどんな意味があるか] | [「郡」の他に「街」という意味, 郡] | [ラオス [SEP] ヴィエンチャン都と県の下には100前後の村(バーン)から成る郡(ムアン... |
7 | jsquad-hybrid-search | a20898p13q0 | 0.170728 | [σは変換前の座標系における応力テンソル、σ' は変換後の座標系における応力テンソル、A は... | [転置行列] | [応力 [SEP] ここで、 σは変換前の座標系における応力テンソル、σ' は変換後の座標系... |
8 | jsquad-hybrid-search | a87893p0q2 | 0.037928 | [ヘクトメートル(hectometre, 記号hm)は、国際単位系の長さの単位だが、何メートル?] | [100メートル] | [ヘクトメートル [SEP] ヘクトメートル(hectometre, 記号hm)は、国際単位... |
9 | jsquad-hybrid-search | a10743p24q1 | 0.000700 | [マーラーのフルネームは?] | [グスタフ・マーラー] | [グスタフ・マーラー [SEP] 現在、マーラーの交響曲作品はその規模の大きさや複雑さにも関... |
ハイブリッド検索で様々な検索を組み合わせられることを確認してきました。ハイブリッド検索は必ずしもベクトル検索との組み合わせが必須ではなく、テキスト検索同士の組み合わせも可能です。様々な場面での利用を検討してみてください。
時間がある方は、続いて以下のラボも実施してみましょう。
index_name = "jsquad-hybrid-search"
try:
response = opensearch_client.indices.delete(index=index_name)
print(json.dumps(response, indent=2))
except Exception as e:
print(e)
{ "acknowledged": true }