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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: ["2.7", "3.0", "3.1", "3.2"]
ruby: ["3.3", "3.4", "4.0"]

steps:
- uses: actions/checkout@master
Expand All @@ -29,4 +29,4 @@ jobs:

- name: Run tests
run: |
bundle exec rspec
bundle exec rspec
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@

# rspec failure tracking
.rspec_status
.env
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ gemspec
gem "rake", "~> 13.4"

gem "rspec", "~> 3.13"
gem "standard", "~> 1.28.5"
gem "standard", "~> 1.56.0"
92 changes: 48 additions & 44 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@ PATH
remote: .
specs:
qdrant-ruby (0.9.10)
faraday (>= 2.0.1, < 3)
logger

GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
base64 (0.2.0)
byebug (11.1.3)
ast (2.4.3)
byebug (13.0.0)
reline (>= 0.6.0)
coderay (1.1.3)
diff-lcs (1.6.2)
faraday (2.8.1)
base64
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (3.0.2)
json (2.7.4)
language_server-protocol (3.17.0.3)
io-console (0.9.2)
json (2.21.2)
language_server-protocol (3.17.0.6)
lint_roller (1.1.0)
method_source (1.0.0)
parallel (1.24.0)
parser (3.3.5.0)
logger (1.7.0)
method_source (1.1.0)
parallel (2.1.0)
parser (3.3.12.0)
ast (~> 2.4.1)
racc
pry (0.14.2)
prism (1.9.0)
pry (0.16.0)
coderay (~> 1.1)
method_source (~> 1.0)
pry-byebug (3.10.1)
byebug (~> 11.0)
pry (>= 0.13, < 0.15)
reline (>= 0.6.0)
pry-byebug (3.12.0)
byebug (~> 13.0)
pry (>= 0.13, < 0.17)
racc (1.8.1)
rainbow (3.1.1)
rake (13.4.2)
regexp_parser (2.9.2)
rexml (3.4.2)
regexp_parser (2.12.0)
reline (0.7.0)
io-console (~> 0.5)
rspec (3.13.2)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
Expand All @@ -45,40 +45,44 @@ GEM
rspec-expectations (3.13.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.6)
rspec-mocks (3.13.8)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.6)
rubocop (1.50.2)
rspec-support (3.13.7)
rubocop (1.88.2)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.2.0.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (>= 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.0, < 2.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.49.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-performance (1.16.0)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.50.0)
parser (>= 3.3.7.2)
prism (~> 1.7)
rubocop-performance (1.26.1)
lint_roller (~> 1.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.47.1, < 2.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
standard (1.28.5)
standard (1.56.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50.2)
rubocop (~> 1.88.0)
standard-custom (~> 1.0.0)
standard-performance (~> 1.0.1)
standard-performance (~> 1.8)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
standard-performance (1.0.1)
lint_roller (~> 1.0)
rubocop-performance (~> 1.16.0)
unicode-display_width (2.6.0)
standard-performance (1.9.0)
lint_roller (~> 1.1)
rubocop-performance (~> 1.26.0)
unicode-display_width (3.2.0)
unicode-emoji (~> 4.1)
unicode-emoji (4.2.0)

PLATFORMS
arm64-darwin-23
Expand All @@ -92,7 +96,7 @@ DEPENDENCIES
qdrant-ruby!
rake (~> 13.4)
rspec (~> 3.13)
standard (~> 1.28.5)
standard (~> 1.56.0)

BUNDLED WITH
2.4.0
2.5.3
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,16 @@ client.set_lock(

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.

The default `bundle exec rake` task runs `lint` (standardrb auto-format), `spec`, and `e2e` (a hosted end-to-end smoke test against a real Qdrant deployment) in sequence. Because the E2E step needs real credentials, run it with your hosted endpoint and API key exported:

```sh
export QDRANT_URL="https://<hosted-qdrant-endpoint>"
export QDRANT_API_KEY="<project-api-key>"
bundle exec rake
```

The individual steps are also available as `bundle exec rake lint`, `bundle exec rake spec`, and `bundle exec rake e2e`. Run the hosted check against an isolated or disposable project, since it creates and deletes a temporary collection.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing
Expand Down
13 changes: 12 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rbconfig"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

task default: :spec
desc "Run the standardrb linter (auto-fix)"
task :lint do
sh "bundle exec standardrb --fix"
end

desc "Run the hosted Qdrant API end-to-end smoke test"
task :e2e do
exec RbConfig.ruby, File.expand_path("script/e2e.rb", __dir__)
end

task default: %i[lint spec e2e]
35 changes: 21 additions & 14 deletions lib/qdrant/client.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

require "faraday"
require "logger"
require "forwardable"

require_relative "client/connection"

module Qdrant
class Client
extend Forwardable
Expand All @@ -14,28 +16,24 @@ class Client
def initialize(
url:,
api_key: nil,
adapter: Faraday.default_adapter,
raise_error: false,
logger: nil
logger: nil,
adapter: nil # Deprecated. Doesn't select the transport. Should be removed in subsequent releases
)
@url = url
@url = normalize_url(url)
@api_key = api_key
@adapter = adapter
@raise_error = raise_error
@logger = logger || Logger.new($stdout)
end

def connection
@connection ||= Faraday.new(url: url) do |faraday|
if api_key
faraday.headers["api-key"] = api_key
end
faraday.request :json
faraday.response :logger, @logger, {headers: true, bodies: true, errors: true}
faraday.response :raise_error if raise_error
faraday.response :json, content_type: /\bjson$/
faraday.adapter adapter
end
@connection ||= Connection.new(
url: url,
api_key: api_key,
raise_error: raise_error,
logger: logger
)
end

def aliases
Expand All @@ -61,5 +59,14 @@ def clusters
def points
@points ||= Qdrant::Points.new(client: self)
end

private

def normalize_url(url)
raise ArgumentError, "url must be a String" unless url.is_a?(String)
return url if url.start_with?("http://", "https://")

"https://#{url}"
end
end
end
51 changes: 51 additions & 0 deletions lib/qdrant/client/connection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# frozen_string_literal: true

require "net/http"

require_relative "request"
require_relative "response"

module Qdrant
class Client
class Connection
def initialize(url:, api_key:, raise_error:, logger:)
@uri = url
@api_key = api_key
@raise_error = raise_error
@logger = logger
end

def get(path, &block)
execute(Net::HTTP::Get, path, &block)
end

def post(path, &block)
execute(Net::HTTP::Post, path, &block)
end

def put(path, &block)
execute(Net::HTTP::Put, path, &block)
end

def patch(path, &block)
execute(Net::HTTP::Patch, path, &block)
end

def delete(path, &block)
execute(Net::HTTP::Delete, path, &block)
end

private

def execute(verb, path, &block)
response = RequestBuilder
.new(verb, @uri, path, @api_key, @logger)
.tap(&block)
.build
.perform(@raise_error)

ResponseBuilder.new(response).build
end
end
end
end
Loading