Create Predicate Index
Creates a predicate index in the AI service to optimize filtered embedding queries. Speeds up retrieval of embeddings based on metadata constraints, improving the performance of get_pred operations.
Source Code Exampleβ
Click to expand
use ahnlich_client_rs::ai::AiClient;
use ahnlich_client_rs::error::AhnlichError;
use ahnlich_types::ai::query::CreatePredIndex;
use ahnlich_types::ai::server::CreateIndex;
#[tokio::main]
async fn main() -> Result<(), AhnlichError> {
// Connect to the AI service
let ai_client = AiClient::new("http://127.0.0.1:1370".to_string())
.await
.expect("Failed to connect AI client");
// Define which store and which predicates to index
let params = CreatePredIndex {
store: "Deven Kicks".to_string(),
predicates: vec!["Brand".to_string(), "Vintage".to_string()],
};
// Call the API
let response: CreateIndex = ai_client.create_pred_index(params, None).await?;
println!(" Created predicate indexes: {:?}", response);
Ok(())
}
Parametersβ
-
params: CreatePredIndexβ Specifies the store and the metadata fields to index for predicate-based queries. -
tracing_id: Option<String>β Optional trace parent ID for observability and distributed tracing.
Returnsβ
-
Ok(CreateIndex)β Confirmation that the predicate index was successfully created, along with 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
CreatePredIndexinput in atonic::Request. -
Adds optional tracing metadata.
-
Calls the AI/DB serviceβs
create_pred_indexRPC endpoint. -
Waits for the response and extracts the index creation result.
-
Returns the newly created index information.