Skip to content

Commit

Permalink
Adding endpoints and tests for collections
Browse files Browse the repository at this point in the history
  • Loading branch information
ScotterC committed Apr 4, 2023
1 parent ab913c5 commit 08c088b
Show file tree
Hide file tree
Showing 13 changed files with 527 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .env.copy
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PINECONE_API_KEY=your-api-key
PINECONE_ENVIRONMENT=us-east1-gcp
51 changes: 35 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Pinecone Ruby Client

Note: This is currently minimal functionality of the Pinecone API. Pull requests to fill out the gem are welcome.
This is most of the Pinecone API functionality and fully tested. Please see #TODO section for the endpoints that aren't fully fleshed out yet. Contributions are welcome!

## Installation

Expand Down Expand Up @@ -110,30 +110,49 @@ Deleting a vector from an index
)
```

## Supported Endpoints
## Collection Operations

Vector
Creating a collection
```ruby
pinecone = Pinecone::Client.new
pinecone.create_collection({
name: "example-collection",
source: "example-index"
})
```

- Upsert
- Query
- Fetch
- Delete
List collections
```ruby
pinecone = Pinecone::Client.new
pinecone.list_collections
```

Index
Describe a collection
```ruby
pinecone = Pinecone::Client.new
pinecone.describe_collection("example-collection")
```

- List Indexes
- Describe Index
- Create Index
- Delete Index
Delete a collection
```ruby
pinecone = Pinecone::Client.new
pinecone.delete_collection("example-collection")
```

## TODO

- Add filter, sparse vector and id options to query request
- Add functionality for
- POST Describe Index Stats
- POST Update Vectors
- GET list_collections
- POST create_collection
- GET describe_collection
- DELETE delete_collection
- Patch configure_index

## Contributing

Contributions welcome!

- Clone the repo locally
- `bundle` to install gems
- run tests with `rspec`
- `mv .env.copy .env` and add Pinecone API Key if developing a new endpoint or modifying existing ones
- to disable VCR and hit real endpoints, `NO_VCR=true rspec`
46 changes: 2 additions & 44 deletions lib/pinecone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "pinecone/client"
require "pinecone/index"
require "pinecone/vector"
require "pinecone/collection"
require "pinecone/version"

module Pinecone
Expand Down Expand Up @@ -47,47 +48,4 @@ def self.configuration
def self.configure
yield(configuration)
end
end

# Vector Operations

# # GET Describe Index Stats
# https://index_name-project_id.svc.environment.pinecone.io/describe_index_stats

# # POST Describe Index Stats
# https://index_name-project_id.svc.environment.pinecone.io/describe_index_stats

# # DELETE Delete Vectors
# https://index_name-project_id.svc.environment.pinecone.io/vectors/delete

# # POST Delete Vectors
# # The Delete operation deletes vectors, by id, from a single namespace.
# https://index_name-project_id.svc.environment.pinecone.io/vectors/delete

# # GET Fetch
# # The Fetch operation looks up and returns vectors, by ID, from a single namespace.
# https://index_name-project_id.svc.environment.pinecone.io/vectors/fetch

# # POST Update
# # The Update operation updates vector in a namespace.
# # If a value is included, it will overwrite the previous value.
# https://index_name-project_id.svc.environment.pinecone.io/vectors/update

# # GET list_collections
# https://controller.unknown.pinecone.io/collections

# POST create_collection

# GET describe_collection

# DELETE delete_collection

# GET list_indexes

# POST create_index

# GET describe_index

# DELETEdelete_index

# Patch configure_index
end
16 changes: 16 additions & 0 deletions lib/pinecone/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ def delete_index(index_name)
Pinecone::Index.new.delete(index_name)
end

def list_collections
Pinecone::Collection.new.list
end

def describe_collection(collection_name)
Pinecone::Collection.new.describe(collection_name)
end

def create_collection(body)
Pinecone::Collection.new.create(body)
end

def delete_collection(collection_name)
Pinecone::Collection.new.delete(collection_name)
end

# This is a very confusing naming convention
def index(index_name)
@index ||= Pinecone::Vector.new(index_name)
Expand Down
38 changes: 38 additions & 0 deletions lib/pinecone/collection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module Pinecone
class Collection
include HTTParty

def initialize
self.class.base_uri "https://controller.#{Pinecone.configuration.environment}.pinecone.io"

@headers = {
"Content-Type" => "application/json",
"Accept" => "application/json",
"Api-Key" => Pinecone.configuration.api_key,
}
end

def list
self.class.get('/collections', options)
end

def describe(collection_name)
self.class.get("/collections/#{collection_name}", options)
end

def create(body)
payload = options.merge(body: body.to_json)
self.class.post('/collections', payload)
end

def delete(collection_name)
self.class.delete("/collections/#{collection_name}", options)
end

def options
{
headers: @headers,
}
end
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 08c088b

Please sign in to comment.