Class: Vecsearch
- Inherits:
-
Object
- Object
- Vecsearch
- Defined in:
- lib/vecsearch/gte_tiny.rb,
lib/vecsearch.rb,
lib/vecsearch/version.rb
Overview
require ‘narray’
Defined Under Namespace
Classes: GTETiny
Constant Summary collapse
- VERSION =
"0.2.0"
Instance Method Summary collapse
- #<<(str) ⇒ Object
-
#initialize(*records) ⇒ Vecsearch
constructor
A new instance of Vecsearch.
- #nearest(str) ⇒ Object
- #query(str, n) ⇒ Object
Constructor Details
Instance Method Details
#<<(str) ⇒ Object
14 15 16 17 18 |
# File 'lib/vecsearch.rb', line 14 def <<(str) emb = @gte.encode(str) @texts << str @faiss.add(emb) end |
#nearest(str) ⇒ Object
20 |
# File 'lib/vecsearch.rb', line 20 def nearest(str) = query(str, 1)[0] |
#query(str, n) ⇒ Object
22 23 24 25 26 |
# File 'lib/vecsearch.rb', line 22 def query(str, n) emb = @gte.encode(str) _scores, indexes = @faiss.search(emb, 2) [].tap { |res| indexes.each { |idx| res << @texts[idx] } } end |