Skip to content

why does GenerateEmbeddingsAsync return IList<ReadOnlyMemory<TEmbedding>> ? #8622

Closed Answered by westey-m
markat1 asked this question in Q&A
Discussion options

You must be logged in to vote

@markat1, ReadOnlyMemory<T> is used in .net to work more efficiently with large blocks of data, like in the case of vectors.

E.g. it's possible to create views over the data without needing to create a new instance / copy of the data, avoiding potentially expensive allocations. You can read more about the benefits and usage here:
https://learn.microsoft.com/en-us/dotnet/standard/memory-and-spans/

Other vector related .net APIs consume ReadOnlySpan<T> as input, which is interrelated with ReadOnlyMemory<T> and can be accessed as a property on ReadOnlyMemory<T>.
See e.g. the TensorPrimitives.CosineSimilarity method:
https://learn.microsoft.com/en-us/dotnet/api/system.numerics.tensors.tensorp…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by sophialagerkranspandey
Comment options

You must be logged in to vote
1 reply
@westey-m
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants