marqo 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +1 -0
- data/.rubocop.yml +37 -0
- data/LICENSE.txt +21 -0
- data/README.md +139 -0
- data/Rakefile +19 -0
- data/lib/marqo/client.rb +50 -0
- data/lib/marqo/configuration.rb +7 -0
- data/lib/marqo/device.rb +24 -0
- data/lib/marqo/document.rb +70 -0
- data/lib/marqo/helpers/request_helpers.rb +18 -0
- data/lib/marqo/helpers/url_helpers.rb +53 -0
- data/lib/marqo/index.rb +90 -0
- data/lib/marqo/models.rb +29 -0
- data/lib/marqo/search.rb +33 -0
- data/lib/marqo/version.rb +5 -0
- data/lib/marqo.rb +28 -0
- data/sig/marqo.rbs +4 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7187c5ff2968c91c36e00be7d7bcfcadae14f6fa45f2e5a8b11c3802003ff4b0
|
4
|
+
data.tar.gz: 6622383016bf6956d39080887692e674c57b4995fdae5d05456fdbff54c44bba
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 87be75a1c421140ac7f0b27b7ac8c0af1f39228b9736aa0aad35738a174d34d7e1cfcd595b7359805a877c60b27fa248259ec1dbbb597bff319cb591701034db
|
7
|
+
data.tar.gz: d2e0b5dfaa79a883ecad1c37bcaa34978b5e0aed31c96b9c34c585b7b83b04d00f19b047383dcc3b9a17a78d027b60a458b947d144983b78dc05f0eded2c620d
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
TargetRubyVersion: 2.7
|
4
|
+
Exclude:
|
5
|
+
- 'Gemfile'
|
6
|
+
- 'bin/*'
|
7
|
+
- '*.gemspec'
|
8
|
+
|
9
|
+
Style/RaiseArgs:
|
10
|
+
EnforcedStyle: compact
|
11
|
+
|
12
|
+
# Tune to MethodLength
|
13
|
+
Metrics/AbcSize:
|
14
|
+
Max: 300
|
15
|
+
|
16
|
+
# Tune to MethodLength
|
17
|
+
Metrics/ClassLength:
|
18
|
+
Max: 200
|
19
|
+
|
20
|
+
# Checks if uses of quotes match the configured preference.
|
21
|
+
Style/StringLiterals:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
# Disable
|
25
|
+
Style/FrozenStringLiteralComment:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Style/ParenthesesAroundCondition:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Metrics/BlockLength:
|
32
|
+
AllowedMethods: ['describe', 'context', 'before', 'shared_context', 'let']
|
33
|
+
Exclude:
|
34
|
+
- "**/*_spec.rb"
|
35
|
+
|
36
|
+
Style/Documentation:
|
37
|
+
Enabled: false
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 linh
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
# Marqo
|
2
|
+
|
3
|
+
Ruby Driver for Marqo.
|
4
|
+
Supported Marqo version [1.2.0](https://docs.marqo.ai/1.2.0/) - https://docs.marqo.ai/1.2.0/
|
5
|
+
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
```
|
10
|
+
client = Marqo::Client.new(endpoint, index_name)
|
11
|
+
```
|
12
|
+
|
13
|
+
### create index
|
14
|
+
```
|
15
|
+
options = {
|
16
|
+
number_of_shards: 3,
|
17
|
+
number_of_replicas: 0
|
18
|
+
}
|
19
|
+
client.create_index(index_name, options)
|
20
|
+
```
|
21
|
+
|
22
|
+
valid options - [ref](https://docs.marqo.ai/1.2.0/API-Reference/indexes/)
|
23
|
+
|
24
|
+
```
|
25
|
+
{
|
26
|
+
"index_defaults": {
|
27
|
+
"treat_urls_and_pointers_as_images": false,
|
28
|
+
"model": "hf/all_datasets_v4_MiniLM-L6",
|
29
|
+
"normalize_embeddings": true,
|
30
|
+
"text_preprocessing": {
|
31
|
+
"split_length": 2,
|
32
|
+
"split_overlap": 0,
|
33
|
+
"split_method": "sentence"
|
34
|
+
},
|
35
|
+
"image_preprocessing": {
|
36
|
+
"patch_method": null
|
37
|
+
},
|
38
|
+
"ann_parameters" : {
|
39
|
+
"space_type": "cosinesimil",
|
40
|
+
"parameters": {
|
41
|
+
"ef_construction": 128,
|
42
|
+
"m": 16
|
43
|
+
}
|
44
|
+
}
|
45
|
+
},
|
46
|
+
"number_of_shards": 3,
|
47
|
+
"number_of_replicas": 0
|
48
|
+
}
|
49
|
+
```
|
50
|
+
### list_index
|
51
|
+
```
|
52
|
+
client.list
|
53
|
+
```
|
54
|
+
|
55
|
+
### delete_index
|
56
|
+
```
|
57
|
+
client.delete_index
|
58
|
+
```
|
59
|
+
|
60
|
+
### add_documents
|
61
|
+
```
|
62
|
+
documents = [
|
63
|
+
{
|
64
|
+
title: 'The Travels of Marco Polo',
|
65
|
+
desc: 'A 13th-century travelogue describing the travels of Polo',
|
66
|
+
genre: 'History'
|
67
|
+
},
|
68
|
+
{
|
69
|
+
title: 'Extravehicular Mobility Unit (EMU)',
|
70
|
+
desc: 'The EMU is a spacesuit that provides environmental protection',
|
71
|
+
genre: 'Science',
|
72
|
+
_id: 'hatkeo_08'
|
73
|
+
}
|
74
|
+
]
|
75
|
+
|
76
|
+
options = { tensor_fields: %w[title desc] }
|
77
|
+
client.add_documents(documents, options)
|
78
|
+
```
|
79
|
+
|
80
|
+
### find_doc
|
81
|
+
```
|
82
|
+
client.find_doc('hatkeo_08', { expose_facets: false })
|
83
|
+
```
|
84
|
+
|
85
|
+
### find_docs (does not support options yet - TODO)
|
86
|
+
|
87
|
+
```
|
88
|
+
client.find_doc(['hatkeo_08', 'another_ids'])
|
89
|
+
```
|
90
|
+
|
91
|
+
### delete_docs
|
92
|
+
|
93
|
+
```
|
94
|
+
client.delete_docs(['hatkeo_08', 'another_ids'])
|
95
|
+
```
|
96
|
+
|
97
|
+
### search
|
98
|
+
```
|
99
|
+
query = 'what is the best outfit to wear on the moon?'
|
100
|
+
default_options = {
|
101
|
+
limit: 20,
|
102
|
+
offset: 0,
|
103
|
+
showHighlights: true,
|
104
|
+
searchMethod: Marqo::Search::SEARCH_METHOD_TENSOR,
|
105
|
+
attributesToRetrieve: ['*'],
|
106
|
+
image_download_headers: {}
|
107
|
+
}
|
108
|
+
client.search(query, default_options)
|
109
|
+
```
|
110
|
+
|
111
|
+
- search_options - [ref](https://docs.marqo.ai/1.2.0/API-Reference/search/)
|
112
|
+
|
113
|
+
# possible options
|
114
|
+
* filter - https://docs.marqo.ai/1.2.0/API-Reference/search/#filter
|
115
|
+
* searchableAttributes - https://docs.marqo.ai/1.2.0/API-Reference/search/#searchable-attributes
|
116
|
+
* reRanker - https://docs.marqo.ai/1.2.0/API-Reference/search/#reranker
|
117
|
+
* boost - https://docs.marqo.ai/1.2.0/API-Reference/search/#boost
|
118
|
+
* context - https://docs.marqo.ai/1.2.0/API-Reference/search/#context
|
119
|
+
* score_modifiers - https://docs.marqo.ai/1.2.0/API-Reference/search/#score-modifiers
|
120
|
+
* modelAuth - https://docs.marqo.ai/1.2.0/API-Reference/search/#model-auth
|
121
|
+
|
122
|
+
|
123
|
+
## Contributing
|
124
|
+
|
125
|
+
- TODO: add support for
|
126
|
+
+ mapping. There document seems not clear - [ref](https://docs.marqo.ai/1.2.0/API-Reference/mappings/)
|
127
|
+
+ bulk - [ref](https://docs.marqo.ai/1.2.0/API-Reference/bulk/)
|
128
|
+
|
129
|
+
make sure follow rubocop and add test for it
|
130
|
+
```
|
131
|
+
rake check
|
132
|
+
rake test
|
133
|
+
```
|
134
|
+
|
135
|
+
- Bug reports and pull requests are welcome on GitHub at https://github.com/haanhduclinh/marqo.
|
136
|
+
|
137
|
+
## License
|
138
|
+
|
139
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
|
5
|
+
task :default do
|
6
|
+
system 'rake --tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
task :test do
|
10
|
+
system 'rspec .'
|
11
|
+
end
|
12
|
+
|
13
|
+
task :check do
|
14
|
+
system 'rubocop .'
|
15
|
+
end
|
16
|
+
|
17
|
+
task :check_end_test do
|
18
|
+
system 'rubocop . && rspec .'
|
19
|
+
end
|
data/lib/marqo/client.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module Marqo
|
2
|
+
class Client
|
3
|
+
attr_accessor :endpoint, :index_name
|
4
|
+
|
5
|
+
def initialize(ept = nil, name = nil)
|
6
|
+
self.endpoint = ept || Marqo.configuration.endpoint
|
7
|
+
self.index_name = name || Marqo.configuration.index_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_index(index_name, options = {})
|
11
|
+
Marqo::Index.create(endpoint, index_name, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def list_index
|
15
|
+
Marqo::Index.list(endpoint)
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete_index
|
19
|
+
Marqo::Index.delete(endpoint, index_name)
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_documents(documents, options = {})
|
23
|
+
Marqo::Document.create(endpoint, index_name, documents, options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def find_doc(document_id, options = {})
|
27
|
+
Marqo::Document.find(endpoint, index_name, document_id, options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def find_docs(document_ids)
|
31
|
+
Marqo::Document.finds(endpoint, index_name, document_ids)
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete_docs(document_ids)
|
35
|
+
Marqo::Document.delete(endpoint, index_name, document_ids)
|
36
|
+
end
|
37
|
+
|
38
|
+
def search(query, options = {})
|
39
|
+
Marqo::Search.run(endpoint, index_name, query, options)
|
40
|
+
end
|
41
|
+
|
42
|
+
def device_cpu
|
43
|
+
Marqo::Device.cpu(endpoint)
|
44
|
+
end
|
45
|
+
|
46
|
+
def device_cuda
|
47
|
+
Marqo::Device.cuda(endpoint)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/marqo/device.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Marqo
|
2
|
+
class Device
|
3
|
+
class << self
|
4
|
+
# https://docs.marqo.ai/1.2.0/API-Reference/models/
|
5
|
+
def cpu(endpoint)
|
6
|
+
url = Marqo::UrlHelpers.device_cpu_endpoint(endpoint)
|
7
|
+
http = Net::HTTP.new(url.host, url.port)
|
8
|
+
http.use_ssl = url.scheme == "https"
|
9
|
+
request = Net::HTTP::Get.new(url)
|
10
|
+
|
11
|
+
http.request(request)
|
12
|
+
end
|
13
|
+
|
14
|
+
def cuda(endpoint)
|
15
|
+
url = Marqo::UrlHelpers.device_cuda_endpoint(endpoint)
|
16
|
+
http = Net::HTTP.new(url.host, url.port)
|
17
|
+
http.use_ssl = url.scheme == "https"
|
18
|
+
request = Net::HTTP::Get.new(url)
|
19
|
+
|
20
|
+
http.request(request)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Marqo
|
4
|
+
class Document
|
5
|
+
class << self
|
6
|
+
# https://docs.marqo.ai/1.2.0/API-Reference/documents/#add-or-replace-documents
|
7
|
+
def create(endpoint, index_name, documents, options = {})
|
8
|
+
url = Marqo::UrlHelpers.base_document_endpoint(endpoint, index_name)
|
9
|
+
|
10
|
+
http = Net::HTTP.new(url.host, url.port)
|
11
|
+
http.use_ssl = url.scheme == "https"
|
12
|
+
request = Net::HTTP::Post.new(url)
|
13
|
+
request['Content-type'] = 'application/json'
|
14
|
+
|
15
|
+
request_body = { documents: documents }
|
16
|
+
|
17
|
+
request_body[:tensorFields] = options[:tensor_fields] if options[:tensor_fields].count.positive?
|
18
|
+
|
19
|
+
request.body = JSON.dump(request_body)
|
20
|
+
|
21
|
+
http.request(request)
|
22
|
+
end
|
23
|
+
|
24
|
+
# https://docs.marqo.ai/1.2.0/API-Reference/documents/#get-one-document
|
25
|
+
def find(endpoint, index_name, document_id, options = {})
|
26
|
+
url = Marqo::UrlHelpers.find_document_endpoint(endpoint, index_name, document_id)
|
27
|
+
|
28
|
+
http = Net::HTTP.new(url.host, url.port)
|
29
|
+
http.use_ssl = url.scheme == "https"
|
30
|
+
request = Net::HTTP::Get.new(url)
|
31
|
+
|
32
|
+
if options[:expose_facets]
|
33
|
+
params = { 'expose_facets' => options[:expose_facets] }
|
34
|
+
request.set_form_data(params)
|
35
|
+
request = Net::HTTP::Get.new("#{url.path}?#{request.body}")
|
36
|
+
end
|
37
|
+
|
38
|
+
http.request(request)
|
39
|
+
end
|
40
|
+
|
41
|
+
# https://docs.marqo.ai/1.2.0/API-Reference/documents/#get-multiple-documents
|
42
|
+
def finds(endpoint, index_name, document_ids)
|
43
|
+
url = Marqo::UrlHelpers.base_document_endpoint(endpoint, index_name)
|
44
|
+
|
45
|
+
http = Net::HTTP.new(url.host, url.port)
|
46
|
+
http.use_ssl = url.scheme == "https"
|
47
|
+
request = Net::HTTP::Get.new(url)
|
48
|
+
request['Content-Type'] = 'application/json'
|
49
|
+
|
50
|
+
request.body = JSON.dump(document_ids)
|
51
|
+
|
52
|
+
http.request(request)
|
53
|
+
end
|
54
|
+
|
55
|
+
# https://docs.marqo.ai/1.2.0/API-Reference/documents/#delete-documents
|
56
|
+
def delete(endpoint, index_name, document_ids)
|
57
|
+
url = Marqo::UrlHelpers.delete_document_endpoint(endpoint, index_name)
|
58
|
+
|
59
|
+
http = Net::HTTP.new(url.host, url.port)
|
60
|
+
http.use_ssl = url.scheme == "https"
|
61
|
+
request = Net::HTTP::Post.new(url)
|
62
|
+
request['Content-type'] = 'application/json'
|
63
|
+
|
64
|
+
request.body = JSON.dump(document_ids)
|
65
|
+
|
66
|
+
http.request(request)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Marqo
|
2
|
+
module RequestHelpers
|
3
|
+
module_function
|
4
|
+
|
5
|
+
def generate_search_payload(query, options)
|
6
|
+
defaul_options = {
|
7
|
+
limit: 20,
|
8
|
+
offset: 0,
|
9
|
+
showHighlights: true,
|
10
|
+
searchMethod: Marqo::Search::SEARCH_METHOD_TENSOR,
|
11
|
+
attributesToRetrieve: ['*'],
|
12
|
+
image_download_headers: {}
|
13
|
+
}.merge(options)
|
14
|
+
|
15
|
+
defaul_options.merge(q: query)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Marqo
|
2
|
+
module UrlHelpers
|
3
|
+
module_function
|
4
|
+
|
5
|
+
def index_endpoint(endpoint)
|
6
|
+
URI.join(endpoint, 'indexes')
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_index_endpoint(endpoint, index_name)
|
10
|
+
URI.join(endpoint, 'indexes/', index_name)
|
11
|
+
end
|
12
|
+
|
13
|
+
def delete_index_endpoint(endpoint, index_name)
|
14
|
+
URI.join(endpoint, 'indexes/', index_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
def refresh_endpoint(endpoint, index_name)
|
18
|
+
URI.join(endpoint, 'indexes/', "#{index_name}/", "refresh")
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete_document_endpoint(endpoint, index_name)
|
22
|
+
URI.join(endpoint, 'indexes/', "#{index_name}/", 'documents/', 'delete-batch')
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_document_endpoint(endpoint, index_name, document_id)
|
26
|
+
URI.join(endpoint, 'indexes/', "#{index_name}/", 'documents/', document_id)
|
27
|
+
end
|
28
|
+
|
29
|
+
def base_document_endpoint(endpoint, index_name)
|
30
|
+
URI.join(endpoint, 'indexes/', "#{index_name}/", 'documents')
|
31
|
+
end
|
32
|
+
|
33
|
+
def search_endpoint(endpoint, index_name)
|
34
|
+
URI.join(endpoint, 'indexes/', "#{index_name}/", 'search')
|
35
|
+
end
|
36
|
+
|
37
|
+
def health_endpoint(endpoint, index_name)
|
38
|
+
URI.join(endpoint, 'indexes/', "#{index_name}/", "health")
|
39
|
+
end
|
40
|
+
|
41
|
+
def models_endpoint(endpoint)
|
42
|
+
URI.join(endpoint, 'models')
|
43
|
+
end
|
44
|
+
|
45
|
+
def device_cpu_endpoint(endpoint)
|
46
|
+
URI.join(endpoint, 'device/', 'cpu')
|
47
|
+
end
|
48
|
+
|
49
|
+
def device_cuda_endpoint(endpoint)
|
50
|
+
URI.join(endpoint, 'device/', 'cuda')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/marqo/index.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Marqo
|
4
|
+
class Index
|
5
|
+
class << self
|
6
|
+
# https://docs.marqo.ai/1.2.0/API-Reference/indexes/#list-indexes
|
7
|
+
def list(endpoint)
|
8
|
+
url = Marqo::UrlHelpers.index_endpoint(endpoint)
|
9
|
+
http = Net::HTTP.new(url.host, url.port)
|
10
|
+
http.use_ssl = url.scheme == "https"
|
11
|
+
request = Net::HTTP::Get.new(url)
|
12
|
+
|
13
|
+
http.request(request)
|
14
|
+
end
|
15
|
+
|
16
|
+
# https://docs.marqo.ai/1.2.0/API-Reference/indexes/#create-index
|
17
|
+
def create(endpoint, index_name, options = {})
|
18
|
+
# valid options - default value
|
19
|
+
# - index_defaults: ""
|
20
|
+
# - number_of_shards: 3
|
21
|
+
# - number_of_replicas: 0
|
22
|
+
# more detail see in url https://docs.marqo.ai/1.2.0/API-Reference/indexes/
|
23
|
+
# example
|
24
|
+
# {
|
25
|
+
# "index_defaults": {
|
26
|
+
# "treat_urls_and_pointers_as_images": false,
|
27
|
+
# "model": "hf/all_datasets_v4_MiniLM-L6",
|
28
|
+
# "normalize_embeddings": true,
|
29
|
+
# "text_preprocessing": {
|
30
|
+
# "split_length": 2,
|
31
|
+
# "split_overlap": 0,
|
32
|
+
# "split_method": "sentence"
|
33
|
+
# },
|
34
|
+
# "image_preprocessing": {
|
35
|
+
# "patch_method": null
|
36
|
+
# },
|
37
|
+
# "ann_parameters" : {
|
38
|
+
# "space_type": "cosinesimil",
|
39
|
+
# "parameters": {
|
40
|
+
# "ef_construction": 128,
|
41
|
+
# "m": 16
|
42
|
+
# }
|
43
|
+
# }
|
44
|
+
# },
|
45
|
+
# "number_of_shards": 3,
|
46
|
+
# "number_of_replicas": 0
|
47
|
+
# }
|
48
|
+
|
49
|
+
url = Marqo::UrlHelpers.create_index_endpoint(endpoint, index_name)
|
50
|
+
http = Net::HTTP.new(url.host, url.port)
|
51
|
+
http.use_ssl = url.scheme == "https"
|
52
|
+
request = Net::HTTP::Post.new(url)
|
53
|
+
request['Content-type'] = 'application/json'
|
54
|
+
request.body = JSON.dump(options) unless options.empty?
|
55
|
+
|
56
|
+
http.request(request)
|
57
|
+
end
|
58
|
+
|
59
|
+
# https://docs.marqo.ai/1.2.0/API-Reference/indexes/#delete-index
|
60
|
+
def delete(endpoint, index_name)
|
61
|
+
url = Marqo::UrlHelpers.delete_index_endpoint(endpoint, index_name)
|
62
|
+
http = Net::HTTP.new(url.host, url.port)
|
63
|
+
http.use_ssl = url.scheme == "https"
|
64
|
+
request = Net::HTTP::Delete.new(url)
|
65
|
+
|
66
|
+
http.request(request)
|
67
|
+
end
|
68
|
+
|
69
|
+
# https://docs.marqo.ai/1.2.0/API-Reference/refresh/
|
70
|
+
def refresh(endpoint, index_name)
|
71
|
+
url = Marqo::UrlHelpers.refresh_endpoint(endpoint, index_name)
|
72
|
+
http = Net::HTTP.new(url.host, url.port)
|
73
|
+
http.use_ssl = url.scheme == "https"
|
74
|
+
request = Net::HTTP::Post.new(url)
|
75
|
+
|
76
|
+
http.request(request)
|
77
|
+
end
|
78
|
+
|
79
|
+
# https://docs.marqo.ai/1.2.0/API-Reference/health/
|
80
|
+
def health(endpoint, index_name)
|
81
|
+
url = Marqo::UrlHelpers.health_endpoint(endpoint, index_name)
|
82
|
+
http = Net::HTTP.new(url.host, url.port)
|
83
|
+
http.use_ssl = url.scheme == "https"
|
84
|
+
request = Net::HTTP::Get.new(url)
|
85
|
+
|
86
|
+
http.request(request)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/marqo/models.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Marqo
|
2
|
+
class Models
|
3
|
+
class << self
|
4
|
+
# https://docs.marqo.ai/1.2.0/API-Reference/models/
|
5
|
+
def info(endpoint)
|
6
|
+
url = Marqo::UrlHelpers.models_endpoint(endpoint)
|
7
|
+
http = Net::HTTP.new(url.host, url.port)
|
8
|
+
http.use_ssl = url.scheme == "https"
|
9
|
+
request = Net::HTTP::Get.new(url)
|
10
|
+
|
11
|
+
http.request(request)
|
12
|
+
end
|
13
|
+
|
14
|
+
def delete(endpoint, params = {})
|
15
|
+
url = Marqo::UrlHelpers.models_endpoint(endpoint)
|
16
|
+
http = Net::HTTP.new(url.host, url.port)
|
17
|
+
http.use_ssl = url.scheme == "https"
|
18
|
+
request = Net::HTTP::Delete.new(url)
|
19
|
+
|
20
|
+
unless params.empty?
|
21
|
+
request.set_form_data(params)
|
22
|
+
request = Net::HTTP::Delete.new("#{url.path}?#{request.body}")
|
23
|
+
end
|
24
|
+
|
25
|
+
http.request(request)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/marqo/search.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Marqo
|
4
|
+
class Search
|
5
|
+
SEARCH_METHOD_TENSOR = 'TENSOR'
|
6
|
+
SEARCH_METHOD_LEXICAL = 'LEXICAL'
|
7
|
+
|
8
|
+
# https://docs.marqo.ai/1.2.0/API-Reference/search/
|
9
|
+
def self.run(endpoint, index_name, query, options = {})
|
10
|
+
# # possible options
|
11
|
+
# filter - https://docs.marqo.ai/1.2.0/API-Reference/search/#filter
|
12
|
+
# searchableAttributes - https://docs.marqo.ai/1.2.0/API-Reference/search/#searchable-attributes
|
13
|
+
# reRanker - https://docs.marqo.ai/1.2.0/API-Reference/search/#reranker
|
14
|
+
# boost - https://docs.marqo.ai/1.2.0/API-Reference/search/#boost
|
15
|
+
# context - https://docs.marqo.ai/1.2.0/API-Reference/search/#context
|
16
|
+
# score_modifiers - https://docs.marqo.ai/1.2.0/API-Reference/search/#score-modifiers
|
17
|
+
# modelAuth - https://docs.marqo.ai/1.2.0/API-Reference/search/#model-auth
|
18
|
+
|
19
|
+
url = Marqo::UrlHelpers.search_endpoint(endpoint, index_name)
|
20
|
+
|
21
|
+
http = Net::HTTP.new(url.host, url.port)
|
22
|
+
http.use_ssl = url.scheme == "https"
|
23
|
+
request = Net::HTTP::Post.new(url)
|
24
|
+
request['Content-type'] = 'application/json'
|
25
|
+
|
26
|
+
payload = Marqo::RequestHelpers.generate_search_payload(query, options)
|
27
|
+
|
28
|
+
request.body = JSON.dump(payload)
|
29
|
+
|
30
|
+
http.request(request)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/marqo.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
|
6
|
+
require_relative 'marqo/version'
|
7
|
+
require_relative 'marqo/configuration'
|
8
|
+
require_relative 'marqo/helpers/url_helpers'
|
9
|
+
require_relative 'marqo/helpers/request_helpers'
|
10
|
+
require_relative 'marqo/index'
|
11
|
+
require_relative 'marqo/document'
|
12
|
+
require_relative 'marqo/search'
|
13
|
+
require_relative 'marqo/models'
|
14
|
+
require_relative 'marqo/device'
|
15
|
+
require_relative 'marqo/client'
|
16
|
+
|
17
|
+
module Marqo
|
18
|
+
class Error < StandardError; end
|
19
|
+
# Your code goes here...
|
20
|
+
|
21
|
+
def self.configuration
|
22
|
+
@configuration ||= Configuration.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.configure
|
26
|
+
yield(configuration)
|
27
|
+
end
|
28
|
+
end
|
data/sig/marqo.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: marqo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- linh
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-08-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.14.2
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.14.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 13.0.6
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '13.0'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 13.0.6
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.12'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.12'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rubocop
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.56'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 1.56.1
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.56'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 1.56.1
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: webmock
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '3.19'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - "~>"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '3.19'
|
95
|
+
description: Marqo API adapter
|
96
|
+
email:
|
97
|
+
- no.email@do-not-reply.com
|
98
|
+
executables: []
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- ".rspec"
|
103
|
+
- ".rubocop.yml"
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- lib/marqo.rb
|
108
|
+
- lib/marqo/client.rb
|
109
|
+
- lib/marqo/configuration.rb
|
110
|
+
- lib/marqo/device.rb
|
111
|
+
- lib/marqo/document.rb
|
112
|
+
- lib/marqo/helpers/request_helpers.rb
|
113
|
+
- lib/marqo/helpers/url_helpers.rb
|
114
|
+
- lib/marqo/index.rb
|
115
|
+
- lib/marqo/models.rb
|
116
|
+
- lib/marqo/search.rb
|
117
|
+
- lib/marqo/version.rb
|
118
|
+
- sig/marqo.rbs
|
119
|
+
homepage: https://github.com/haanhduclinh/marqo
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata:
|
123
|
+
allowed_push_host: https://rubygems.org
|
124
|
+
homepage_uri: https://github.com/haanhduclinh/marqo
|
125
|
+
source_code_uri: https://github.com/haanhduclinh/marqo
|
126
|
+
changelog_uri: https://github.com/haanhduclinh/marqo
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: 2.6.0
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubygems_version: 3.4.14
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: This gem in order to comunicate with Marqo
|
146
|
+
test_files: []
|