Skip to content

Commit ec3a7f3

Browse files
RonanLOUARNandreibondarev
authored andcommitted
fix(collection) Fix #create_index method
The readme says that we can pass and as parameter, but we can't. So here is the fix
1 parent 9056952 commit ec3a7f3

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
qdrant-ruby (0.9.9)
4+
qdrant-ruby (0.9.10)
55
faraday (>= 2.0.1, < 3)
66

77
GEM

lib/qdrant/collections.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,15 @@ def update_aliases(actions:)
9191
def create_index(
9292
collection_name:,
9393
field_name:,
94-
field_schema: nil
94+
field_schema: nil,
95+
wait: nil,
96+
ordering: nil
9597
)
9698
response = client.connection.put("#{PATH}/#{collection_name}/index") do |req|
97-
req.body = {
98-
field_name: field_name
99-
}
99+
req.params["ordering"] = ordering unless ordering.nil?
100+
# Add explicit false check to avoid nil case. True is default behavior.
101+
req.params["wait"] = wait unless wait.nil?
102+
req.body = { field_name: field_name }
100103
req.body["field_schema"] = field_schema unless field_schema.nil?
101104
end
102105

spec/qdrant/collections_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,52 @@
159159
expect(response.dig("status")).to eq("ok")
160160
expect(response.dig("result")).to eq(true)
161161
end
162+
163+
it "adds wait=false query param when specified" do
164+
allow_any_instance_of(Faraday::Connection).to receive(:put)
165+
.with("collections/test_collection/index?wait=false")
166+
.and_return(response)
167+
168+
response = collections.create_index(
169+
collection_name: "test_collection",
170+
field_name: "description",
171+
field_schema: "text",
172+
wait: false
173+
)
174+
expect(response.dig("status")).to eq("ok")
175+
expect(response.dig("result")).to eq(true)
176+
end
177+
178+
it "adds ordering query param when specified" do
179+
allow_any_instance_of(Faraday::Connection).to receive(:put)
180+
.with("collections/test_collection/index?ordering=weak")
181+
.and_return(response)
182+
183+
response = collections.create_index(
184+
collection_name: "test_collection",
185+
field_name: "description",
186+
field_schema: "text",
187+
ordering: "weak"
188+
)
189+
expect(response.dig("status")).to eq("ok")
190+
expect(response.dig("result")).to eq(true)
191+
end
192+
193+
it "adds both wait=false and ordering params when specified" do
194+
allow_any_instance_of(Faraday::Connection).to receive(:put)
195+
.with("collections/test_collection/index?ordering=weak&wait=false")
196+
.and_return(response)
197+
198+
response = collections.create_index(
199+
collection_name: "test_collection",
200+
field_name: "description",
201+
field_schema: "text",
202+
ordering: "weak",
203+
wait: false
204+
)
205+
expect(response.dig("status")).to eq("ok")
206+
expect(response.dig("result")).to eq(true)
207+
end
162208
end
163209

164210
describe "#delete_index" do

0 commit comments

Comments
 (0)