Skip to main content

Create Non-Linear Algorithm Index

Schema

This request accepts an optional schema field. When it is omitted, the server uses the public schema. Set schema to target a store in another schema.

Creates a non-linear algorithm index on a vector store within the AI service to optimize similarity search performance. These indexes (HNSW) accelerate nearest-neighbor and semantic searches over large embedding datasets, making retrieval faster and more efficient.

Each index type is specified using a NonLinearIndex message with a HnswConfig.

Source Code Example

Click to expand
Rust
use ahnlich_client_rs::ai::AiClient;
use ahnlich_types::ai::query::CreateNonLinearAlgorithmIndex;
use ahnlich_types::algorithm::nonlinear::{NonLinearIndex, non_linear_index, HnswConfig};
use tokio;


#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = AiClient::new("http://127.0.0.1:1370".to_string()).await?;

// Create an HNSW index (with default config)
let params = CreateNonLinearAlgorithmIndex {
store: "MyStore".to_string(),
schema: Some("analytics".to_string()),
non_linear_indices: vec![
NonLinearIndex {
index: Some(non_linear_index::Index::Hnsw(HnswConfig::default())),
},
],
};

let result = client.create_non_linear_algorithm_index(params, None).await?;
println!("Created non-linear indices: {:?}", result);

Ok(())
}

Parameters

  • params: CreateNonLinearAlgorithmIndex — Specifies the target store and algorithm parameters for building the non-linear index.

Returns

  • Ok(CreateIndex) — Confirmation that the non-linear algorithm index was successfully created, including index details.

  • Err(AhnlichError) — Returned if index creation fails due to invalid parameters, store issues, or server errors.

Behavior (explains the code, brief)

  • Wraps the CreateNonLinearAlgorithmIndex input in a tonic::Request.

  • Attaches tracing metadata if provided.

  • Calls the AI service’s create_non_linear_algorithm_index RPC endpoint.

  • Awaits the response and extracts the result.

  • Returns a CreateIndex object with details of the created index.