Skip to content

Commit 3a18a83

Browse files
committed
added a multitest to recreate the problem for Weaviate support
1 parent 24ac4f8 commit 3a18a83

File tree

2 files changed

+65
-8
lines changed

2 files changed

+65
-8
lines changed

bin/multitest

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require "bundler/setup"
5+
require "weaviate"
6+
7+
# You can add fixtures and/or initialization code here to make experimenting
8+
# with your gem easier. You can also use a different console, if you like.
9+
10+
# (If you use this, don't forget to add pry to your Gemfile!)
11+
# require "pry"
12+
# Pry.start
13+
14+
client = Weaviate::Client.new(
15+
url: ENV["WEAVIATE_URL"],
16+
api_key: ENV["WEAVIATE_API_KEY"],
17+
model_service: :openai,
18+
model_service_api_key: ENV["MODEL_SERVICE_API_KEY"]
19+
)
20+
21+
puts "Creating a tenant"
22+
WeaviateClient.client.schema.create(
23+
class_name: 'Thought',
24+
multi_tenant: true,
25+
description: 'Thoughts made by a bot about a subject',
26+
properties: [
27+
{
28+
"dataType": ["text"],
29+
"description": "The type of thought",
30+
"name": "type"
31+
}, {
32+
"dataType": ["text"],
33+
"description": "The observation (in brief)",
34+
"name": "brief"
35+
}, {
36+
"dataType": ["text"],
37+
"description": "The full observation",
38+
"name": "content"
39+
}, {
40+
"dataType": ["uuid"],
41+
"description": "The id of the subject",
42+
"name": "subject_id"
43+
}, {
44+
"dataType": ["uuid"],
45+
"description": "The id of the bot",
46+
"name": "bot_id"
47+
}
48+
],
49+
vectorizer: "text2vec-openai"
50+
)
51+
52+
puts "Adding a tenant for Thought class"
53+
puts client
54+
.schema
55+
.add_tenants(
56+
class_name: "Thought",
57+
tenants: ["fe744efd-9f39-4792-ade4-08bce8e1145f"]
58+
)
59+
60+
puts "Listings tenants for Thought class"
61+
puts client.schema.list_tenants(class_name: "Thought")

lib/weaviate/schema.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,16 @@ def add_tenants(
100100
class_name:,
101101
tenants:
102102
)
103-
response = client.connection.post("#{PATH}/#{class_name}/tenants") do |req|
104-
req.body = {}
105-
req.body = tenants.map { |tenant| { name: tenant } }
106-
end
107-
108-
if response.success?
103+
client.connection.post("#{PATH}/#{class_name}/tenants") do |req|
104+
tenants_str = tenants.map { |t| %({"name": "#{t}"}) }.join(", ")
105+
req.body = "[#{tenants_str}]"
109106
end
110-
response.body
111107
end
112108

113109
# List tenants of a class.
114110
def list_tenants(class_name:)
115111
response = client.connection.get("#{PATH}/#{class_name}/tenants")
116-
response.body if response.success?
112+
response.body
117113
end
118114

119115
# Remove one or more tenants from a class.

0 commit comments

Comments
 (0)