Module: Documentrix::Documents::Cache::Records::FindRecords
- Defined in:
- lib/documentrix/documents/cache/records.rb
Instance Method Summary collapse
-
#find_records(needle, tags: nil, max_records: nil) {|record| ... } ⇒ Array<Documentrix::Documents::Records>
The find_records method finds records that match the given needle and tags.
Instance Method Details
#find_records(needle, tags: nil, max_records: nil) {|record| ... } ⇒ Array<Documentrix::Documents::Records>
The find_records method finds records that match the given needle and tags.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/documentrix/documents/cache/records.rb', line 70 def find_records(needle, tags: nil, max_records: nil) = Documentrix::Utils::Tags.new(Array()).to_a records = self if .present? records = records.select { |_key, record| ( & record.).size >= 1 } end needle_norm = norm(needle) records = records.sort_by { |key, record| record.key = key record.similarity = cosine_similarity( a: needle, b: record., a_norm: needle_norm, b_norm: record.norm, ) } records.transpose.last&.reverse.to_a end |