/*
* Hotdata API
*
* Powerful data platform API for instant databases, queries, and analytics.
*
* The version of the OpenAPI document: 1.0.0
* Contact: developers@hotdata.dev
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
/// CreateIndexRequest : Request body for POST .../indexes One constraint spans the whole table rather than this request alone: a vector index that generates its own embeddings — that is, one created with `embedding_provider_id` — has to be the only index on its table. So a table that already carries any index (sorted, full-text, or vector) will not accept an embedding-backed vector index, and a table that already carries an embedding-backed vector index will not accept any further index of any type. To move between the two arrangements, drop what is there first. Plan for it when designing a table: combining full-text search with generated embeddings on one table is not possible, so use a separate table for the second index, or supply the embeddings yourself. A vector index over a column that already holds vectors — no `embedding_provider_id` — is not affected and coexists with other indexes normally. Embedding generation also rewrites the table to add its generated column, and that rewrite cannot preserve a declared partition or sort order. An embedding-backed vector index is therefore refused on a table declaring either.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct CreateIndexRequest {
/// When true, create the index as a background job and return a job ID for polling.
#[serde(rename = "async", skip_serializing_if = "Option::is_none")]
pub r#async: Option<bool>,
/// If set (requires `async` = true), wait up to this many milliseconds for the index build to finish: if it completes in time the index is returned (201), otherwise a 202 with a job ID to poll. Must be between 1000 and the server maximum; a value out of that range, or set without `async` = true, is rejected with 400.
#[serde(
rename = "async_after_ms",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub async_after_ms: Option<Option<i32>>,
/// Columns to index. Required for all index types.
#[serde(rename = "columns")]
pub columns: Vec<String>,
/// User-facing description of the embedding (e.g., \"product descriptions\").
#[serde(
rename = "description",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub description: Option<Option<String>>,
/// Output vector dimensions. Some models support multiple dimension sizes (e.g., OpenAI text-embedding-3-small supports 512 or 1536). If omitted, the model's default dimensions are used
#[serde(
rename = "dimensions",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub dimensions: Option<Option<i32>>,
/// Embedding provider ID. When set for a vector index, the source column is treated as text and embeddings are generated automatically. The vector index is then built on the generated embedding column (`{column}_embedding` by default).
#[serde(
rename = "embedding_provider_id",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub embedding_provider_id: Option<Option<String>>,
#[serde(rename = "index_name")]
pub index_name: String,
/// Index type. `sorted` supports range queries, `bm25` full-text search, and `vector` similarity search.
#[serde(rename = "index_type", skip_serializing_if = "Option::is_none")]
pub index_type: Option<IndexType>,
/// Distance metric for vector indexes: \"l2\", \"cosine\", or \"dot\". When omitted, defaults to \"l2\" for float array columns or the provider's preferred metric for text columns with auto-embedding.
#[serde(
rename = "metric",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub metric: Option<Option<String>>,
/// Custom name for the generated embedding column. Defaults to `{column}_embedding`.
#[serde(
rename = "output_column",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub output_column: Option<Option<String>>,
}
impl CreateIndexRequest {
/// Request body for POST .../indexes One constraint spans the whole table rather than this request alone: a vector index that generates its own embeddings — that is, one created with `embedding_provider_id` — has to be the only index on its table. So a table that already carries any index (sorted, full-text, or vector) will not accept an embedding-backed vector index, and a table that already carries an embedding-backed vector index will not accept any further index of any type. To move between the two arrangements, drop what is there first. Plan for it when designing a table: combining full-text search with generated embeddings on one table is not possible, so use a separate table for the second index, or supply the embeddings yourself. A vector index over a column that already holds vectors — no `embedding_provider_id` — is not affected and coexists with other indexes normally. Embedding generation also rewrites the table to add its generated column, and that rewrite cannot preserve a declared partition or sort order. An embedding-backed vector index is therefore refused on a table declaring either.
pub fn new(columns: Vec<String>, index_name: String) -> CreateIndexRequest {
CreateIndexRequest {
r#async: None,
async_after_ms: None,
columns,
description: None,
dimensions: None,
embedding_provider_id: None,
index_name,
index_type: None,
metric: None,
output_column: None,
}
}
}
/// Index type. `sorted` supports range queries, `bm25` full-text search, and `vector` similarity search.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum IndexType {
#[serde(rename = "sorted")]
Sorted,
#[serde(rename = "bm25")]
Bm25,
#[serde(rename = "vector")]
Vector,
}
impl Default for IndexType {
fn default() -> IndexType {
Self::Sorted
}
}