speaky 0.1.7 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 978cd92d282523846c4b7b592776656f3d351162a361e28460de95e4af338378
4
- data.tar.gz: dac048c47d89c41ef1b96dc31d3a7f600ee2ef393d59bffd203af1b7f97c17cd
3
+ metadata.gz: 564d48d19c0f2c99ef2266064911bc1010523dd52d127c7aca4262c8b329700f
4
+ data.tar.gz: 38c4365d3a09e26523c79da531211e276f53aa4a2ebff0a7337af8ff6e47a307
5
5
  SHA512:
6
- metadata.gz: 06e1d13344593cce42a57f730d44e4f838660a7581810a5357e023b42a6f7a00c866e3fadcbb98d6a4398f202a0c693c02202c69415f7eac16ca7f9190903b93
7
- data.tar.gz: 3afc6a7bd45fd9fff233a5e753a6778421d8664405ccc33c1e7189988770056dcd6a45dd04c60052aa2d24b1c7eb61ecb85ee508959c9360e53e1b26ca70f211
6
+ metadata.gz: 565cba4dfa83cd596d3fafbf45db271ffc99225726a7af0ad7a899f859c8157cca0da0308f79957f0d7307ad15e9c34ef31e009e960dc4cadd35b77cd171dbed
7
+ data.tar.gz: 81edbf263c317fe847fe6befbaf6d8bef329114ab8e1f87fefc440b6499d9218ec0090e39e0cad414f61e421f98a97a74c0b499247834a4d9ab3fd8c28bae9b6
@@ -25,7 +25,7 @@ module Speaky
25
25
  end
26
26
 
27
27
  # Query the vectorstore with a question.
28
- # Returns a string.
28
+ # Returns an array of strings.
29
29
  def query(question)
30
30
  raise NotImplementedError
31
31
  end
@@ -1,25 +1,51 @@
1
- # frozen_string_literal: true
2
-
3
- module Speaky
4
- class VectorstoreFaiss < VectorstoreBase
5
- def initialize(config)
6
- raise 'This class is not implemented yet.' # TEMP
7
-
8
- @config = config
9
-
10
- # check if the index path is set
11
- raise ArgumentError, 'index_path is required' unless @config[:index_path]
12
-
13
- # load index from index_path if exists
14
- if File.exist?(@config[:index_path])
15
- @index = Faiss::Index.load(@config[:index_path])
16
- else
17
- # create a new index
18
- @index = Faiss::IndexFlatL2.new(768)
19
- @index.save(@config[:index_path])
20
- end
21
- end
22
-
23
- # TODO: Implement the other methods
24
- end
25
- end
1
+ # # frozen_string_literal: true
2
+
3
+ # require 'faiss'
4
+
5
+ # module Speaky
6
+ # class VectorstoreFaiss < VectorstoreBase
7
+ # def initialize(config)
8
+ # @config = config
9
+
10
+ # # check if the index path is set
11
+ # raise ArgumentError, 'index_path is required' unless @config[:index_path]
12
+
13
+ # # load index from index_path if exists
14
+ # if File.exist?(@config[:index_path])
15
+ # @index = Faiss::Index.load(@config[:index_path])
16
+ # else
17
+ # # create a new index
18
+ # index = Faiss::IndexFlatL2.new(1536)
19
+ # @index = Faiss::IndexIDMap.new(index)
20
+ # @index.save(@config[:index_path])
21
+ # end
22
+ # end
23
+
24
+ # def add(id, data)
25
+ # embeddings = Speaky.llm.embed(data)
26
+
27
+ # @index.add_with_ids([embeddings], [string_id_to_unique_int_id(id)])
28
+
29
+ # true
30
+ # end
31
+
32
+ # def remove(id)
33
+ # # remove is not supported by Faiss
34
+ # true
35
+ # end
36
+
37
+ # def query(question)
38
+ # # TODO: implement query
39
+
40
+ # []
41
+ # end
42
+
43
+ # private
44
+
45
+ # # This method is used to convert a string ID to a unique integer ID
46
+ # # that can be used by the Qdrant API.
47
+ # def string_id_to_unique_int_id(string_id)
48
+ # string_id.to_s.hash.abs
49
+ # end
50
+ # end
51
+ # end
@@ -67,7 +67,7 @@ module Speaky
67
67
 
68
68
  points_search = @client.points.search(
69
69
  collection_name: @config[:collection_name],
70
- limit: 1,
70
+ limit: 5,
71
71
  vector: embeddings,
72
72
  with_payload: true,
73
73
  with_vector: false
@@ -78,7 +78,7 @@ module Speaky
78
78
  raise 'Failed to search vectors'
79
79
  end
80
80
 
81
- points_search.dig('result').first.dig('payload', 'content')
81
+ points_search.dig('result').map { |r| r.dig('payload', 'content') }
82
82
  end
83
83
 
84
84
  def reset
@@ -1,3 +1,3 @@
1
1
  module Speaky
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.9'
3
3
  end
data/lib/speaky.rb CHANGED
@@ -87,7 +87,7 @@ module Speaky
87
87
  template ||= default_template
88
88
 
89
89
  # load context
90
- context = vectorstore.query(question)
90
+ context = vectorstore.query(question).join("\n")
91
91
 
92
92
  # generate prompt
93
93
  prompt = template.gsub("{{context}}", context).gsub("{{question}}", question)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: speaky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregorio Galante