Create Predicate Index
Creates an index on a predicate field in a store. Predicate indexes allow efficient filtering and retrieval of vectors based on metadata conditions, improving query performance for repeated predicate lookups.
Source Code Exampleβ
Click to expand
use ahnlich_client_rs::db::DbClient;
use ahnlich_types::db::query::CreatePredIndex;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// connect to DB server
let db_client = DbClient::new("127.0.0.1:1369".to_string()).await?;
let tracing_id: Option<String> = None;
// Create predicate index request
let params = CreatePredIndex {
store: "Main".to_string(),
predicates: vec!["role = 'admin'".to_string()], // <-- must be Vec<String>
};
// Call the client
match db_client.create_pred_index(params, tracing_id).await {
Ok(result) => {
println!("Created predicate index: {:?}", result);
}
Err(err) => {
eprintln!("Error creating predicate index: {:?}", err);
}
}
Ok(())
}
Parametersβ
params: CreatePredIndexβ Defines the target store and the predicate field to be indexed.
Returnsβ
-
CreateIndexβ Response confirming that the index has been successfully created. -
AhnlichErrorβ Returned if the store does not exist, the field is invalid, or index creation fails.
Behaviorβ
-
Wraps the provided
CreatePredIndexparameters into a gRPC request. -
Adds optional tracing metadata to the request for debugging or monitoring.
-
Invokes the
create_pred_indexRPC on the Ahnlich server via the cloned gRPC client. -
Awaits the serverβs response and extracts the
CreateIndexresult using.into_inner().