0

Retrieve metadata about a corpus

by
Published Nov 5, 2024

Get metadata about a corpus. This operation is not a method of searching a corpus. Specify the `corpus_key` to identify the corpus whose metadata you want to retrieve. The `corpus_key` is created when the corpus is set up, either through the Vectara Console UI or the Create Corpus API. 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
 * Retrieve metadata about a corpus
7
 * Get metadata about a corpus. This operation is not a method of searching a corpus. 
8
Specify the `corpus_key` to identify the corpus whose metadata you want to 
9
retrieve. The `corpus_key` is created when the corpus is set up, either through
10
the Vectara Console UI or the Create Corpus API. For more information, 
11
see [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).
12

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

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