0

Create a corpus

by
Published Nov 5, 2024

Create a corpus, which is a container to store documents and associated metadata. This is where you create the unique `corpus_key` that identifies the corpus. The `corpus_key` can be custom-defined following your preferred naming convention, allowing you to easily manage the corpus's data and reference it in queries. 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
 * Create a corpus
7
 * Create a corpus, which is a container to store documents and associated metadata. This is where you 
8
create the unique `corpus_key` that identifies the corpus. The `corpus_key` can be custom-defined 
9
following your preferred naming convention, allowing you to easily manage the corpus's data and 
10
reference it in queries. For more information, see 
11
[Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).
12

13
 */
14
export async function main(
15
	auth: Vectara,
16
	body: {
17
		key: string
18
		name?: string
19
		description?: string
20
		queries_are_answers?: false | true
21
		documents_are_questions?: false | true
22
		encoder_id?: string
23
		encoder_name?: string
24
		filter_attributes?: {
25
			name: string
26
			level: 'document' | 'part'
27
			description?: string
28
			indexed?: false | true
29
			type:
30
				| 'boolean'
31
				| 'integer'
32
				| 'real_number'
33
				| 'text'
34
				| 'list[integer]'
35
				| 'list[real_number]'
36
				| 'list[text]'
37
		}[]
38
		custom_dimensions?: {
39
			name: string
40
			description?: string
41
			indexing_default?: number
42
			querying_default?: number
43
		}[]
44
	}
45
) {
46
	const url = new URL(`https://api.vectara.io/v2/corpora`)
47

48
	const response = await fetch(url, {
49
		method: 'POST',
50
		headers: {
51
			'Content-Type': 'application/json',
52
			'x-api-key': auth.apiKey
53
		},
54
		body: JSON.stringify(body)
55
	})
56
	if (!response.ok) {
57
		const text = await response.text()
58
		throw new Error(`${response.status} ${text}`)
59
	}
60
	return await response.json()
61
}
62