LatticaAI Documentation
  • Welcome to LatticaAI
  • Conceptual Guide
  • Architecture Overview
    • Management Client
    • Query Client
  • Platform Workflows
    • Account Management
    • Model Management
    • User Access Management
    • Query Submission
    • Credit Management
    • Worker Management
  • How-To Guides
    • Client Installation
      • How-To: Install Management Client
      • How-To: Install Query Client
    • Model Lifecycle
      • How-To: Deploy AI model
      • How-To: Modify AI Model Settings
    • Access Control
      • How-To: Create User Access Token
      • How-To: Modify User Access Token Setting
      • How-To: Remove Token's Assignment
      • How-To: Assign Token to Model
      • How-To: See List of Tokens
    • Resource Management
      • How-To: Start Worker
      • How-To: Stop Worker
      • How-To: Monitor Worker Performance
    • Secure Query Processing
      • How To: Upload Evaluation Key
      • How-To: Encrypt Input Message
      • How To: Execute Query
      • How-To: Decrypt Output Data
      • How-To: Encrypt, Execute, and Decrypt in One Step
    • Account and Finance Operations
      • How-To: View Payment Transaction History
      • How-To: Update Account Information
      • How-To: View Credit Balance and Add Credit to Your Account
      • How-To: Monitor Balance and Usage
  • Demo Tutorials
    • Image Sharpening with LatticaAI Demo Tutorial
    • Sentiment Analysis with LatticaAI Demo Tutorial
    • Health Analysis with LatticaAI Demo Tutorial
    • Digit Recognition with LatticaAI Demo Tutorial
    • Zooming Into Each Step of Demo Run with LatticaAI flow
Powered by GitBook
On this page
  • Prerequisites
  • Executing a Query in One Command

Was this helpful?

  1. How-To Guides
  2. Secure Query Processing

How-To: Encrypt, Execute, and Decrypt in One Step

PreviousHow-To: Decrypt Output DataNextAccount and Finance Operations

Last updated 2 months ago

Was this helpful?

LatticaAI provides a streamlined way to perform end-to-end query execution in a single command using our SDK. Instead of calling separate functions for encryption, query submission, and decryption, this method allows users to provide an input and receive the decrypted output in one step.

This functionality is available in both Python and TypeScript SDKs.


Prerequisites

Before executing a complete query, ensure that:

  1. A valid User Access Token is available, provided by the AI Provider for a specific model.

  2. An Evaluation Key (EVK) is generated and published to the LatticaAI backend.

    • See: [How-To: ]


Executing a Query in One Command

Use the following code snippet to encrypt the input message. The encryption process takes the User Access Token and the message to be encrypted as parameters:

import torch
import matplotlib.pyplot as plt
from lattica_query.lattica_query_client import QueryClient

# Authenticate
client = QueryClient("user_token_from_lattica_console")

# Generate keys and upload the evaluation key to the server.
(
    context,
    secret_key,
    client_blocks,
) = client.generate_key()


# Run multiple encrypted queries
image1 = plt.imread('image1.png')
pt1 = torch.Tensor(image1)
result1 = client.run_query(context, secret_key, pt1, client_blocks)

image2 = plt.imread('image2.png')
pt2 = torch.Tensor(image2)
result2 = client.run_query(context, secret_key, pt2, client_blocks)
import { LatticaQueryClient, imageToTensor } from '@Lattica-ai/lattica-query-client';

// Authenticate
const client = new LatticaQueryClient("user_token_from_lattica_console");

// Generate keys and upload the evaluation key to the server.
await client.init();

// Run multiple encrypted queries
const pt1 = await imageToTensor(imageDataUrl1);
const res1 = await client.runQuery(pt1);

const pt2 = await imageToTensor(imageDataUrl2);
const res2 = await client.runQuery(pt2);
Upload Evaluation Key