How To: Execute Query

Executing a query allows an end-user to interact securely with an AI model on the LatticaAI platform. This guide explains how to submit an encrypted query using the Query Client.

Prerequisites

  1. Encrypted Message: The input message must be encrypted using the Secret Key in the Query Client.

  2. User Access Token: The user must have a valid Access Token, specific to the AI model being queried. Tokens are validated by LatticaAI during the query process.


Use the following code snippet to execute the query. Provide the User Access Token and the encrypted message as parameters:

import lattica_common.app_api as agent_app
​
# Notice your query token expires in 30 days
query_token = "the_query_token_you_got_using_the_generate_user_token"

# user_data is a tuple of: 
# (serialized_context, serialized_secret_key, serialized_homseq)
# which you need for encrypting the query and querying the model
user_data = agent_app.user.query_offline_phase(query_token)

dataset = pd.read_csv('data/mnist_data.csv').values / 255
data = torch.tensor(dataset[0])
serialized_ct = agent_app.user.encrypt(user_data, dataset)

serialized_ct_res = agent_app.user.apply_hom_pipeline(serialized_ct)

Process the Response

  • If the query is successful, the result will be returned as an encrypted response.

  • Decrypt the response using your Secret Key to obtain the result.

This step focuses on a specific part of the query process: Query Execution. If you prefer to perform encryption, query execution, and decryption in a single command, refer to [How-To: Encrypt, Execute, and Decrypt in One Step].

Last updated

Was this helpful?