모듈: Mongoid::SearchIndexable

확장자:
ActiveSupport::Concern
포함 항목:
컴포저블
다음에 정의됨:
lib/mongoid/search_indexable.rb

개요

검색 인덱스 관리와 관련된 동작을 캡슐화합니다. 이 기능 은 Atlas cluster 에 연결된 경우에만 지원됩니다.

네임스페이스 아래에 정의됨

모듈: 클래스 메서드 클래스: 상태

인스턴스 메서드 요약 접기

인스턴스 메서드 세부 정보

#auto_embed_search(인덱스: nil, 경로: nil, limit:, 10 num_candidates: nil, 필터하다: nil, exact: false, 모델: nil, 파이프라인: []) ⇒ Array

자동 임베딩을 사용하여 이 문서의 저장된 텍스트 필드 와 유사한 텍스트가 있는 문서에 대해 Atlas Vector Search 쿼리 수행합니다. 현재 문서 는 결과에서 제외됩니다.

예시:

유사한 설명이 포함된 문서를 찾습니다.

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

매개변수:

  • index (문자열 | 기호 | nil) (기본값: nil)

    사용할 자동 임베딩 인덱스 의 이름입니다(모델에 하나만 선언된 경우 선택 사항).

  • 경로 (문자열 | 기호 | nil) (기본값: nil)

    인덱싱된 텍스트 필드 경로 ( 인덱스 정의에서 모호하지 않은 경우 선택 사항).

  • limit (정수) (기본값: 10)

    최대 결과 수(기본값: 10).

  • num_candidates (정수 | nil) (기본값: nil)

    ANN 검색 후보자 ; 기본값은 limit * 10입니다. 정확하면 무시됩니다: true.

  • 필터 (해시 | nil) (기본값: nil)

    사전 필터링을 위한 MongoDB 필터하다 (선택 사항).

  • 정확한 (true | false) (기본값은 false)

    정확한 가장 가까운 이웃 검색 사용합니다(기본값: false).

  • 모델 (string | nil) (기본값: nil)

    쿼리 시간 임베딩 모델 재정의.

  • 파이프라인 (배열) (기본값: [])

    추가할 추가 집계 단계입니다.

반환합니다:

  • (Array<Mongoid::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

def auto_embed_search(index: nil, 경로: nil, limit: 10, num_candidates: nil, 필터: nil, 정확: 거짓, model: nil, 파이프라인: []) # Rubocop:disable Metrics/ParameterLists
  _index, resolve_path = self.클래스.send(:resolve_auto_embed_index, index, 경로)
  text = public_send(resolve_path)

  만약 text.nil?
    올리다 ArgumentError,
          이 문서 에서 "#{resolve_path} is nil ; can do to be auto-embed 검색"
  end

  self_filter = { '_id' => { '$ne' => _id } }
  결합된_필터 = 필터 ? { '$and' => [ self_filter, 필터 ] } : self_filter

  self.클래스.auto_embed_search(
    text,
    index: index,
    경로: 경로,
    limit: limit,
    num_candidates: num_candidates,
    필터: 결합된_필터,
    정확: 정확한,
    model: 모델,
    파이프라인: 파이프라인
  )
end

#vector_search(인덱스: nil, 경로: nil, 10 제한:, num_candidates: nil, 필터하다: nil, 파이프라인: []) ⇒ Array

이 문서의 저장된 임베딩을 쿼리 벡터로 사용하여 이와 유사한 문서에 대한 벡터 검색 수행합니다. 문서 자체는 결과에서 제외됩니다.

예시:

이와 유사한 문서를 찾습니다.

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

매개변수:

  • index (문자열 | 기호 | nil) (기본값: nil)

    사용할 벡터 검색 인덱스 의 이름입니다(모델에 하나만 선언된 경우 선택 사항).

  • 경로 (문자열 | 기호 | nil) (기본값: nil)

    저장된 벡터가 포함된 필드 ( 인덱스 정의에서 모호하지 않은 경우 선택 사항).

  • limit (정수) (기본값: 10)

    최대 결과 수입니다(기본값: 10).

  • num_candidates (정수 | nil) (기본값: nil)

    ANN 검색 시 고려해야 할 후보의 수입니다. 기본값은 limit * 10입니다.

  • 필터 (해시 | nil) (기본값: nil)

    점수를 매기기 전에 후보를 사전 필터링하는 선택 사항인 MongoDB 필터하다 입니다.

  • 파이프라인 (배열) (기본값: [])

    벡터 검색 및 점수 프로젝션 후에 추가할 추가 집계 단계입니다.

반환합니다:

  • (Array<Mongoid::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

def vector_search(index: nil, 경로: nil, limit: 10, num_candidates: nil, 필터: nil, 파이프라인: [])
  _index, resolve_path = self.클래스.send(:resolve_vector_index, index, 경로)
  query_vector = public_send(resolve_path)

  만약 query_vector.nil?
    올리다 ArgumentError,
          이 문서 에서 "#{resolve_path} 는 nil이며 벡터 검색 수행할 수 없습니다"
  end

  self_filter = { '_id' => { '$ne' => _id } }
  결합된_필터 = 필터 ? { '$and' => [ self_filter, 필터 ] } : self_filter

  self.클래스.vector_search(
    query_vector,
    index: index,
    경로: 경로,
    limit: limit,
    num_candidates: num_candidates,
    필터: 결합된_필터,
    파이프라인: 파이프라인
  )
end