Skip to content

Commit 2ea24b7

Browse files
committed
Support query endpoint
1 parent ab5b43c commit 2ea24b7

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

lib/qdrant/points.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,45 @@ def batch_recommend(
294294
response.body
295295
end
296296

297+
# Universally query points. This endpoint covers all capabilities of search, recommend, discover, filters. But also enables hybrid and multi-stage queries.
298+
def query(
299+
collection_name:,
300+
consistency: nil,
301+
timeout: nil,
302+
shard_key: nil,
303+
prefetch: nil,
304+
query: nil,
305+
using: nil,
306+
filter: nil,
307+
params: nil,
308+
score_threshold: nil,
309+
limit: nil,
310+
offset: nil,
311+
with_vector: nil,
312+
with_payload: nil,
313+
lookup_from: nil
314+
)
315+
response = client.connection.post("collections/#{collection_name}/#{PATH}/query") do |req|
316+
req.params["consistency"] = consistency unless consistency.nil?
317+
req.params["timeout"] = timeout unless timeout.nil?
318+
319+
req.body = {}
320+
req.body["shard_key"] = shard_key unless shard_key.nil?
321+
req.body["prefetch"] = prefetch unless prefetch.nil?
322+
req.body["query"] = query unless query.nil?
323+
req.body["using"] = using unless using.nil?
324+
req.body["filter"] = filter unless filter.nil?
325+
req.body["params"] = params unless params.nil?
326+
req.body["score_threshold"] = score_threshold unless score_threshold.nil?
327+
req.body["limit"] = limit unless limit.nil?
328+
req.body["offset"] = offset unless offset.nil?
329+
req.body["with_vector"] = with_vector unless with_vector.nil?
330+
req.body["with_payload"] = with_payload unless with_payload.nil?
331+
req.body["lookup_from"] = lookup_from unless lookup_from.nil?
332+
end
333+
response.body
334+
end
335+
297336
# Count points which matches given filtering condition
298337
def count(
299338
collection_name:,

spec/qdrant/points_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,25 @@
290290
expect(response.dig("status")).to eq("ok")
291291
end
292292
end
293+
294+
describe "#query" do
295+
let(:response) {
296+
OpenStruct.new(body: points_fixture)
297+
}
298+
299+
before do
300+
allow_any_instance_of(Faraday::Connection).to receive(:post)
301+
.with("collections/test_collection/points/query")
302+
.and_return(response)
303+
end
304+
305+
it "return the data" do
306+
response = client.points.query(
307+
collection_name: "test_collection",
308+
query: [0.05, 0.61, 0.76, 0.74],
309+
limit: 10
310+
)
311+
expect(response.dig("result").count).to eq(5)
312+
end
313+
end
293314
end

0 commit comments

Comments
 (0)