export type LexicalSimilarity = 'Bm25f' | 'Bm25fProximity'; export type TokenizerType = 'AsciiAlphabetic' | 'UnicodeAlphanumeric' | 'UnicodeAlphanumericFolded' | 'Whitespace' | 'WhitespaceLowercase' | 'UnicodeAlphanumericZH'; export type StemmerType = 'None' | 'Arabic' | 'Armenian' | 'Basque' | 'Catalan' | 'Czech' | 'Danish' | 'Dutch' | 'DutchPorter' | 'English' | 'Esperanto' | 'Estonian' | 'Finnish' | 'French' | 'German' | 'Greek' | 'Hindi' | 'Hungarian' | 'Indonesian' | 'Irish' | 'Italian' | 'Lithuanian' | 'Lovins' | 'Nepali' | 'Norwegian' | 'Persian' | 'Polish' | 'Porter' | 'Portuguese' | 'Romanian' | 'Russian' | 'Serbian' | 'Sesotho' | 'Spanish' | 'Swedish' | 'Tamil' | 'Turkish' | 'Ukrainian' | 'Yiddish'; export type StopwordType = 'None' | 'English' | 'German' | 'French' | 'Spanish' | {Custom: {terms: Array}}; export type FrequentwordType = 'None' | 'English' | 'German' | 'French' | 'Spanish' | {Custom: {terms: Array}}; export type DocumentCompression = 'None' | 'Lz4' | 'Snappy' | 'Zstd'; export type AccessType = 'Ram' | 'Mmap'; export type SpellingCorrection = {max_dictionary_edit_distance: number, term_length_threshold?: (Array | null) | undefined, count_threshold: number, max_dictionary_entries: number}; export type QueryCompletion = {max_completion_entries: number}; export type Clustering = 'None' | 'Auto' | {Fixed: number}; export type Model = 'PotionCode16MV2' | 'PotionBase32M' | 'PotionMultilingual128M' | 'PotionRetrieval32M' | 'PotionBase8M' | 'PotionBase4M' | 'PotionBase2M'; export type Quantization = 'ScalarQuantizationI8' | 'TurboQuantI8' | 'None'; export type Precision = 'None' | 'F32' | 'I8'; export type VectorSimilarity = 'Cosine' | 'Dot' | 'Euclidean'; export type Inference = {Model2Vec: {model: Model, chunk_size: number, quantization: Quantization}} | {Model2VecCustom: {path: string, chunk_size: number, quantization: Quantization}} | {External: {dimensions: number, precision: Precision, quantization: Quantization, similarity: VectorSimilarity}} | 'None'; export type IndexConfig = {name?: string | undefined, lexical_similarity?: LexicalSimilarity | undefined, tokenizer?: TokenizerType | undefined, stemmer?: StemmerType | undefined, stop_words?: StopwordType | undefined, frequent_words?: FrequentwordType | undefined, ngram_indexing?: number | undefined, document_compression?: DocumentCompression | undefined, access_type?: AccessType | undefined, spelling_correction?: (SpellingCorrection | null) | undefined, query_completion?: (QueryCompletion | null) | undefined, clustering?: Clustering | undefined, inference?: Inference | undefined}; export type FieldType = 'U8' | 'U16' | 'U32' | 'U64' | 'I8' | 'I16' | 'I32' | 'I64' | 'Timestamp' | 'F32' | 'F64' | 'Bool' | 'String16' | 'String32' | 'StringSet16' | 'StringSet32' | 'Point' | 'Text' | 'Json' | 'Binary'; export type SchemaField = {field: string, store?: boolean | undefined, index_lexical?: boolean | undefined, index_vector?: boolean | undefined, field_type?: FieldType | undefined, facet?: boolean | undefined, longest?: boolean | undefined, boost?: number | undefined, dictionary_source?: boolean | undefined, completion_source?: boolean | undefined}; export type Synonym = {terms: Array, multiway?: boolean | undefined}; export type CreateIndexRequest = {index_config: IndexConfig, schema: Array, synonyms?: Array | undefined}; export type CreateApiApiV1IndexArgs = {apikey: string, body: CreateIndexRequest}; export type CreateApiApiV1IndexOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create Index * * POST /api/v1/index */ export const createApiApiV1Index = async (args: CreateApiApiV1IndexArgs, options?: CreateApiApiV1IndexOptions) => { const {baseUrl = "http://127.0.0.1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "text/plain") if (args.apikey != null) headers.set("apikey", String(args.apikey)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/index${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };