Class: OpenAI::Resources::VectorStores

Inherits:
Object
  • Object
show all
Defined in:
lib/openai/resources/vector_stores.rb,
lib/openai/resources/vector_stores/files.rb,
lib/openai/resources/vector_stores/file_batches.rb,
sig/openai/resources/vector_stores.rbs,
sig/openai/resources/vector_stores/files.rbs,
sig/openai/resources/vector_stores/file_batches.rbs

Defined Under Namespace

Classes: FileBatches, Files

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ VectorStores

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of VectorStores.

Parameters:



230
231
232
233
234
# File 'lib/openai/resources/vector_stores.rb', line 230

def initialize(client:)
  @client = client
  @files = OpenAI::Resources::VectorStores::Files.new(client: client)
  @file_batches = OpenAI::Resources::VectorStores::FileBatches.new(client: client)
end

Instance Attribute Details

#file_batchesOpenAI::Resources::VectorStores::FileBatches (readonly)



10
11
12
# File 'lib/openai/resources/vector_stores.rb', line 10

def file_batches
  @file_batches
end

#filesOpenAI::Resources::VectorStores::Files (readonly)



7
8
9
# File 'lib/openai/resources/vector_stores.rb', line 7

def files
  @files
end

Instance Method Details

#create(chunking_strategy: nil, description: nil, expires_after: nil, file_ids: nil, metadata: nil, name: nil, request_options: {}) ⇒ OpenAI::Models::VectorStore

Create a vector store.

Parameters:

  • chunking_strategy (OpenAI::Models::AutoFileChunkingStrategyParam, OpenAI::Models::StaticFileChunkingStrategyObjectParam)

    The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. Only applicable if file_ids is non-empty.

  • description (String)

    A description for the vector store. Can be used to describe the vector store's purpose.

  • expires_after (OpenAI::Models::VectorStoreCreateParams::ExpiresAfter)

    The expiration policy for a vector store.

  • file_ids (Array<String>)

    A list of File IDs that the vector store should use. Useful for tools like file_search that can access files.

  • metadata (Hash{Symbol=>String}, nil)

    Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.

    Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.

  • name (String)

    The name of the vector store.

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/openai/resources/vector_stores.rb', line 48

def create(params = {})
  parsed, options = OpenAI::VectorStoreCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "vector_stores",
    body: parsed,
    model: OpenAI::VectorStore,
    security: {bearer_auth: true},
    options: {extra_headers: {"OpenAI-Beta" => "assistants=v2"}, **options}
  )
end

#delete(vector_store_id, request_options: {}) ⇒ OpenAI::Models::VectorStoreDeleted

Delete a vector store.

Parameters:

  • vector_store_id (String)

    The ID of the vector store to delete.

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



175
176
177
178
179
180
181
182
183
# File 'lib/openai/resources/vector_stores.rb', line 175

def delete(vector_store_id, params = {})
  @client.request(
    method: :delete,
    path: ["vector_stores/%1$s", vector_store_id],
    model: OpenAI::VectorStoreDeleted,
    security: {bearer_auth: true},
    options: {extra_headers: {"OpenAI-Beta" => "assistants=v2"}, **params[:request_options].to_h}
  )
end

#list(after: nil, before: nil, limit: nil, order: nil, request_options: {}) ⇒ OpenAI::Internal::CursorPage<OpenAI::Models::VectorStore>

Returns a list of vector stores.

Parameters:

  • after (String)

    A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.

  • before (String)

    A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.

  • limit (Integer)

    A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.

  • order (Symbol, OpenAI::Models::VectorStoreListParams::Order)

    Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/openai/resources/vector_stores.rb', line 149

def list(params = {})
  parsed, options = OpenAI::VectorStoreListParams.dump_request(params)
  query = OpenAI::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "vector_stores",
    query: query,
    page: OpenAI::Internal::CursorPage,
    model: OpenAI::VectorStore,
    security: {bearer_auth: true},
    options: {extra_headers: {"OpenAI-Beta" => "assistants=v2"}, **options}
  )
end

#retrieve(vector_store_id, request_options: {}) ⇒ OpenAI::Models::VectorStore

Retrieves a vector store.

Parameters:

  • vector_store_id (String)

    The ID of the vector store to retrieve.

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



72
73
74
75
76
77
78
79
80
# File 'lib/openai/resources/vector_stores.rb', line 72

def retrieve(vector_store_id, params = {})
  @client.request(
    method: :get,
    path: ["vector_stores/%1$s", vector_store_id],
    model: OpenAI::VectorStore,
    security: {bearer_auth: true},
    options: {extra_headers: {"OpenAI-Beta" => "assistants=v2"}, **params[:request_options].to_h}
  )
end

#search(vector_store_id, query:, filters: nil, max_num_results: nil, ranking_options: nil, rewrite_query: nil, request_options: {}) ⇒ OpenAI::Internal::Page<OpenAI::Models::VectorStoreSearchResponse>

Search a vector store for relevant chunks based on a query and file attributes filter.

Parameters:

Returns:

See Also:



214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/openai/resources/vector_stores.rb', line 214

def search(vector_store_id, params)
  parsed, options = OpenAI::VectorStoreSearchParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["vector_stores/%1$s/search", vector_store_id],
    body: parsed,
    page: OpenAI::Internal::Page,
    model: OpenAI::Models::VectorStoreSearchResponse,
    security: {bearer_auth: true},
    options: {extra_headers: {"OpenAI-Beta" => "assistants=v2"}, **options}
  )
end

#update(vector_store_id, expires_after: nil, metadata: nil, name: nil, request_options: {}) ⇒ OpenAI::Models::VectorStore

Modifies a vector store.

Parameters:

  • vector_store_id (String)

    The ID of the vector store to modify.

  • expires_after (OpenAI::Models::VectorStoreUpdateParams::ExpiresAfter, nil)

    The expiration policy for a vector store.

  • metadata (Hash{Symbol=>String}, nil)

    Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.

    Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.

  • name (String, nil)

    The name of the vector store.

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/openai/resources/vector_stores.rb', line 108

def update(vector_store_id, params = {})
  parsed, options = OpenAI::VectorStoreUpdateParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["vector_stores/%1$s", vector_store_id],
    body: parsed,
    model: OpenAI::VectorStore,
    security: {bearer_auth: true},
    options: {extra_headers: {"OpenAI-Beta" => "assistants=v2"}, **options}
  )
end