Class: LLM::OpenAI::VectorStores

Inherits:
Object
  • Object
show all
Defined in:
lib/llm/providers/openai/vector_stores.rb

Overview

The LLM::OpenAI::VectorStore class provides an interface to OpenAI’s vector stores API

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(provider) ⇒ VectorStores

Returns a new instance of VectorStores.

Parameters:



12
13
14
# File 'lib/llm/providers/openai/vector_stores.rb', line 12

def initialize(provider)
  @provider = provider
end

Instance Method Details

#all(**params) ⇒ LLM::Response

List all vector stores

Parameters:

  • params (Hash)

    Other parameters (see OpenAI docs)

Returns:



20
21
22
23
24
25
# File 'lib/llm/providers/openai/vector_stores.rb', line 20

def all(**params)
  query = URI.encode_www_form(params)
  req = Net::HTTP::Get.new("/v1/vector_stores?#{query}", headers)
  res = execute(request: req)
  LLM::Response.new(res)
end

#create(name:, file_ids: [], **params) ⇒ LLM::Response

Create a vector store

Parameters:

  • name (String)

    The name of the vector store

  • file_ids (Array<String>) (defaults to: [])

    The IDs of the files to include in the vector store

  • params (Hash)

    Other parameters (see OpenAI docs)

Returns:

See Also:



35
36
37
38
39
40
# File 'lib/llm/providers/openai/vector_stores.rb', line 35

def create(name:, file_ids: [], **params)
  req = Net::HTTP::Post.new("/v1/vector_stores", headers)
  req.body = JSON.dump(params.merge({name:, file_ids:}).compact)
  res = execute(request: req)
  LLM::Response.new(res)
end

#delete(vector:) ⇒ LLM::Response

Delete a vector store

Parameters:

  • vector (String, #id)

    The ID of the vector store

Returns:

See Also:



77
78
79
80
81
82
# File 'lib/llm/providers/openai/vector_stores.rb', line 77

def delete(vector:)
  vector_id = vector.respond_to?(:id) ? vector.id : vector
  req = Net::HTTP::Delete.new("/v1/vector_stores/#{vector_id}", headers)
  res = execute(request: req)
  LLM::Response.new(res)
end

#get(vector:) ⇒ LLM::Response

Get a vector store

Parameters:

  • vector (String, #id)

    The ID of the vector store

Returns:

See Also:



48
49
50
51
52
53
# File 'lib/llm/providers/openai/vector_stores.rb', line 48

def get(vector:)
  vector_id = vector.respond_to?(:id) ? vector.id : vector
  req = Net::HTTP::Get.new("/v1/vector_stores/#{vector_id}", headers)
  res = execute(request: req)
  LLM::Response.new(res)
end

#modify(vector:, name: nil, **params) ⇒ LLM::Response

Modify an existing vector store

Parameters:

  • vector (String, #id)

    The ID of the vector store

  • name (String) (defaults to: nil)

    The new name of the vector store

  • params (Hash)

    Other parameters (see OpenAI docs)

Returns:

See Also:



63
64
65
66
67
68
69
# File 'lib/llm/providers/openai/vector_stores.rb', line 63

def modify(vector:, name: nil, **params)
  vector_id = vector.respond_to?(:id) ? vector.id : vector
  req = Net::HTTP::Post.new("/v1/vector_stores/#{vector_id}", headers)
  req.body = JSON.dump(params.merge({name:}).compact)
  res = execute(request: req)
  LLM::Response.new(res)
end

#search(vector:, query:, **params) ⇒ LLM::Response

Search a vector store

Parameters:

  • vector (String, #id)

    The ID of the vector store

  • query (String)

    The query to search for

  • params (Hash)

    Other parameters (see OpenAI docs)

Returns:

See Also:



92
93
94
95
96
97
98
# File 'lib/llm/providers/openai/vector_stores.rb', line 92

def search(vector:, query:, **params)
  vector_id = vector.respond_to?(:id) ? vector.id : vector
  req = Net::HTTP::Post.new("/v1/vector_stores/#{vector_id}/search", headers)
  req.body = JSON.dump(params.merge({query:}).compact)
  res = execute(request: req)
  LLM::Response.new(res)
end