0

Remove all documents and data in a corpus

by
Published Nov 5, 2024

Resets a corpus, which removes all documents and data from the specified corpus, while keeping the corpus itself. 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
 * Remove all documents and data in a corpus
7
 * Resets a corpus, which removes all documents and data from the specified corpus, 
8
while keeping the corpus itself. The `corpus_key` uniquely identifies the corpus. 
9
For more information, see [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).
10

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

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