Cryptography configuration
The SDK supports two production-ready homomorphic encryption schemes and one experimental scheme. BothPaillierClient and PaillierLookupClient run on CPU by default.
GPU backend (internal testing phase). XTrace maintains a GPU-accelerated implementation of the homomorphic encryption layer that is approximately 20× faster than the CPU path for large embedding collections. It is available as a compiled extension that slots into the same
DEVICE=gpu switch — no application code changes required.The GPU implementation is not open-sourced at this time as it is under internal testing. Contact us at liwen@xtrace.ai if you are interested in access.DEVICE=gpu to activate the GPU backend once the compiled extension is in place.
Paillier — standard Paillier encryption:
embed_len must be strictly less than key_len. Use at least key_len=1024 for security, as it is the bit-length for the prime modulus.
Goldwasser-Micali (
xtrace_sdk.x_vec.crypto.goldwasser_micali_client) is included for research purposes and is experimental — it is not supported by DataLoader or Retriever and should not be used in production.Execution context configuration
ExecutionContext bundles the homomorphic client and AES encryption under a single key-provider-protected object. A key provider supplies the AES key used to encrypt the homomorphic secret key at rest. The SDK ships two providers:
PassphraseKeyProvider— derives a 256-bit AES key from a passphrase using scrypt.AWSKMSKeyProvider— envelope encryption via AWS KMS (the data encryption key is generated and wrapped by KMS and never persisted in plaintext).
The key provider encrypts the secret homomorphic key at rest. There is no way to recover it through the SDK — manage your passphrase or KMS key securely.
Passphrase key provider
The simplest option — derive an AES key from a passphrase:salt to PassphraseKeyProvider for additional key-derivation control.
AWS KMS key provider
For production workloads, use envelope encryption via AWS KMS. The data encryption key (DEK) is generated by KMS and never stored in plaintext:Persisting and reloading
You can persist and reload the execution context:ExecutionContext has a unique id attribute you can use to reference it later.
DataLoader configuration
DataLoader requires an execution context and an XTrace integration instance:
DataLoader from a saved execution context:
Retriever configuration
Retriever mirrors the DataLoader setup. Pass parallel=True to decode Hamming distances using multiprocessing (useful for large KBs):
Environment variables
The following environment variables are read automatically:| Variable | Description |
|---|---|
XTRACE_API_KEY | XTrace API key (used by XTraceIntegration when api_key is not passed explicitly). |
XTRACE_ORG_ID | Organisation ID (used by XTraceIntegration when org_id is not passed explicitly). |
XTRACE_API_URL | API base URL — defaults to https://api.production.xtrace.ai. |
XTRACE_EXECUTION_CONTEXT_PATH | Default path to a saved execution context. |
INFERENCE_API_KEY | API key for your inference provider (OpenAI, Redpill, etc.). |