Pinecone.NET icon indicating copy to clipboard operation
Pinecone.NET copied to clipboard

Optimize vector values un-marshalling from Protobuf

Open neon-sunset opened this issue 2 years ago • 0 comments

Currently, we do vector values unmarshalling by taking out the underlying buffer from RepeatedField<float>. Because it's implemented in a list-like fashion, this means that it usually has Pow2 length. This is not ideal because this results in array re-allocation for the most common vector length being 1536.

This could be addressed by switching from float[] to Memory<float> or ReadOnlyMemory<float> for dense vector values and just slicing it to the necessary size. However, it does not work with LINQ without some workarounds and may seem like an advanced type for the developers coming from other languages and unfamiliar with C#.

A likely solution to this issue is writing a custom deserializer/unmarshaller for RepeatedField<T>.

neon-sunset avatar Jan 03 '24 19:01 neon-sunset