//native
type Vectara = {
apiKey: string
}
/**
* Add a document to a corpus
* Add a document to a corpus. You can add documents that are either in a typical structured format,
or in a format that explicitly specifies each document part. Each part becomes a separate search result.
*/
export async function main(
auth: Vectara,
corpus_key: string,
body:
| {
id: string
type: string
metadata?: {}
document_parts: {
text: string
metadata?: {}
context?: string
custom_dimensions?: {}
}[]
}
| {
id: string
type: string
title?: string
description?: string
metadata?: {}
custom_dimensions?: {}
sections: {
id?: number
title?: string
text: string
metadata?: {}
sections?: {}[]
}[]
}
) {
const url = new URL(`https://api.vectara.io/v2/corpora/${corpus_key}/documents`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': auth.apiKey
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 581 days ago