Class: Pinecone::Index
- Inherits:
-
Object
- Object
- Pinecone::Index
- Defined in:
- lib/pinecone/index.rb
Defined Under Namespace
Classes: QueryError
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
- .[](name) ⇒ Object
-
.create(name:, params: {}) ⇒ Object
# POST Create # Creates an index docs.pinecone.io/docs/manage-indexes#creating-an-index.
-
.list ⇒ Object
# Get Index # Lists all databases docs.pinecone.io/docs/manage-indexes#getting-information-on-your-indexes.
Instance Method Summary collapse
-
#configure(params:) ⇒ Object
# PATCH Configure # Creates an index docs.pinecone.io/docs/manage-indexes#creating-an-index.
-
#delete ⇒ Object
# DELETE # Creates an index docs.pinecone.io/docs/manage-indexes#deleting-an-index.
-
#describe ⇒ Object
# Get Show # Show database info docs.pinecone.io/docs/manage-indexes#getting-information-on-your-indexes.
-
#describe_index_stats ⇒ Object
# Get Show # Show database info docs.pinecone.io/docs/manage-indexes#getting-information-on-your-indexes.
-
#initialize(name:) ⇒ Index
constructor
A new instance of Index.
- #prefix ⇒ Object
-
#query(vector, options: {}) ⇒ Object
# POST Query # Provide a vector and retrieve the top-k most similar vectors for each query docs.pinecone.io/docs/query-data#sending-a-query.
-
#vectors ⇒ Object
# Vectors API.
Constructor Details
#initialize(name:) ⇒ Index
Returns a new instance of Index.
6 7 8 |
# File 'lib/pinecone/index.rb', line 6 def initialize(name:) self.name = name end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/pinecone/index.rb', line 5 def name @name end |
Class Method Details
.[](name) ⇒ Object
10 11 12 |
# File 'lib/pinecone/index.rb', line 10 def self.[](name) self.new(name: name) end |
.create(name:, params: {}) ⇒ Object
# POST Create # Creates an index docs.pinecone.io/docs/manage-indexes#creating-an-index
35 36 37 38 39 40 41 42 43 |
# File 'lib/pinecone/index.rb', line 35 def self.create(name:, params: {}) defaults = { name: name, dimension: 128 } body = defaults.merge(params.deep_symbolize_keys) Pinecone::Client.json_post(prefix: 'controller', path: "/databases", parameters: body) self.new(name: name) end |
.list ⇒ Object
# Get Index # Lists all databases docs.pinecone.io/docs/manage-indexes#getting-information-on-your-indexes
27 28 29 30 |
# File 'lib/pinecone/index.rb', line 27 def self.list indexes = Pinecone::Client.get(prefix: 'controller', path: "/databases") indexes.map{|i| self.new(name: i) } end |
Instance Method Details
#configure(params:) ⇒ Object
# PATCH Configure # Creates an index docs.pinecone.io/docs/manage-indexes#creating-an-index
80 81 82 |
# File 'lib/pinecone/index.rb', line 80 def configure(params:) Pinecone::Client.json_patch(prefix: 'controller', path: "/databases/#{name}", parameters: params) end |
#delete ⇒ Object
# DELETE # Creates an index docs.pinecone.io/docs/manage-indexes#deleting-an-index
87 88 89 |
# File 'lib/pinecone/index.rb', line 87 def delete Pinecone::Client.delete(prefix: 'controller', path: "/databases/#{name}") end |
#describe ⇒ Object
# Get Show # Show database info docs.pinecone.io/docs/manage-indexes#getting-information-on-your-indexes
66 67 68 |
# File 'lib/pinecone/index.rb', line 66 def describe Pinecone::Client.get(prefix: 'controller', path: "/databases/#{name}") end |
#describe_index_stats ⇒ Object
# Get Show # Show database info docs.pinecone.io/docs/manage-indexes#getting-information-on-your-indexes
73 74 75 |
# File 'lib/pinecone/index.rb', line 73 def describe_index_stats Pinecone::Client.get(prefix: prefix, path: '/describe_index_stats') end |
#prefix ⇒ Object
14 15 16 |
# File 'lib/pinecone/index.rb', line 14 def prefix "#{name}-#{Pinecone::Client.project_name}.svc" end |
#query(vector, options: {}) ⇒ Object
# POST Query # Provide a vector and retrieve the top-k most similar vectors for each query docs.pinecone.io/docs/query-data#sending-a-query
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/pinecone/index.rb', line 48 def query(vector, options: {}) defaults = { "includeValues": false, "includeMetadata": true, "topK": 5, "vector": vector } body = defaults.merge() result = Pinecone::Client.json_post(prefix: prefix, path: '/query', parameters: body) if !result.success? raise QueryError.new("Query failed with #{result.response.code} - #{result.parsed_response.to_s}") end result.parsed_response end |