Skip to content
forked from ScotterC/pinecone

Ruby client for Pinecone Vector DB

Notifications You must be signed in to change notification settings

leio10/pinecone

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pinecone Ruby Client

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

gem install pinecone

Configuration

require "dotenv/load"
require 'pinecone'

Pinecone.configure do |config|
  config.api_key  = ENV.fetch('PINECONE_API_KEY')
  config.environment = ENV.fetch('PINECONE_ENVIRONMENT')
end

Index Operations

Listing Indexes

pinecone = Pinecone::Client.new
pinecone.list_indexes

Describe Index

pinecone.describe_index("example-index")

Create Index

pinecone.create_index({
  "metric": "dotproduct",
  "name": "example-index",
  "dimension": 3,
})

Delete Index

pinecone.delete_index("example-index")

Vector Operations

Adding vectors to an existing index

pinecone = Pinecone::Client.new
index = pinecone.index("example-index")

index.upsert(
  vectors: [{
    id: "1",
    metadata: {
      key: value
    },
    namespace: "example-namespace",
    values: [
      0.1,
      0.2,
      0.0
    ]
  }]
)

Querying index with a vector

  pinecone = Pinecone::Client.new
  index = pinecone.index("example-index")
  embedding = [0.0, -0.2, 0.4]
  response = index.query(vector: embedding)

Querying index with options

  pinecone = Pinecone::Client.new
  index = pinecone.index("example-index")
  embedding = [0.0, -0.2, 0.4]
  response = index.query(vector: embedding, 
                         namespace: "example-namespace",
                         top_k: 10,
                         include_values: false,
                         include_metadata: true)

Fetching a vector from an index

  pinecone = Pinecone::Client.new
  index = pinecone.index("example-index")
  index.fetch(
    ids: ["1"], 
    namespace: "example-namespace"
  )

Deleting a vector from an index

  pinecone = Pinecone::Client.new
  index = pinecone.index("example-index")
  index.delete(
    ids: ["1"], 
    namespace: "example-namespace", 
    delete_all: false
  )

Collection Operations

Creating a collection

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

List collections

  pinecone = Pinecone::Client.new
  pinecone.list_collections

Describe a collection

  pinecone = Pinecone::Client.new
  pinecone.describe_collection("example-collection")

Delete a collection

  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
    • 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

About

Ruby client for Pinecone Vector DB

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%