Class: Roseflow::Pinecone::Vector

Inherits:
Object
  • Object
show all
Defined in:
lib/roseflow/pinecone/vector.rb,
lib/roseflow/pinecone/vectors/query.rb,
lib/roseflow/pinecone/vectors/filter.rb,
lib/roseflow/pinecone/vectors/update.rb,
lib/roseflow/pinecone/vectors/upsert.rb,
lib/roseflow/pinecone/vectors/deletion.rb,
lib/roseflow/pinecone/vectors/sparse_vector.rb,
lib/roseflow/pinecone/vectors/vector_object.rb

Defined Under Namespace

Classes: Deletion, Filter, Query, SparseVector, Update, Upsert, VectorObject

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Vector

Returns a new instance of Vector.



14
15
16
# File 'lib/roseflow/pinecone/vector.rb', line 14

def initialize(connection)
  @connection = connection
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



12
13
14
# File 'lib/roseflow/pinecone/vector.rb', line 12

def connection
  @connection
end

Class Method Details

.build(id:, values:, sparse_values: nil, metadata: nil) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/roseflow/pinecone/vector.rb', line 18

def self.build(id:, values:, sparse_values: nil, metadata: nil)
  VectorObject.new(
    id: id,
    values: values,
    sparse_values: sparse_values,
    metadata: ,
  )
end

Instance Method Details

#delete(query) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/roseflow/pinecone/vector.rb', line 39

def delete(query)
  object = query.is_a?(Deletion) ? query : Deletion.new(query)
  VectorResponse.new(
    method: :delete,
    response: @connection.post("/vectors/delete", object.to_json),
  )
end

#empty?(namespace = "") ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/roseflow/pinecone/vector.rb', line 27

def empty?(namespace = "")
  query(namespace: namespace).vectors.empty?
end

#fetch(options) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/roseflow/pinecone/vector.rb', line 63

def fetch(options)
  query_string = URI.encode_www_form(
    {
      namespace: options.fetch(:namespace, ""),
      ids: options.fetch(:ids, []),
    }
  )
  VectorQueryResponse.new(
    method: :fetch,
    response: @connection.get("/vectors/fetch?#{query_string}"),
  )
end

#query(query) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/roseflow/pinecone/vector.rb', line 31

def query(query)
  object = query.is_a?(Query) ? query : Query.new(query)
  VectorQueryResponse.new(
    method: :query,
    response: @connection.post("/query", object.to_json),
  )
end

#update(vectors) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/roseflow/pinecone/vector.rb', line 47

def update(vectors)
  object = vectors.is_a?(Update) ? vectors : Update.new(vectors)
  VectorResponse.new(
    method: :update,
    response: @connection.post("/vectors/update", object.to_json),
  )
end

#upsert(data) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/roseflow/pinecone/vector.rb', line 55

def upsert(data)
  object = data.is_a?(Upsert) ? data : Upsert.from(data)
  VectorResponse.new(
    method: :upsert,
    response: @connection.post("/vectors/upsert", object.to_json),
  )
end