|
| 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") |
0 commit comments