Class: Weaviate::Client
- Inherits:
-
Object
- Object
- Weaviate::Client
- Defined in:
- lib/weaviate/client.rb
Constant Summary collapse
- API_VERSION =
"v1"
- API_KEY_HEADERS =
{ openai: "X-OpenAI-Api-Key", azure_openai: "X-Azure-Api-Key", cohere: "X-Cohere-Api-Key", huggingface: "X-HuggingFace-Api-Key", google_palm: "X-Palm-Api-Key" }
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#model_service ⇒ Object
readonly
Returns the value of attribute model_service.
-
#model_service_api_key ⇒ Object
readonly
Returns the value of attribute model_service_api_key.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #backups ⇒ Object
- #classifications ⇒ Object
- #connection ⇒ Object
- #graphql ⇒ Object
-
#initialize(url:, api_key: nil, model_service: nil, model_service_api_key: nil, adapter: Faraday.default_adapter) ⇒ Client
constructor
A new instance of Client.
- #live? ⇒ Boolean
- #meta ⇒ Object
- #nodes ⇒ Object
- #objects ⇒ Object
- #oidc ⇒ Object
- #query ⇒ Object
- #ready? ⇒ Boolean
- #schema ⇒ Object
Constructor Details
#initialize(url:, api_key: nil, model_service: nil, model_service_api_key: nil, adapter: Faraday.default_adapter) ⇒ Client
Returns a new instance of Client.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/weaviate/client.rb', line 20 def initialize( url:, api_key: nil, model_service: nil, model_service_api_key: nil, adapter: Faraday.default_adapter ) validate_model_service!(model_service) unless model_service.nil? @url = url @api_key = api_key @model_service = model_service @model_service_api_key = model_service_api_key @adapter = adapter end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
8 9 10 |
# File 'lib/weaviate/client.rb', line 8 def adapter @adapter end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/weaviate/client.rb', line 8 def api_key @api_key end |
#model_service ⇒ Object (readonly)
Returns the value of attribute model_service.
8 9 10 |
# File 'lib/weaviate/client.rb', line 8 def model_service @model_service end |
#model_service_api_key ⇒ Object (readonly)
Returns the value of attribute model_service_api_key.
8 9 10 |
# File 'lib/weaviate/client.rb', line 8 def model_service_api_key @model_service_api_key end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
8 9 10 |
# File 'lib/weaviate/client.rb', line 8 def url @url end |
Instance Method Details
#backups ⇒ Object
64 65 66 |
# File 'lib/weaviate/client.rb', line 64 def backups @backups ||= Weaviate::Backups.new(client: self) end |
#classifications ⇒ Object
68 69 70 |
# File 'lib/weaviate/client.rb', line 68 def classifications @classifications ||= Weaviate::Classifications.new(client: self) end |
#connection ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/weaviate/client.rb', line 101 def connection @connection ||= Faraday.new(url: "#{url}/#{API_VERSION}/") do |faraday| if api_key faraday.request :authorization, :Bearer, api_key end faraday.request :json faraday.response :json, content_type: /\bjson$/ faraday.adapter adapter faraday.headers[API_KEY_HEADERS[model_service]] = model_service_api_key if model_service && model_service_api_key end end |
#graphql ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/weaviate/client.rb', line 80 def graphql headers = {} if model_service && model_service_api_key headers[API_KEY_HEADERS[model_service]] = model_service_api_key end if api_key headers["Authorization"] = "Bearer #{api_key}" end @graphql ||= Graphlient::Client.new( "#{url}/#{API_VERSION}/graphql", headers: headers, http_options: { read_timeout: 20, write_timeout: 30 } ) end |
#live? ⇒ Boolean
54 55 56 57 |
# File 'lib/weaviate/client.rb', line 54 def live? @health ||= Weaviate::Health.new(client: self) @health.live? end |
#meta ⇒ Object
44 45 46 47 |
# File 'lib/weaviate/client.rb', line 44 def @meta ||= Weaviate::Meta.new(client: self) @meta.get end |
#nodes ⇒ Object
49 50 51 52 |
# File 'lib/weaviate/client.rb', line 49 def nodes @nodes ||= Weaviate::Nodes.new(client: self) @nodes.list end |
#objects ⇒ Object
72 73 74 |
# File 'lib/weaviate/client.rb', line 72 def objects @objects ||= Weaviate::Objects.new(client: self) end |
#oidc ⇒ Object
36 37 38 |
# File 'lib/weaviate/client.rb', line 36 def oidc Weaviate::OIDC.new(client: self).get end |
#query ⇒ Object
76 77 78 |
# File 'lib/weaviate/client.rb', line 76 def query @query ||= Weaviate::Query.new(client: self) end |