Class: Weaviate::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#adapterObject (readonly)

Returns the value of attribute adapter.



8
9
10
# File 'lib/weaviate/client.rb', line 8

def adapter
  @adapter
end

#api_keyObject (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_serviceObject (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_keyObject (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

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/weaviate/client.rb', line 8

def url
  @url
end

Instance Method Details

#backupsObject



64
65
66
# File 'lib/weaviate/client.rb', line 64

def backups
  @backups ||= Weaviate::Backups.new(client: self)
end

#classificationsObject



68
69
70
# File 'lib/weaviate/client.rb', line 68

def classifications
  @classifications ||= Weaviate::Classifications.new(client: self)
end

#connectionObject



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

#graphqlObject



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

Returns:

  • (Boolean)


54
55
56
57
# File 'lib/weaviate/client.rb', line 54

def live?
  @health ||= Weaviate::Health.new(client: self)
  @health.live?
end

#metaObject



44
45
46
47
# File 'lib/weaviate/client.rb', line 44

def meta
  @meta ||= Weaviate::Meta.new(client: self)
  @meta.get
end

#nodesObject



49
50
51
52
# File 'lib/weaviate/client.rb', line 49

def nodes
  @nodes ||= Weaviate::Nodes.new(client: self)
  @nodes.list
end

#objectsObject



72
73
74
# File 'lib/weaviate/client.rb', line 72

def objects
  @objects ||= Weaviate::Objects.new(client: self)
end

#oidcObject



36
37
38
# File 'lib/weaviate/client.rb', line 36

def oidc
  Weaviate::OIDC.new(client: self).get
end

#queryObject



76
77
78
# File 'lib/weaviate/client.rb', line 76

def query
  @query ||= Weaviate::Query.new(client: self)
end

#ready?Boolean

Returns:

  • (Boolean)


59
60
61
62
# File 'lib/weaviate/client.rb', line 59

def ready?
  @health ||= Weaviate::Health.new(client: self)
  @health.ready?
end

#schemaObject



40
41
42
# File 'lib/weaviate/client.rb', line 40

def schema
  @schema ||= Weaviate::Schema.new(client: self)
end