0

Replace the filter attributes of a corpus

by
Published Nov 5, 2024

Replace the filter attributes of a corpus. This does not happen immediately, but instead creates a job and will complete when that job completes. Until that job completes, using new filter attributes will not work. You can monitor the status of the filter change using the returned job ID. 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
 * Replace the filter attributes of a corpus
7
 * Replace the filter attributes of a corpus. This does not happen immediately, but
8
instead creates a job and will complete when that job completes. Until that
9
job completes, using new filter attributes will not work.
10

11
You can monitor the status of the filter change using the returned job ID. The 
12
`corpus_key` uniquely identifies the corpus. For more information, see 
13
[Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).
14

15
 */
16
export async function main(
17
	auth: Vectara,
18
	corpus_key: string,
19
	body: {
20
		filter_attributes: {
21
			name: string
22
			level: 'document' | 'part'
23
			description?: string
24
			indexed?: false | true
25
			type:
26
				| 'boolean'
27
				| 'integer'
28
				| 'real_number'
29
				| 'text'
30
				| 'list[integer]'
31
				| 'list[real_number]'
32
				| 'list[text]'
33
		}[]
34
	}
35
) {
36
	const url = new URL(`https://api.vectara.io/v2/corpora/${corpus_key}/replace_filter_attributes`)
37

38
	const response = await fetch(url, {
39
		method: 'POST',
40
		headers: {
41
			'Content-Type': 'application/json',
42
			'x-api-key': auth.apiKey
43
		},
44
		body: JSON.stringify(body)
45
	})
46
	if (!response.ok) {
47
		const text = await response.text()
48
		throw new Error(`${response.status} ${text}`)
49
	}
50
	return await response.json()
51
}
52