Class: SimpleRag::Index
- Inherits:
-
Object
- Object
- SimpleRag::Index
- Defined in:
- lib/simple_rag/index.rb
Instance Method Summary collapse
- #chunk(text) ⇒ Object
- #embed_chunks(chunks) ⇒ Object
-
#initialize(client) ⇒ Index
constructor
A new instance of Index.
- #load(url) ⇒ Object
- #save(text_embeddings) ⇒ Object
Constructor Details
#initialize(client) ⇒ Index
Returns a new instance of Index.
3 4 5 6 |
# File 'lib/simple_rag/index.rb', line 3 def initialize(client) @text = nil @client = client end |
Instance Method Details
#chunk(text) ⇒ Object
16 17 18 19 |
# File 'lib/simple_rag/index.rb', line 16 def chunk(text) chunk_size = 2048 text.chars.each_slice(chunk_size).map(&:join) end |
#embed_chunks(chunks) ⇒ Object
21 22 23 |
# File 'lib/simple_rag/index.rb', line 21 def (chunks) SimpleRag::Embed.(@client, chunks) end |
#load(url) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/simple_rag/index.rb', line 8 def load(url) response = HTTParty.get(url) text = response.body File.write("data/essay.txt", text) @text = text text end |
#save(text_embeddings) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/simple_rag/index.rb', line 25 def save() d = .shape[1] index = Faiss::IndexFlatL2.new(d) index.add() index end |