Class: Vellum::AsyncDocumentIndexesClient

Inherits:
Object
  • Object
show all
Defined in:
lib/vellum_ai/document_indexes/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ AsyncDocumentIndexesClient

Parameters:



177
178
179
180
# File 'lib/vellum_ai/document_indexes/client.rb', line 177

def initialize(request_client:)
  # @type [AsyncRequestClient]
  @request_client = request_client
end

Instance Attribute Details

#request_clientObject (readonly)

Returns the value of attribute request_client.



173
174
175
# File 'lib/vellum_ai/document_indexes/client.rb', line 173

def request_client
  @request_client
end

Instance Method Details

#create(label:, name:, indexing_config:, status: nil, environment: nil, copy_documents_from_index_id: nil, request_options: nil) ⇒ DocumentIndexRead

Creates a new document index.

Parameters:

  • label (String)

    A human-readable label for the document index

  • name (String)

    A name that uniquely identifies this index within its workspace

  • status (ENTITY_STATUS) (defaults to: nil)

    The current status of the document index

    • ‘ACTIVE` - Active

    • ‘ARCHIVED` - Archived

  • environment (ENVIRONMENT_ENUM) (defaults to: nil)

    The environment this document index is used in

    • ‘DEVELOPMENT` - Development

    • ‘STAGING` - Staging

    • ‘PRODUCTION` - Production

  • indexing_config (Hash{String => String})

    Configuration representing how documents should be indexed

  • copy_documents_from_index_id (String) (defaults to: nil)

    Optionally specify the id of a document index from which you’d like to copy and re-index its documents into this newly created index

  • request_options (RequestOptions) (defaults to: nil)

Returns:



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/vellum_ai/document_indexes/client.rb', line 226

def create(label:, name:, indexing_config:, status: nil, environment: nil, copy_documents_from_index_id: nil,
           request_options: nil)
  Async do
    response = @request_client.conn.post do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["X_API_KEY"] = request_options.api_key unless request_options&.api_key.nil?
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.body = {
        **(request_options&.additional_body_parameters || {}),
        label: label,
        name: name,
        status: status,
        environment: environment,
        indexing_config: indexing_config,
        copy_documents_from_index_id: copy_documents_from_index_id
      }.compact
      req.url "#{@request_client.default_environment[:Default]}/v1/document-indexes"
    end
    DocumentIndexRead.from_json(json_object: response.body)
  end
end

#destroy(id:, request_options: nil) ⇒ Void

Used to delete a Document Index given its ID.

Parameters:

  • id (String)

    A UUID string identifying this document index.

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


301
302
303
304
305
306
307
308
309
310
# File 'lib/vellum_ai/document_indexes/client.rb', line 301

def destroy(id:, request_options: nil)
  Async do
    @request_client.conn.delete do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["X_API_KEY"] = request_options.api_key unless request_options&.api_key.nil?
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.url "#{@request_client.default_environment[:Default]}/v1/document-indexes/#{id}"
    end
  end
end

#list(limit: nil, offset: nil, ordering: nil, status: nil, request_options: nil) ⇒ PaginatedDocumentIndexReadList

Used to retrieve a list of Document Indexes.

Parameters:

  • limit (Integer) (defaults to: nil)

    Number of results to return per page.

  • offset (Integer) (defaults to: nil)

    The initial index from which to return the results.

  • ordering (String) (defaults to: nil)

    Which field to use when ordering the results.

  • status (DOCUMENT_INDEXES_LIST_REQUEST_STATUS) (defaults to: nil)

    The current status of the document index

    • ‘ACTIVE` - Active

    • ‘ARCHIVED` - Archived

  • request_options (RequestOptions) (defaults to: nil)

Returns:



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/vellum_ai/document_indexes/client.rb', line 192

def list(limit: nil, offset: nil, ordering: nil, status: nil, request_options: nil)
  Async do
    response = @request_client.conn.get do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["X_API_KEY"] = request_options.api_key unless request_options&.api_key.nil?
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.params = {
        **(request_options&.additional_query_parameters || {}),
        "limit": limit,
        "offset": offset,
        "ordering": ordering,
        "status": status
      }.compact
      req.url "#{@request_client.default_environment[:Default]}/v1/document-indexes"
    end
    PaginatedDocumentIndexReadList.from_json(json_object: response.body)
  end
end

#partial_update(id:, label: nil, status: nil, environment: nil, request_options: nil) ⇒ DocumentIndexRead

Used to partial update a Document Index given its ID.

Parameters:

  • id (String)

    A UUID string identifying this document index.

  • label (String) (defaults to: nil)

    A human-readable label for the document index

  • status (ENTITY_STATUS) (defaults to: nil)

    The current status of the document index

    • ‘ACTIVE` - Active

    • ‘ARCHIVED` - Archived

  • environment (ENVIRONMENT_ENUM) (defaults to: nil)

    The environment this document index is used in

    • ‘DEVELOPMENT` - Development

    • ‘STAGING` - Staging

    • ‘PRODUCTION` - Production

  • request_options (RequestOptions) (defaults to: nil)

Returns:



325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/vellum_ai/document_indexes/client.rb', line 325

def partial_update(id:, label: nil, status: nil, environment: nil, request_options: nil)
  Async do
    response = @request_client.conn.patch do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["X_API_KEY"] = request_options.api_key unless request_options&.api_key.nil?
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.body = {
        **(request_options&.additional_body_parameters || {}),
        label: label,
        status: status,
        environment: environment
      }.compact
      req.url "#{@request_client.default_environment[:Default]}/v1/document-indexes/#{id}"
    end
    DocumentIndexRead.from_json(json_object: response.body)
  end
end

#retrieve(id:, request_options: nil) ⇒ DocumentIndexRead

Used to retrieve a Document Index given its ID or name.

Parameters:

  • id (String)

    Either the Document Index’s ID or its unique name

  • request_options (RequestOptions) (defaults to: nil)

Returns:



253
254
255
256
257
258
259
260
261
262
263
# File 'lib/vellum_ai/document_indexes/client.rb', line 253

def retrieve(id:, request_options: nil)
  Async do
    response = @request_client.conn.get do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["X_API_KEY"] = request_options.api_key unless request_options&.api_key.nil?
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.url "#{@request_client.default_environment[:Default]}/v1/document-indexes/#{id}"
    end
    DocumentIndexRead.from_json(json_object: response.body)
  end
end

#update(id:, label:, status: nil, environment: nil, request_options: nil) ⇒ DocumentIndexRead

Used to fully update a Document Index given its ID.

Parameters:

  • id (String)

    A UUID string identifying this document index.

  • label (String)

    A human-readable label for the document index

  • status (ENTITY_STATUS) (defaults to: nil)

    The current status of the document index

    • ‘ACTIVE` - Active

    • ‘ARCHIVED` - Archived

  • environment (ENVIRONMENT_ENUM) (defaults to: nil)

    The environment this document index is used in

    • ‘DEVELOPMENT` - Development

    • ‘STAGING` - Staging

    • ‘PRODUCTION` - Production

  • request_options (RequestOptions) (defaults to: nil)

Returns:



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/vellum_ai/document_indexes/client.rb', line 278

def update(id:, label:, status: nil, environment: nil, request_options: nil)
  Async do
    response = @request_client.conn.put do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["X_API_KEY"] = request_options.api_key unless request_options&.api_key.nil?
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.body = {
        **(request_options&.additional_body_parameters || {}),
        label: label,
        status: status,
        environment: environment
      }.compact
      req.url "#{@request_client.default_environment[:Default]}/v1/document-indexes/#{id}"
    end
    DocumentIndexRead.from_json(json_object: response.body)
  end
end