Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions lib/qdrant/points.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,45 @@ def batch_recommend(
response.body
end

# Universally query points. This endpoint covers all capabilities of search, recommend, discover, filters. But also enables hybrid and multi-stage queries.
def query(
collection_name:,
consistency: nil,
timeout: nil,
shard_key: nil,
prefetch: nil,
query: nil,
using: nil,
filter: nil,
params: nil,
score_threshold: nil,
limit: nil,
offset: nil,
with_vector: nil,
with_payload: nil,
lookup_from: nil
)
response = client.connection.post("collections/#{collection_name}/#{PATH}/query") do |req|
req.params["consistency"] = consistency unless consistency.nil?
req.params["timeout"] = timeout unless timeout.nil?

req.body = {}
req.body["shard_key"] = shard_key unless shard_key.nil?
req.body["prefetch"] = prefetch unless prefetch.nil?
req.body["query"] = query unless query.nil?
req.body["using"] = using unless using.nil?
req.body["filter"] = filter unless filter.nil?
req.body["params"] = params unless params.nil?
req.body["score_threshold"] = score_threshold unless score_threshold.nil?
req.body["limit"] = limit unless limit.nil?
req.body["offset"] = offset unless offset.nil?
req.body["with_vector"] = with_vector unless with_vector.nil?
req.body["with_payload"] = with_payload unless with_payload.nil?
req.body["lookup_from"] = lookup_from unless lookup_from.nil?
end
response.body
end

# Count points which matches given filtering condition
def count(
collection_name:,
Expand Down
21 changes: 21 additions & 0 deletions spec/qdrant/points_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,25 @@
expect(response.dig("status")).to eq("ok")
end
end

describe "#query" do
let(:response) {
OpenStruct.new(body: points_fixture)
}

before do
allow_any_instance_of(Faraday::Connection).to receive(:post)
.with("collections/test_collection/points/query")
.and_return(response)
end

it "returns the data" do
response = client.points.query(
collection_name: "test_collection",
query: [0.05, 0.61, 0.76, 0.74],
limit: 10
)
expect(response.dig("result").count).to eq(5)
end
end
end