speaky 0.1.9 → 0.1.10
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 +4 -4
- data/lib/speaky/llm_openai.rb +2 -2
- data/lib/speaky/vectorstore_faiss.rb +45 -39
- data/lib/speaky/vectorstore_qdrant.rb +2 -1
- data/lib/speaky/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4c6b9331e1d4d69bf0e8e66f22fc9e43620874d22400552a418af290d286969
|
4
|
+
data.tar.gz: 1878fe018b91f0caede735903334a2e86a9a1ecbfd3814ebccfe6857f58ff606
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3dbb0b0cd00be46b2ab61ff749474623c182c067ffdc3e51b6b20c5f1d87587f78d1290577cc61e6276db5574b81cb8116afe5db9f7a2e9aa0e4e078c220ae0e
|
7
|
+
data.tar.gz: 628ae505b3b8b6dbce97d08dcf953c568116d21725a2d4f3c82ee04c49815ac0c8dc10621af9e17f97aed9c34ee26426b41a3c7d2e31e319a5a04c8253c97880
|
data/lib/speaky/llm_openai.rb
CHANGED
@@ -1,51 +1,57 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
module Speaky
|
4
|
+
class VectorstoreFaiss < VectorstoreBase
|
5
|
+
def initialize(config)
|
6
|
+
require 'faiss'
|
4
7
|
|
5
|
-
|
6
|
-
# class VectorstoreFaiss < VectorstoreBase
|
7
|
-
# def initialize(config)
|
8
|
-
# @config = config
|
8
|
+
@config = config
|
9
9
|
|
10
|
-
#
|
11
|
-
|
10
|
+
# check if the index path is set
|
11
|
+
raise ArgumentError, 'index_path is required' unless @config[:index_path]
|
12
12
|
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
23
|
|
24
|
-
|
25
|
-
|
24
|
+
def add(id, data)
|
25
|
+
embeddings = Speaky.llm.embed(data)
|
26
26
|
|
27
|
-
|
27
|
+
@index.add_with_ids([embeddings], [string_id_to_unique_int_id(id)])
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
true
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
#
|
34
|
-
|
35
|
-
|
32
|
+
def remove(id)
|
33
|
+
# remove is not supported by Faiss
|
34
|
+
true
|
35
|
+
end
|
36
36
|
|
37
|
-
|
38
|
-
#
|
37
|
+
def query(question)
|
38
|
+
# TODO
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
[]
|
41
|
+
end
|
42
42
|
|
43
|
-
|
43
|
+
def reset
|
44
|
+
# TODO
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
#
|
51
|
-
#
|
46
|
+
true
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# This method is used to convert a string ID to a unique integer ID
|
52
|
+
# that can be used by the Qdrant API.
|
53
|
+
def string_id_to_unique_int_id(string_id)
|
54
|
+
string_id.to_s.hash.abs
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/speaky/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: speaky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregorio Galante
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Store activerecord models in vector stores and query them with LLMs!
|
14
14
|
email:
|