0

Delete a corpus and all its data

by
Published Nov 5, 2024

Delete a corpus and all the data that it contains. 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).

Script vectara Verified

The script

Submitted by hugo697 Bun
Verified 581 days ago
1
//native
2
type Vectara = {
3
	apiKey: string
4
}
5
/**
6
 * Delete a corpus and all its data
7
 * Delete a corpus and all the data that it contains. The `corpus_key` uniquely identifies 
8
the corpus. For more information, see [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).
9

10
 */
11
export async function main(auth: Vectara, corpus_key: string) {
12
	const url = new URL(`https://api.vectara.io/v2/corpora/${corpus_key}`)
13

14
	const response = await fetch(url, {
15
		method: 'DELETE',
16
		headers: {
17
			'x-api-key': auth.apiKey
18
		},
19
		body: undefined
20
	})
21
	if (!response.ok) {
22
		const text = await response.text()
23
		throw new Error(`${response.status} ${text}`)
24
	}
25
	return await response.text()
26
}
27