Hub documentation
ベクトル類似度検索を実行する
シングルサインオン(SSO) 監査ログ ストレージリージョン プライベートデータセット用の Data Studio リソースグループ(アクセス制御) 高度な計算オプション 高度なセキュリティ トークン管理 サービスアカウント パブリッシャー分析 ゲーティンググループコレクション ネットワークセキュリティ ダウンロード分析 レート制限 ブログ記事
PRO Plan リポジトリ リポジトリの入門 リポジトリ設定 ストレージの制限 ストレージバックエンド (Xet) ローカルキャッシュ Pull Requests と Discussions 通知 コレクション Webhooks GitHub Actions ノートブック 次のステップ ライセンス
モデル モデルハブ モデルカード 評価結果 リーダーボードデータ ゲート付きモデル モデルのアップロード モデルのダウンロード 統合ライブラリ モデルウィジェット モデル推論 モデルのダウンロード統計 モデルリリースチェックリスト ハードウェア ローカルアプリ よくある質問 高度なトピック
データセット Datasetsの概要 Dataset Cards Gated Datasets Datasets のアップロード データセットのアップロード(LLM用) データのダウンロード ストリーミングデータセット 統合ライブラリ
Spaces Argilla Daft Dask Datasets データデザイナー Distilabel DuckDB Embedding Atlas fenic FiftyOne Lance Pandas Polars Spark WebDataset Zephon
Data Studio エージェントのトレース Datasets ダウンロード統計 Spaces 概要 Spaces GPU アップグレード Spaces ZeroGPU Spaces Dev Mode Spaces ディスク使用量とストレージ Spaces カスタムドメイン SpacesをMCPサーバーとして Spacesをエージェントツールとして Spaces を API エンドポイントとして利用する Gradio Spaces Streamlit Spaces 静的 HTML Spaces Docker Spaces Space を埋め込む Docker で Spaces を実行する Spaces 設定リファレンス HFでサインイン 注目のスペース Spaces 変更履歴 高度なトピック
ストレージバケット new コンテナイメージ new ジョブ ジョブの概要 クイックスタート 料金と請求 ジョブの管理 設定 Dockerイメージの使用 モデルのサービング モデルの学習 例とチュートリアル 大規模なデータセットの処理 ジョブのスケジュール設定 Webhook 自動化 リファレンス
エージェント エージェントの概要 AIエージェント向けHugging Face CLI Hugging Face MCP Server Hugging Face Agent Skills HF SDK を用いたエージェントの構築 llama.cppによるローカルエージェント エージェントライブラリ セッショントレース形式
その他 ベクトル類似度検索を実行する
Fixed-Length Arrays 機能は DuckDB バージョン 0.10.0 で追加されました。これにより、DuckDB のテーブルでベクトル埋め込みを使用できるようになり、データ分析がさらに強力になります。
array_cosine_similarity関数も導入されました。この関数は、2つのベクトルの間の角度のコサインを測定し、それらの類似度を示します。値が1の場合は完全に一致しており、0の場合は垂直、-1の場合は完全に反対方向であることを意味します。
この関数を用いた類似度検索の使い方を確認しましょう。このセクションでは、DuckDBを使用して類似度検索を実行する方法を説明します。
asoria/awesome-chatgpt-prompts-embeddings データセットを使用します。
まず、データセットからいくつかのレコードをプレビューします:
FROM 'hf://datasets/asoria/awesome-chatgpt-prompts-embeddings/data/*.parquet' SELECT act, prompt, len(embedding) as embed_len LIMIT 3;
┌──────────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬───────────┐
│ act │ prompt │ embed_len │
│ varchar │ varchar │ int64 │
├──────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼───────────┤
│ Linux Terminal │ I want you to act as a linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output insid… │ 384 │
│ English Translator… │ I want you to act as an English translator, spelling corrector and improver. I will speak to you in any language and you will detect the language, translate it and answer… │ 384 │
│ `position` Intervi… │ I want you to act as an interviewer. I will be the candidate and you will ask me the interview questions for the `position` position. I want you to only reply as the inte… │ 384 │
└──────────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴───────────┘
次に、類似度検索に使用する埋め込みを選択します:
FROM 'hf://datasets/asoria/awesome-chatgpt-prompts-embeddings/data/*.parquet' SELECT embedding WHERE act = 'Linux Terminal';
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ embedding │
│ float[] │
├─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ [-0.020781303, -0.029143505, -0.0660217, -0.00932716, -0.02601602, -0.011426172, 0.06627567, 0.11941507, 0.0013917526, 0.012889079, 0.053234346, -0.07380514, 0.04871567, -0.043601237, -0.0025319182, 0.0448… │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
では、選択した埋め込みを使用して、類似のレコードを検索しましょう。
SELECT act,
prompt,
array_cosine_similarity(embedding::float[384], (SELECT embedding FROM 'hf://datasets/asoria/awesome-chatgpt-prompts-embeddings/data/*.parquet' WHERE act = 'Linux Terminal')::float[384]) AS similarity
FROM 'hf://datasets/asoria/awesome-chatgpt-prompts-embeddings/data/*.parquet'
ORDER BY similarity DESC
LIMIT 3;
┌──────────────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬────────────┐
│ act │ prompt │ similarity │
│ varchar │ varchar │ float │
├──────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────┤
│ Linux Terminal │ I want you to act as a linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output insi… │ 1.0 │
│ JavaScript Console │ I want you to act as a javascript console. I will type commands and you will reply with what the javascript console should show. I want you to only reply with the termin… │ 0.7599728 │
│ R programming Inte… │ I want you to act as a R interpreter. I'll type commands and you'll reply with what the terminal should show. I want you to only reply with the terminal output inside on… │ 0.7303775 │
└──────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴────────────┘
以上です!DuckDBを使用してベクトル類似度検索に成功しました。
Update on GitHub