Class: Weaviate::Client

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

Instance Method Summary collapse

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

#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

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
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



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

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

#classificationsObject



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

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

#connectionObject



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

#graphqlObject



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

Returns:

  • (Boolean)


57
58
59
60
# File 'lib/weaviate/client.rb', line 57

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

#metaObject



47
48
49
50
# File 'lib/weaviate/client.rb', line 47

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

#nodesObject



52
53
54
55
# File 'lib/weaviate/client.rb', line 52

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

#objectsObject



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

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

#oidcObject



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

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

#queryObject



79
80
81
# File 'lib/weaviate/client.rb', line 79

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

#ready?Boolean

Returns:

  • (Boolean)


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

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

#schemaObject



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

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