模块:Mongoid::SearchIndexable
Overview
封装有关管理搜索索引的行为。 仅当连接到Atlas 集群时才支持此功能。
在命名空间下定义
实例方法摘要折叠
-
#auto_embed_search(索引: nil, path: nil, limit: 10, num_candidates: nil, 过滤器: nil, exact: false, model: nil, 管道: []) ⇒ Array<Mongoid::Document>
使用自动嵌入,对文本与此document的存储文本字段相似的document执行Atlas Vector Search查询。
-
#vector_search(索引: nil, path: nil, limit: 10, num_candidates: nil, 过滤器: nil, 管道: []) ⇒ Array<Mongoid::Document>
使用此document的存储嵌入作为查询向量,对与此类似的document执行向量搜索。
实例方法详细信息
#auto_embed_search(索引: nil, path: nil, limit: 10, num_candidates: nil, 过滤器: nil, exact: false, model: nil, 管道: []) ⇒ Array<Document>
使用自动嵌入,对文本与此document的存储文本字段相似的document执行Atlas Vector Search查询。当前 document 将从结果中排除。
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/mongoid/search_indexable.rb', line 123 def (index: nil, path: nil, limit: 10, num_candidates: nil, 过滤器: nil, 精确: false, 模型: nil, 管道: []) # rubocop:disable Metrics/ParameterLists _index, solved_path = self.class.发送(:resolve_auto_embed_index, 索引(index), 路径) text = public_send(solved_path) if text.nil? 提高 ArgumentError, “#{resolved_path} document 为零;无法执行自动嵌入搜索” end self_filter = { '_id' => { '$ne' => _id } } 组合过滤器 = 筛选器 ? { ' $and ' => [ self_filter, 筛选器 ] } : self_filter self.class.( text, index: 索引(index), path: 路径, limit: limit, num_candidates: num_candidates, 过滤器: 组合过滤器, 精确: 精确, 模型: 模型, 管道: 管道 ) end |
#vector_search(索引: nil, path: nil, limit: 10, num_candidates: nil, 过滤器: nil, 管道: []) ⇒ Array<Mongoid::Document>
使用此document的存储嵌入作为查询向量,对与此类似的document执行向量搜索。document本身会从结果中排除。
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/mongoid/search_indexable.rb', line 79 def vector_search(index: nil, path: nil, limit: 10, num_candidates: nil, 过滤器: nil, 管道: []) _index, solved_path = self.class.发送(:resolve_vector_index, 索引(index), 路径) query_vector = public_send(solved_path) if query_vector.nil? 提高 ArgumentError, “#{resolved_path} 在该 document 中为零;无法执行向量搜索}” end self_filter = { '_id' => { '$ne' => _id } } 组合过滤器 = 筛选器 ? { ' $and ' => [ self_filter, 筛选器 ] } : self_filter self.class.vector_search( query_vector, index: 索引(index), path: 路径, limit: limit, num_candidates: num_candidates, 过滤器: 组合过滤器, 管道: 管道 ) end |