Class: Vellum::DocumentIndexesClient

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:) ⇒ DocumentIndexesClient

Parameters:



17
18
19
20
# File 'lib/vellum_ai/document_indexes/client.rb', line 17

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

Instance Attribute Details

#request_clientObject (readonly)

Returns the value of attribute request_client.



13
14
15
# File 'lib/vellum_ai/document_indexes/client.rb', line 13

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:



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/vellum_ai/document_indexes/client.rb', line 64

def create(label:, name:, indexing_config:, status: nil, environment: nil, copy_documents_from_index_id: nil,
           request_options: nil)
  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

#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)


133
134
135
136
137
138
139
140
# File 'lib/vellum_ai/document_indexes/client.rb', line 133

def destroy(id:, request_options: nil)
  @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

#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:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/vellum_ai/document_indexes/client.rb', line 32

def list(limit: nil, offset: nil, ordering: nil, status: nil, request_options: nil)
  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

#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:



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/vellum_ai/document_indexes/client.rb', line 155

def partial_update(id:, label: nil, status: nil, environment: nil, request_options: nil)
  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

#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:



89
90
91
92
93
94
95
96
97
# File 'lib/vellum_ai/document_indexes/client.rb', line 89

def retrieve(id:, request_options: nil)
  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

#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:



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/vellum_ai/document_indexes/client.rb', line 112

def update(id:, label:, status: nil, environment: nil, request_options: nil)
  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