1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Databricks Vector Searchでハイブリッド検索?

Last updated at Posted at 2024-05-28

免責:
この記事の内容は、2024/5/28時点でDatabricks社の公式ドキュメントに記載されておらず(たぶん)、ただの一般ユーザの実験記録です。公式な内容ではありませんのでご注意ください。

導入

Databricks Vector Searchについて、helpでPython APIの使い方を確認していたのですが。(databricks_vectorsearchのバージョンは0.36です)

from databricks.vector_search.client import VectorSearchIndex
help(VectorSearchIndex.similarity_search)
出力
Help on function similarity_search in module databricks.vector_search.index:

similarity_search(self, columns, query_text=None, query_vector=None, filters=None, num_results=5, debug_level=1, score_threshold=None, use_hybrid=False)
    Perform a similarity search on the index. This returns the top K results that are most similar to the query.
    
    :param columns: List of column names to return in the results.
    :param query_text: Query text to search for.
    :param query_vector: Query vector to search for.
    :param filters: Filters to apply to the query.
    :param num_results: Number of results to return.
    :param debug_level: Debug level to use for the query.
    :param score_threshold: Score threshold to use for the query.
    :param use_hybrid: Whether to use hybrid search or not.

ん?最後にuse_hybridのパラメータが追加されてる?

名前だけ見ると、Databricks Vector Searchでハイブリッド検索を実施するフラグに見えます。
Databricks Vector Searchは通常のベクトル検索のみ(Dense Vectorを使った検索のみ)という理解をしていたのですが、キーワード検索(Sparse Vectorを使った検索)といった別種の検索も追加された・・・?

2024/5/28時点でPython APIのドキュメントにもまだ記載がなく、正直挙動がわからず。

現時点で将来的な拡張を見越したパラメータ拡張だけの可能性もあるので、ひとまず試すだけ試してみました。

検索してみる

以下の記事で作成したVector Search EndpointとIndex(通常のテーブルから作成)を使って、use_hybridをTrue/Falseで切り替えた場合の挙動を確認してみます。

use_hybrid=Falseの場合

従来通りのベクトル検索(のはず)。

import pandas as pd

# 結果をPandas DFへ変換
def conv_related_docs_to_pdf(result):
    cols = [c["name"] for c in result["manifest"]["columns"]]
    return pd.DataFrame(result["result"]["data_array"], columns=cols)

result = index.similarity_search(
    query_text="Unity Catalogとはどのような機能なのか?",
    columns=["id", "context"],
    num_results=5,
    use_hybrid=False,
)

display(conv_related_docs_to_pdf(result))

image.png

類似文書を取得できました。

use_hybrid=Trueの場合

ハイブリッドサーチ?

result = index.similarity_search(
    query_text="Unity Catalogとはどのような機能なのか?",
    columns=["id", "context"],
    num_results=5,
    use_hybrid=True,
)

display(conv_related_docs_to_pdf(result))

image.png

use_hybrid=Falseのときと結果が異なっていますね。
特にスコアのつけ方が大きく変わっています。
ダミーのパラメータというわけではないようです。

検索性能の良し悪しを評価はしていませんが、なんらか新たな検索オプションが追加された?ということでいいのかな?

まとめ

今後オフィシャルに発表があるのだと思いますが、ますます利便性が高くなりそうですね。
詳細は公式アナウンスを待ちたいと思います。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?