@@ -5,6 +5,25 @@ import * as Core from '../core';
55import { GetDocumentInfoListCursor , type GetDocumentInfoListCursorParams } from '../pagination' ;
66
77export class Documents extends APIResource {
8+ /**
9+ * Updates a document. This endpoint is atomic.
10+ *
11+ * The only attribute currently supported for update is `metadata`. This endpoint
12+ * can only be called with a non-null `metadata` if the document status is
13+ * `indexed`.
14+ *
15+ * Sometimes, when updating a document, a new document ID will be assigned and the
16+ * previous will be deleted. For this reason, the previous and the new document ID
17+ * will both be returned in the response. If the document ID was not updated, then
18+ * these two IDs will be identical.
19+ *
20+ * A `404 Not Found` status code will be returned, if the provided collection name
21+ * or document path does not exist.
22+ */
23+ update ( body : DocumentUpdateParams , options ?: Core . RequestOptions ) : Core . APIPromise < DocumentUpdateResponse > {
24+ return this . _client . post ( '/documents/update-document' , { body, ...options } ) ;
25+ }
26+
827 /**
928 * Deletes a document
1029 *
@@ -86,6 +105,12 @@ export class Documents extends APIResource {
86105
87106export class DocumentGetInfoListResponsesGetDocumentInfoListCursor extends GetDocumentInfoListCursor < DocumentGetInfoListResponse > { }
88107
108+ export interface DocumentUpdateResponse {
109+ new_id : string ;
110+
111+ previous_id : string ;
112+ }
113+
89114export interface DocumentDeleteResponse {
90115 /**
91116 * This string will always be "Success!". This may change in the future.
@@ -110,7 +135,14 @@ export namespace DocumentGetInfoResponse {
110135
111136 collection_name : string ;
112137
113- index_status : 'parsing_failed' | 'not_parsed' | 'not_indexed' | 'indexing' | 'indexed' ;
138+ index_status :
139+ | 'not_parsed'
140+ | 'parsing'
141+ | 'not_indexed'
142+ | 'indexing'
143+ | 'indexed'
144+ | 'parsing_failed'
145+ | 'indexing_failed' ;
114146
115147 metadata : Record < string , string | Array < string > > ;
116148
@@ -135,7 +167,14 @@ export interface DocumentGetInfoListResponse {
135167
136168 collection_name : string ;
137169
138- index_status : 'parsing_failed' | 'not_parsed' | 'not_indexed' | 'indexing' | 'indexed' ;
170+ index_status :
171+ | 'not_parsed'
172+ | 'parsing'
173+ | 'not_indexed'
174+ | 'indexing'
175+ | 'indexed'
176+ | 'parsing_failed'
177+ | 'indexing_failed' ;
139178
140179 metadata : Record < string , string | Array < string > > ;
141180
@@ -162,6 +201,14 @@ export namespace DocumentGetPageInfoResponse {
162201 */
163202 collection_name : string ;
164203
204+ /**
205+ * A URL to an image of the page. This field will only be provided if the document
206+ * has finished parsing, and if it is a filetype that is capable of producing
207+ * images (e.g. PDF, DOCX, PPT, etc). In all other cases, this field will be
208+ * `null`.
209+ */
210+ image_url : string | null ;
211+
165212 /**
166213 * The specific page index of this page. Pages are 0-indexed, so that the 1st page
167214 * of a PDF is of page index 0.
@@ -179,18 +226,30 @@ export namespace DocumentGetPageInfoResponse {
179226 * will be set to `null`.
180227 */
181228 content ?: string | null ;
182-
183- /**
184- * An image of the page. This will be a base64-encoded string. Currently, this data
185- * is guaranteed to be a JPEG-encoded image. This field will only be provided if
186- * `include_image` was set to `true`, and the document has finished parsing. Also,
187- * the document must be a datatype that supports images (PDF, DOCX, PPT, but not
188- * .txt). In all other cases, this field will be `null`.
189- */
190- image_base64_data ?: string | null ;
191229 }
192230}
193231
232+ export interface DocumentUpdateParams {
233+ /**
234+ * The name of the collection.
235+ */
236+ collection_name : string ;
237+
238+ /**
239+ * The filepath of the document that you are updating. A `404 Not Found` status
240+ * code will be returned if no document with this path was found.
241+ */
242+ path : string ;
243+
244+ /**
245+ * If this field is provided, the given metadata json will replace the document's
246+ * existing metadata json. In other words, if you want to add a new field, you will
247+ * need to provide the entire metadata object (Both the original fields, and the
248+ * new field).
249+ */
250+ metadata ?: Record < string , string | Array < string > > | null ;
251+ }
252+
194253export interface DocumentDeleteParams {
195254 /**
196255 * The name of the collection.
@@ -343,30 +402,21 @@ export interface DocumentGetPageInfoParams {
343402 * rather than `null`. This string will contain the full contents of the page.
344403 */
345404 include_content ?: boolean ;
346-
347- /**
348- * If `true`, then the response will have the `image_base64_data` attribute be a
349- * `string`\*, rather than `null`. This string will contain the image data of the
350- * document, as a base64-encoded string. Currently, this data is guaranteed to be a
351- * JPEG-encoded image.
352- *
353- * \*Note that the response may still be `null`, if the page has no image data,
354- * such as if the document was uploaded with raw text rather than as a PDF.
355- */
356- include_image ?: boolean ;
357405}
358406
359407Documents . DocumentGetInfoListResponsesGetDocumentInfoListCursor =
360408 DocumentGetInfoListResponsesGetDocumentInfoListCursor ;
361409
362410export declare namespace Documents {
363411 export {
412+ type DocumentUpdateResponse as DocumentUpdateResponse ,
364413 type DocumentDeleteResponse as DocumentDeleteResponse ,
365414 type DocumentAddResponse as DocumentAddResponse ,
366415 type DocumentGetInfoResponse as DocumentGetInfoResponse ,
367416 type DocumentGetInfoListResponse as DocumentGetInfoListResponse ,
368417 type DocumentGetPageInfoResponse as DocumentGetPageInfoResponse ,
369418 DocumentGetInfoListResponsesGetDocumentInfoListCursor as DocumentGetInfoListResponsesGetDocumentInfoListCursor ,
419+ type DocumentUpdateParams as DocumentUpdateParams ,
370420 type DocumentDeleteParams as DocumentDeleteParams ,
371421 type DocumentAddParams as DocumentAddParams ,
372422 type DocumentGetInfoParams as DocumentGetInfoParams ,
0 commit comments