Skip to main content
The x-vec SDK is designed to be highly configurable. You can configure it via environment variables or by passing parameters directly to classes and methods.

Cryptography configuration

The SDK supports two production-ready homomorphic encryption schemes and one experimental scheme. Both PaillierClient 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.
Set DEVICE=gpu to activate the GPU backend once the compiled extension is in place. Paillier — standard Paillier encryption:
Paillier-Lookup — optimised Paillier variant using precomputed tables for faster encryption. Recommended for large collections:
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:
You can also pass an explicit 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:
When loading a context that was saved with KMS, reconstruct the provider from the stored encrypted DEK (EDEK):

Persisting and reloading

You can persist and reload the execution context:
Or store/load it remotely via XTrace:
Each 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:
To reconstruct a 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: