0

Update a corpus

by
Published Nov 5, 2024

Enable, disable, or update the name and description of a corpus. This lets you manage data availability without deleting the corpus, which is useful for maintenance and security purposes. The `corpus_key` uniquely identifies the corpus. For more information, see [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition). Update the name and description of a corpus dynamically to help keep your data aligned with changing business needs.

Script vectara Verified

The script

Submitted by hugo697 Bun
Verified 581 days ago
1
//native
2
type Vectara = {
3
	apiKey: string
4
}
5
/**
6
 * Update a corpus
7
 * Enable, disable, or update the name and description of a corpus. This lets you
8
manage data availability without deleting the corpus, which is useful for 
9
maintenance and security purposes. The `corpus_key` uniquely identifies the corpus. 
10
For more information, see [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition). 
11
Update the name and description of a corpus dynamically to help keep your data 
12
aligned with changing business needs.
13

14
 */
15
export async function main(
16
	auth: Vectara,
17
	corpus_key: string,
18
	body: { enabled?: false | true; name?: string; description?: string }
19
) {
20
	const url = new URL(`https://api.vectara.io/v2/corpora/${corpus_key}`)
21

22
	const response = await fetch(url, {
23
		method: 'PATCH',
24
		headers: {
25
			'Content-Type': 'application/json',
26
			'x-api-key': auth.apiKey
27
		},
28
		body: JSON.stringify(body)
29
	})
30
	if (!response.ok) {
31
		const text = await response.text()
32
		throw new Error(`${response.status} ${text}`)
33
	}
34
	return await response.json()
35
}
36