Skip to content

Commit f74cded

Browse files
Merge branch 'main' into replace_object
2 parents c74ce4e + 26930cb commit f74cded

File tree

4 files changed

+89
-5
lines changed

4 files changed

+89
-5
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
- Allow the user to specify any options they want for multi-tenancy when creating a schema using their own hash
1212
- Allow Ollama vectorizer
1313

14+
## [0.8.10] - 2024-01-25
15+
16+
## [0.8.9] - 2023-10-10
17+
18+
## [0.8.8] - 2023-10-10
19+
20+
## [0.8.7] - 2023-09-11
21+
22+
## [0.8.6] - 2023-08-10
23+
1424
## [0.8.5] - 2023-07-19
1525
- Add multi-tenancy support
1626

README.md

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ Ruby wrapper for the Weaviate.io API.
1010

1111
Part of the [Langchain.rb](https://github.com/andreibondarev/langchainrb) stack.
1212

13+
Available for paid consulting engagements! [Email me](mailto:[email protected]).
14+
1315
![Tests status](https://github.com/andreibondarev/weaviate-ruby/actions/workflows/ci.yml/badge.svg)
1416
[![Gem Version](https://badge.fury.io/rb/weaviate-ruby.svg)](https://badge.fury.io/rb/weaviate-ruby)
1517
[![Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/gems/weaviate-ruby)
1618
[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/andreibondarev/weaviate-ruby/blob/main/LICENSE.txt)
1719
[![](https://dcbadge.vercel.app/api/server/WDARp7J2n8?compact=true&style=flat)](https://discord.gg/WDARp7J2n8)
20+
[![X](https://img.shields.io/twitter/url/https/twitter.com/cloudposse.svg?style=social&label=Follow%20%40rushing_andrei)](https://twitter.com/rushing_andrei)
1821

1922
## Installation
2023

@@ -63,7 +66,7 @@ client.schema.create(
6366
"name": "category"
6467
}
6568
],
66-
# Possible values: 'text2vec-cohere', 'text2vec-openai', 'text2vec-huggingface', 'text2vec-transformers', 'text2vec-contextionary', 'img2vec-neural', 'multi2vec-clip', 'ref2vec-centroid'
69+
# Possible values: 'text2vec-cohere', 'text2vec-ollama', 'text2vec-openai', 'text2vec-huggingface', 'text2vec-transformers', 'text2vec-contextionary', 'img2vec-neural', 'multi2vec-clip', 'ref2vec-centroid'
6770
vectorizer: "text2vec-openai"
6871
)
6972

@@ -73,9 +76,6 @@ client.schema.get(class_name: 'Question')
7376
# Get the schema
7477
client.schema.list()
7578

76-
# Remove a class (and all data in the instances) from the schema.
77-
client.schema.delete(class_name: 'Question')
78-
7979
# Update settings of an existing schema class.
8080
# Does not support modifying existing properties.
8181
client.schema.update(
@@ -94,6 +94,51 @@ client.schema.add_property(
9494

9595
# Inspect the shards of a class
9696
client.schema.shards(class_name: 'Question')
97+
98+
# Remove a class (and all data in the instances) from the schema.
99+
client.schema.delete(class_name: 'Question')
100+
101+
# Creating a new data object class in the schema while configuring the vectorizer on the schema and on individual properties (Ollama example)
102+
client.schema.create(
103+
class_name: 'Question',
104+
description: 'Information from a Jeopardy! question',
105+
properties: [
106+
{
107+
"dataType": ["text"],
108+
"description": "The question",
109+
"name": "question"
110+
# By default all properties are included in the vector
111+
}, {
112+
"dataType": ["text"],
113+
"description": "The answer",
114+
"name": "answer",
115+
"moduleConfig": {
116+
"text2vec-ollama": {
117+
"skip": false,
118+
"vectorizePropertyName": true,
119+
},
120+
},
121+
}, {
122+
"dataType": ["text"],
123+
"description": "The category",
124+
"name": "category",
125+
"indexFilterable": true,
126+
"indexSearchable": false,
127+
"moduleConfig": {
128+
"text2vec-ollama": {
129+
"skip": true, # Don't include in the vector
130+
},
131+
},
132+
}
133+
],
134+
vectorizer: "text2vec-ollama",
135+
module_config: {
136+
"text2vec-ollama": {
137+
apiEndpoint: "http://localhost:11434",
138+
model: "mxbai-embed-large",
139+
},
140+
},
141+
)
97142
```
98143

99144
### Using the Objects endpoint
@@ -305,6 +350,30 @@ client.live?
305350
client.ready?
306351
```
307352

353+
### Tenants
354+
355+
Any schema can be multi-tenant
356+
357+
```ruby
358+
client.schema.create(
359+
# Other keys...
360+
mutli_tenant: true, # passes { enabled: true } to weaviate
361+
)
362+
```
363+
364+
You can also manually specify your multi tenancy configuration with a hash
365+
366+
```ruby
367+
client.schema.create(
368+
# Other keys...
369+
mutli_tenant: { enabled: true, autoTenantCreation: true, autoTenantActivation: true },
370+
)
371+
```
372+
373+
See [Weaviate Multi-tenancy operations](https://weaviate.io/developers/weaviate/manage-data/multi-tenancy). Note that the mix of snake case(used by Ruby) and lower camel case(used by Weaviate) is intentional as that hash is passed directly to Weaviate.
374+
375+
All data methods in this library support an optional `tenant` argument which must be passed if multi-tenancy is enabled on the related collection
376+
308377
## Development
309378

310379
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

lib/weaviate/client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Client
1010
API_VERSION = "v1"
1111

1212
API_KEY_HEADERS = {
13+
ollama: "X-Ollama-Not-Used",
1314
openai: "X-OpenAI-Api-Key",
1415
azure_openai: "X-Azure-Api-Key",
1516
cohere: "X-Cohere-Api-Key",

lib/weaviate/schema.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ def create(
4343
req.body["vectorizer"] = vectorizer unless vectorizer.nil?
4444
req.body["moduleConfig"] = module_config unless module_config.nil?
4545
req.body["properties"] = properties unless properties.nil?
46-
req.body["multiTenancyConfig"] = {enabled: true} unless multi_tenant.nil?
46+
if multi_tenant.is_a?(Hash)
47+
req.body["multiTenancyConfig"] = multi_tenant
48+
elsif multi_tenant.present?
49+
req.body["multiTenancyConfig"] = {enabled: true}
50+
end
4751
req.body["invertedIndexConfig"] = inverted_index_config unless inverted_index_config.nil?
4852
req.body["replicationConfig"] = replication_config unless replication_config.nil?
4953
end

0 commit comments

Comments
 (0)