モジュール: Mongoid::SearchIndexable

次による拡張機能。
ActiveSupport::Concern
次のドキュメントに含まれます。
構成可能
定義:
lib/mongoid/search_indexable.rb

Overview

検索インデックスの管理に関する動作をカプセル化します。 この機能は、Atlas クラスターに接続されている場合にのみサポートされます。

名前空間で定義済み

Modules: クラスメソッド クラス: ステータス

インスタンス メソッドの概要を折りたたむ

インスタンス メソッドの詳細

#auto_ embedded_search(インデックス: nil, path: nil, limit: 10, num_canidates: nil, filter: nil, strict: false, model: nil,パイプライン: [] より: 配列<Mongoid::document>

自動埋め込みを使用して、この document の保存された text field に類似する text を持つ documents に対して Atlas Vector Search クエリを実行します。現在のdocumentは結果から除外されます。

例:

同様の説明を持つ記事を検索します。

article.auto_embed_search(limit: 5, filter: { status: 'published' })

パラメーター:

  • index String | Symbol | nil (デフォルトはnil

    使用する自動埋め込みインデックスの名前(modelで 1 つのみが宣言されている場合は任意)

  • path String | Symbol | nil (デフォルトはnil

    インデックス付きテキストフィールドパス(インデックス定義から明確でない場合は任意)。

  • limit 整数 (デフォルトは10です)

    結果の最大数(デフォルト: 10)。

  • num_ candidates (Integer | nil) (デフォルトはnil

    近似最近傍探索検索の候補。デフォルトは * 10 を制限します。strict が true の場合は無視されます。

  • フィルター ハッシュ | nil (デフォルトはnil

    事前フィルタリング用の任意のMongoDBフィルター。

  • 正確な true | false (デフォルトはfalse

    厳密最近傍探索を使用します(デフォルト: false)。

  • モデル string | nil (デフォルトはnil

    クエリ時間埋め込みモデルの上書き。

  • パイプライン 配列 (デフォルトは[]

    追加する追加の集計ステージ。

次の値を返します。

  • 配列未満Mongoid >

    matching document、それぞれに vector_search_score 属性が入力されています。



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# ファイル 'lib/mongoid/search_indexable.rb' は、 123行

デフォルト auto_ embedded_search(index: nil, path: nil, limit: 10, num_ candidates: nil, フィルター: nil, 正確: false, モデル: nil, パイプライン: []) # rust メトリクス/パラメーターリストを無効化
  _index, associated_path = 自己.クラス.送信(:resolve_auto_embed_index, index, path)
  text = public_send(associated_path)

  場合 text.nil?
    発生 ArgumentError,
          " この document では #{解決済み_パス} は nil です。自動埋め込み検索は実行できません "
  end

  private_filter = { '_id' => { '$ne' => _id } }
  completed_filter = フィルター ? { ' $and ' => [ private_filter, フィルター ] } : private_filter

  自己.クラス.auto_ embedded_search(
    text,
    index: index,
    path: path,
    limit: limit,
    num_ candidates: num_ candidates,
    フィルター: completed_filter,
    正確: 正確な,
    モデル: モデル,
    パイプライン: パイプライン
  )
end

# vector_search(インデックス: nil、パス: nil、limit: 10、num_canidates: nil、フィルター: nil、パイプライン: [])⇒ Array[Mongoid::Document]

このdocumentの保存された埋め込みをクエリベクトルとして使用して、このdocumentと同様のdocumentのベクトル検索を実行します。document自体は結果から除外されます。

例:

この記事に類似する記事を検索します。

article.vector_search(limit: 5, filter: { status: 'published' })

パラメーター:

  • index String | Symbol | nil (デフォルトはnil

    使用するベクトル検索インデックスの名前(modelで 1 つのみが宣言されている場合は任意)

  • path String | Symbol | nil (デフォルトはnil

    保存されたベクトルを含むフィールド(インデックス定義から明確でない場合は任意)。

  • limit 整数 (デフォルトは10です)

    結果の最大数(デフォルト: 10)。

  • num_ candidates (Integer | nil) (デフォルトはnil

    近似最近傍探索検索中に考慮する候補の数。のデフォルトは * 10 を制限します。

  • フィルター ハッシュ | nil (デフォルトはnil

    スコアリング前に候補を事前にフィルタリングする任意のMongoDBフィルター。

  • パイプライン 配列 (デフォルトは[]

    ベクトル検索と スコアプロジェクションの後に追加する追加の集計ステージ 。

次の値を返します。

  • 配列未満Mongoid >

    matching document、それぞれに vector_search_score 属性が入力されています。



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# ファイル 'lib/mongoid/search_indexable.rb' は、 79行

デフォルト vector_search(index: nil, path: nil, limit: 10, num_ candidates: nil, フィルター: nil, パイプライン: [])
  _index, associated_path = 自己.クラス.送信(:resolve_vector_index, index, path)
  query_vector = public_send(associated_path)

  場合 query_vector.nil?
    発生 ArgumentError,
          " この document では #{解決済み_パス} は nil です。ベクトル検索は実行できません "
  end

  private_filter = { '_id' => { '$ne' => _id } }
  completed_filter = フィルター ? { ' $and ' => [ private_filter, フィルター ] } : private_filter

  自己.クラス.vector_search(
    query_vector,
    index: index,
    path: path,
    limit: limit,
    num_ candidates: num_ candidates,
    フィルター: completed_filter,
    パイプライン: パイプライン
  )
end