Skip to content

Commit 8e53b6d

Browse files
Merge pull request #64 from fkchang/add_named_vector_support
Add named vector support
2 parents bef476a + 74ece83 commit 8e53b6d

File tree

3 files changed

+102
-1
lines changed

3 files changed

+102
-1
lines changed

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,44 @@ client.schema.create(
139139
},
140140
},
141141
)
142+
143+
# Creating named schemas
144+
145+
client.schema.create(
146+
class_name: 'ArticleNV',
147+
description: 'Articles with named vectors',
148+
properties: [
149+
{
150+
"dataType": ["text"],
151+
"name": "title"
152+
},
153+
{
154+
"dataType": ["text"],
155+
"name": "body"
156+
}
157+
],
158+
# cannot use vectorizer and vector_config at the same time
159+
# will need to specify for each property
160+
vector_config: {
161+
"title": {
162+
"vectorizer": {
163+
"text2vec-openai": {
164+
"properties": ["title"]
165+
}
166+
},
167+
"vectorIndexType": "hnsw", # This is the default
168+
},
169+
"body": {
170+
"vectorizer": {
171+
"text2vec-openai": {
172+
"properties": ["body"]
173+
}
174+
},
175+
"vectorIndexType": "hnsw", # This is the default
176+
177+
}
178+
}
179+
)
142180
```
143181

144182
### Using the Objects endpoint
@@ -268,6 +306,17 @@ client.query.get class_name: 'Question', where: '{ operator: Like, valueText: "S
268306

269307
client.query.get class_name: 'Question', fields: 'answer question category _additional { id }', after: "3c5f7039-37f3-4244-b3e2-8f4a083e448d", limit: "1"
270308

309+
# Named vector query - uses targetVectors
310+
query_title = client.query.get(
311+
class_name: 'ArticleNV',
312+
fields: 'title body _additional { id }',
313+
near_text: '{
314+
targetVectors: ["title"],
315+
concepts: ["quantum computers advances"]
316+
}',
317+
limit: "2"
318+
)
319+
271320

272321

273322
```

lib/weaviate/schema.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def create(
3434
vectorizer: nil,
3535
module_config: nil,
3636
inverted_index_config: nil,
37-
replication_config: nil
37+
replication_config: nil,
38+
vector_config: nil # added for named vector support
3839
)
3940
response = client.connection.post(PATH) do |req|
4041
req.body = {}
@@ -56,6 +57,7 @@ def create(
5657

5758
req.body["invertedIndexConfig"] = inverted_index_config unless inverted_index_config.nil?
5859
req.body["replicationConfig"] = replication_config unless replication_config.nil?
60+
req.body["vectorConfig"] = vector_config unless vector_config.nil? # Added for multi vector support
5961
end
6062

6163
response.body

spec/weaviate/schema_spec.rb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,56 @@
101101
expect(@captured_request.body["multiTenancyConfig"]).to eq({enabled: true, autoTenantCreation: true, autoTenantActivation: true})
102102
end
103103
end
104+
105+
context "named vector config" do
106+
before do
107+
@captured_request = nil
108+
allow_any_instance_of(Faraday::Connection).to receive(:post) do |_, path, &block|
109+
expect(path).to eq("schema")
110+
req = OpenStruct.new(body: {})
111+
block.call(req)
112+
@captured_request = req
113+
response
114+
end
115+
end
116+
117+
it "sets up named vector config" do
118+
schema.create(
119+
class_name: "ArticleNV",
120+
description: "Articles with named vectors",
121+
properties: [
122+
{
123+
dataType: ["text"],
124+
name: "title"
125+
},
126+
{
127+
dataType: ["text"],
128+
name: "body"
129+
}
130+
],
131+
vector_config: {
132+
title: {
133+
vectorizer: {
134+
"text2vec-openai": {
135+
properties: ["title"]
136+
}
137+
},
138+
vectorIndexType: "hnsw" # Adding vector index type
139+
},
140+
body: {
141+
vectorizer: {
142+
"text2vec-openai": {
143+
properties: ["body"]
144+
}
145+
},
146+
vectorIndexType: "hnsw" # Adding vector index type
147+
}
148+
}
149+
)
150+
151+
expect(@captured_request.body["vectorConfig"]).to eq({title: {vectorizer: {"text2vec-openai": {properties: ["title"]}}, vectorIndexType: "hnsw"}, body: {vectorizer: {"text2vec-openai": {properties: ["body"]}}, vectorIndexType: "hnsw"}})
152+
end
153+
end
104154
end
105155

106156
describe "#delete" do

0 commit comments

Comments
 (0)