Ruby Pinecone
Rather use the more full featured libary
This was built to hit a deadline.
Please rather use https://github.com/ScotterC/pinecone
It's well maintained and full featured.
Description
Ruby library to make interacting with the Pinecone Vector Database API easier.
Format and workings inspired by https://github.com/alexrudall/ruby-openai
Installation
Add this line to your application's Gemfile:
gem 'ruby-pinecone'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install ruby-pinecone
Usage
Quickstart
For a quick test you can pass your token directly to a new client:
client = Pinecone::Client.new(api_key: "access_token_goes_here", environment: "us-east1-gcp")
With Config
For a more robust setup, you can configure the gem with your API keys, for example in a pinecone.rb initializer. Never hardcode secrets into your codebase - instead use something like dotenv to pass the keys safely into your environments.
Pinecone.configuration.api_key = ENV.fetch('PINECONE_API_KEY')
Pinecone.configuration.environment = ENV.fetch('PINECONE_ENVIRONMENT')
Then you can create a client like this:
client = Pinecone::Client.new
Indexes
View Indexes
client = Pinecone::Client.new
indexes = client.indexes.list
index = client.indexes['my-index']
index.describe
index.describe_index_stats
Create Index
index = client.indexes.create(name: 'my-new-index', params: {dimension: 1536})
Delete Index
index = client.indexes['my-index']
index.delete
Update an Index
index = client.indexes['my-index']
index.configure(params: {pod_type: 's1.x2'})
Manage Vectors
Upsert
client = Pinecone::Client.new
index = client.indexes['my-index']
body = {
vectors: [
{
id: 'id-1',
values: [0.1, 0.1, 0.1, 0.1, 0.1],
metadata: {genre: 'comedy', year: 2020}
},
{
id: 'id-2',
values: [0.2, 0.2, 0.2, 0.2, 0.2],
metadata: {genre: 'drama'}
},
]
}
index.vectors.upsert(body)
Delete
client = Pinecone::Client.new
index = client.indexes['my-index']
index.vectors.delete(ids: ['id-1', 'id-2'])
Query
client = Pinecone::Client.new
index = client.indexes['my-index']
options = {
"includeValues": false,
"includeMetadata": true,
"topK": 10,
}
index.query([1.0, 1.0], options: options)
index.query(nil, options: options)
Development
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.
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.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ruby-pinecone. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the Ruby Pinecone project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.