speaky 0.1.5 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/speaky/concern.rb +1 -0
- data/lib/speaky/vectorstore_qdrant.rb +15 -2
- data/lib/speaky/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 978cd92d282523846c4b7b592776656f3d351162a361e28460de95e4af338378
|
4
|
+
data.tar.gz: dac048c47d89c41ef1b96dc31d3a7f600ee2ef393d59bffd203af1b7f97c17cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06e1d13344593cce42a57f730d44e4f838660a7581810a5357e023b42a6f7a00c866e3fadcbb98d6a4398f202a0c693c02202c69415f7eac16ca7f9190903b93
|
7
|
+
data.tar.gz: 3afc6a7bd45fd9fff233a5e753a6778421d8664405ccc33c1e7189988770056dcd6a45dd04c60052aa2d24b1c7eb61ecb85ee508959c9360e53e1b26ca70f211
|
data/lib/speaky/concern.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'rails'
|
3
4
|
require 'qdrant'
|
4
5
|
|
5
6
|
module Speaky
|
@@ -29,7 +30,7 @@ module Speaky
|
|
29
30
|
collection_name: @config[:collection_name],
|
30
31
|
points: [
|
31
32
|
{
|
32
|
-
id: id,
|
33
|
+
id: string_id_to_unique_int_id(id),
|
33
34
|
vector: embeddings,
|
34
35
|
payload: {
|
35
36
|
content: data
|
@@ -40,6 +41,7 @@ module Speaky
|
|
40
41
|
)
|
41
42
|
|
42
43
|
if !points_upsert || points_upsert.dig('status') != 'ok'
|
44
|
+
Rails.logger.error(points_upsert)
|
43
45
|
raise 'Failed to add vector'
|
44
46
|
end
|
45
47
|
|
@@ -49,10 +51,11 @@ module Speaky
|
|
49
51
|
def remove(id)
|
50
52
|
points_delete = @client.points.delete(
|
51
53
|
collection_name: @config[:collection_name],
|
52
|
-
points: [id],
|
54
|
+
points: [string_id_to_unique_int_id(id)],
|
53
55
|
)
|
54
56
|
|
55
57
|
if !points_delete || points_delete.dig('status') != 'ok'
|
58
|
+
Rails.logger.error(points_delete)
|
56
59
|
raise 'Failed to remove vector'
|
57
60
|
end
|
58
61
|
|
@@ -71,6 +74,7 @@ module Speaky
|
|
71
74
|
)
|
72
75
|
|
73
76
|
if !points_search || points_search.dig('status') != 'ok'
|
77
|
+
Rails.logger.error(points_search)
|
74
78
|
raise 'Failed to search vectors'
|
75
79
|
end
|
76
80
|
|
@@ -80,6 +84,7 @@ module Speaky
|
|
80
84
|
def reset
|
81
85
|
collections_delete = @client.collections.delete(collection_name: @config[:collection_name])
|
82
86
|
if !collections_delete || collections_delete.dig('status') != 'ok'
|
87
|
+
Rails.logger.error(collections_delete)
|
83
88
|
raise 'Failed to delete collection'
|
84
89
|
end
|
85
90
|
|
@@ -99,6 +104,7 @@ module Speaky
|
|
99
104
|
}
|
100
105
|
)
|
101
106
|
if !collections_create || collections_create.dig('status') != 'ok'
|
107
|
+
Rails.logger.error(collections_create)
|
102
108
|
raise 'Failed to create collection'
|
103
109
|
end
|
104
110
|
end
|
@@ -106,10 +112,17 @@ module Speaky
|
|
106
112
|
# create index for field "id" in collection
|
107
113
|
collections_create_index = @client.collections.create_index(collection_name: @config[:collection_name], field_name: 'id', field_schema: 'keyword')
|
108
114
|
if !collections_create_index || collections_create_index.dig('status') != 'ok'
|
115
|
+
Rails.logger.error(collections_create_index)
|
109
116
|
raise 'Failed to create index for field "id" on collection'
|
110
117
|
end
|
111
118
|
|
112
119
|
true
|
113
120
|
end
|
121
|
+
|
122
|
+
# This method is used to convert a string ID to a unique integer ID
|
123
|
+
# that can be used by the Qdrant API.
|
124
|
+
def string_id_to_unique_int_id(string_id)
|
125
|
+
string_id.to_s.hash.abs
|
126
|
+
end
|
114
127
|
end
|
115
128
|
end
|
data/lib/speaky/version.rb
CHANGED