Class: Vellum::AsyncDocumentsClient
- Inherits:
-
Object
- Object
- Vellum::AsyncDocumentsClient
- Defined in:
- lib/vellum_ai/documents/client.rb
Instance Attribute Summary collapse
-
#request_client ⇒ Object
readonly
Returns the value of attribute request_client.
Instance Method Summary collapse
- #destroy(id:, request_options: nil) ⇒ Void
- #initialize(request_client:) ⇒ AsyncDocumentsClient constructor
-
#list(document_index_id: nil, limit: nil, offset: nil, ordering: nil, request_options: nil) ⇒ PaginatedSlimDocumentList
Used to list documents.
-
#partial_update(id:, label: nil, status: nil, metadata: nil, request_options: nil) ⇒ DocumentRead
Update a Document, keying off of its Vellum-generated ID.
-
#upload(label:, contents:, add_to_index_names: nil, external_id: nil, keywords: nil, metadata: nil, request_options: nil) ⇒ UploadDocumentResponse
Upload a document to be indexed and used for search.
Constructor Details
#initialize(request_client:) ⇒ AsyncDocumentsClient
130 131 132 133 |
# File 'lib/vellum_ai/documents/client.rb', line 130 def initialize(request_client:) # @type [AsyncRequestClient] @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ Object (readonly)
Returns the value of attribute request_client.
126 127 128 |
# File 'lib/vellum_ai/documents/client.rb', line 126 def request_client @request_client end |
Instance Method Details
#destroy(id:, request_options: nil) ⇒ Void
165 166 167 168 169 170 171 172 173 174 |
# File 'lib/vellum_ai/documents/client.rb', line 165 def destroy(id:, request_options: nil) Async do @request_client.conn.delete do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["X_API_KEY"] = .api_key unless &.api_key.nil? req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.url "#{@request_client.default_environment[:Default]}/v1/documents/#{id}" end end end |
#list(document_index_id: nil, limit: nil, offset: nil, ordering: nil, request_options: nil) ⇒ PaginatedSlimDocumentList
Used to list documents. Optionally filter on supported fields.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/vellum_ai/documents/client.rb', line 143 def list(document_index_id: nil, limit: nil, offset: nil, ordering: nil, request_options: nil) Async do response = @request_client.conn.get do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["X_API_KEY"] = .api_key unless &.api_key.nil? req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.params = { **(&.additional_query_parameters || {}), "document_index_id": document_index_id, "limit": limit, "offset": offset, "ordering": ordering }.compact req.url "#{@request_client.default_environment[:Default]}/v1/documents" end PaginatedSlimDocumentList.from_json(json_object: response.body) end end |
#partial_update(id:, label: nil, status: nil, metadata: nil, request_options: nil) ⇒ DocumentRead
Update a Document, keying off of its Vellum-generated ID. Particularly useful for updating its metadata.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/vellum_ai/documents/client.rb', line 185 def partial_update(id:, label: nil, status: nil, metadata: nil, request_options: nil) Async do response = @request_client.conn.patch do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["X_API_KEY"] = .api_key unless &.api_key.nil? req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.body = { **(&.additional_body_parameters || {}), label: label, status: status, metadata: }.compact req.url "#{@request_client.default_environment[:Default]}/v1/documents/#{id}" end DocumentRead.from_json(json_object: response.body) end end |
#upload(label:, contents:, add_to_index_names: nil, external_id: nil, keywords: nil, metadata: nil, request_options: nil) ⇒ UploadDocumentResponse
Upload a document to be indexed and used for search.
Note: Uses a base url of ‘documents.vellum.ai`.
This is a multipart/form-data request. The ‘contents` field should be a file upload. It also expects a JSON body with the following fields:
-
‘add_to_index_names: list` - Optionally include the names of all indexes that you’d like this document to be included in
-
‘external_id: str | None` - Optionally include an external ID for this document. This is useful if you want to re-upload the same document later when its contents change and would like it to be re-indexed.
-
‘label: str` - A human-friendly name for this document. Typically the filename.
-
‘keywords: list | None` - Optionally include a list of keywords that’ll be associated with this document. Used when performing keyword searches.
-
‘metadata: dict[str, Any]` - A stringified JSON object containing any metadata associated with the document that you’d like to filter upon later.
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/vellum_ai/documents/client.rb', line 223 def upload(label:, contents:, add_to_index_names: nil, external_id: nil, keywords: nil, metadata: nil, request_options: nil) Async do response = @request_client.conn.post do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["X_API_KEY"] = .api_key unless &.api_key.nil? req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.body = { **(&.additional_body_parameters || {}), add_to_index_names: add_to_index_names, external_id: external_id, label: label, contents: FileUtilities.as_faraday_multipart(file_like: contents), keywords: keywords, metadata: }.compact req.url "#{@request_client.default_environment[:Documents]}/v1/upload-document" end UploadDocumentResponse.from_json(json_object: response.body) end end |