Class: Pinecone::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/pinecone/index.rb

Defined Under Namespace

Classes: QueryError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject

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



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

.listObject



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

#deleteObject



87
88
89
# File 'lib/pinecone/index.rb', line 87

def delete
  Pinecone::Client.delete(prefix: 'controller', path: "/databases/#{name}")
end

#describeObject



66
67
68
# File 'lib/pinecone/index.rb', line 66

def describe
  Pinecone::Client.get(prefix: 'controller', path: "/databases/#{name}")
end

#describe_index_statsObject



73
74
75
# File 'lib/pinecone/index.rb', line 73

def describe_index_stats
  Pinecone::Client.get(prefix: prefix, path: '/describe_index_stats')
end

#prefixObject



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(options)
  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

#vectorsObject

# Vectors API



20
21
22
# File 'lib/pinecone/index.rb', line 20

def vectors
  @vectors ||= Pinecone::Vectors.new(index: self)
end