For example, if I encrypt {1,2,3,4,5} with a ciphertext ct, do I have to unpack and repack if I want to add a {6} to the encrypted {1,2,3,4,5,6}?
As long as your batch_size is large enough to accommodate the extra elements you want to add (in the example you gave, to encode the first ciphertext you need batch_size >= 8, so there is no problem to add up to three elements afterwards), you can encrypt {0,0,0,0,0,6} in a ciphertext and add it to the ciphertext ct encrypting {1,2,3,4,5}. If ct doesn’t encode zeroes after 5, then you need to first multiplicatively mask it by {1,1,1,1,1,0,0…}. Finally, if the length of the vector you want to obtain is larger than the currently set batch_size, you need to change the batch_size in order to accomodate this length, which is done by multiplicative masks and rotations.
Thank you for your answer! That’s a perspective I didn’t think of. I was stuck on a method similar to vector’s push_back() function.
You have to think in terms of SIMD, a single instruction that is performed on all the data in the vector at the same time. the one exception is when we rotate the vector, there we shift ALL elements in the vector to the left or right (by all I mean all the elements based on the ringsize, not the elements you have encoded (usually the rest of the elements are zeroed out when encoding).
The context of my question is the INSERT statement in a database, where new elements are constantly being inserted and CKKS is chosen to pack all the elements to control the size of the ciphertext.
Understood. point is, if you want to insert at the end of the list, @andreea.alexandru has told you the best way. Inserting in the middle of the list (vs. replacement) would require you to perform several vector operations, i.e. mask to obtain a vector with just the items before the new element,
add the new element to the end of that vector, rotate and mask the original vector to get all the elements after the new element and add that to your new vector. This takes multiplicative depth btw. so after a few of these operations, you probably need to bootstrap.
yeap, multiplicative depth,it’s a problem