Class: Weaviate::Client
- Inherits:
-
Object
- Object
- Weaviate::Client
- Defined in:
- lib/weaviate/client.rb
Constant Summary collapse
- API_VERSION =
"v1"
- API_KEY_HEADERS =
{ ollama: "X-Ollama-Not-Used", 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.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#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, logger: nil) ⇒ 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, logger: nil) ⇒ Client
Returns a new instance of Client.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/weaviate/client.rb', line 21 def initialize( url:, api_key: nil, model_service: nil, model_service_api_key: nil, adapter: Faraday.default_adapter, logger: nil ) 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 @logger = logger || Logger.new($stdout) 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 |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
8 9 10 |
# File 'lib/weaviate/client.rb', line 8 def logger @logger 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
67 68 69 |
# File 'lib/weaviate/client.rb', line 67 def backups @backups ||= Weaviate::Backups.new(client: self) end |
#classifications ⇒ Object
71 72 73 |
# File 'lib/weaviate/client.rb', line 71 def classifications @classifications ||= Weaviate::Classifications.new(client: self) end |
#connection ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/weaviate/client.rb', line 104 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 :logger, logger, {headers: true, bodies: true, errors: true} faraday.response :json, content_type: /\bjson$/ faraday.response :raise_error 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
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/weaviate/client.rb', line 83 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
57 58 59 60 |
# File 'lib/weaviate/client.rb', line 57 def live? @health ||= Weaviate::Health.new(client: self) @health.live? end |
#meta ⇒ Object
47 48 49 50 |
# File 'lib/weaviate/client.rb', line 47 def @meta ||= Weaviate::Meta.new(client: self) @meta.get end |
#nodes ⇒ Object
52 53 54 55 |
# File 'lib/weaviate/client.rb', line 52 def nodes @nodes ||= Weaviate::Nodes.new(client: self) @nodes.list end |
#objects ⇒ Object
75 76 77 |
# File 'lib/weaviate/client.rb', line 75 def objects @objects ||= Weaviate::Objects.new(client: self) end |
#oidc ⇒ Object
39 40 41 |
# File 'lib/weaviate/client.rb', line 39 def oidc Weaviate::OIDC.new(client: self).get end |
#query ⇒ Object
79 80 81 |
# File 'lib/weaviate/client.rb', line 79 def query @query ||= Weaviate::Query.new(client: self) end |