Skip to content

Embeddings npyblock

github-actions[bot] edited this page Aug 29, 2026 · 1 revision

Development build. This page describes main, not a released package. The latest published Lodestar.Embeddings is 0.4.0 — read its documentation.

NpyBlock

A float block read from a .npy file, with the shape it was stored under.

public readonly record struct NpyBlock(ReadOnlyMemory<float> Values, IReadOnlyList<int> Shape)

ParametersValues are the elements in C order, so a matrix reads row by row. Shape has one entry for a vector and two for a matrix.

Example — the shape is the file's, not a guess.

using Lodestar.Embeddings.Persistence;

using var buffer = new MemoryStream();
NpyFile.Write(buffer, [1f, 2f, 3f, 4f, 5f, 6f], 2, 3);
buffer.Position = 0;

NpyBlock block = NpyFile.Read(buffer);
string shape = string.Join("x", block.Shape);   // => 2x3

RemarksValues is ReadOnlyMemory<float> rather than an array because the block is the file's content and not the caller's buffer to grow. .Span reads it without copying; .ToArray() takes a copy when one is wanted.

Shape is what the file declared and what the read was bounded against — the element count is checked before it sizes anything, which is the rule every loader here follows.

Applies to — net10.0, netstandard2.0.

See alsoNpyFile, NpyFile.Read, the persistence index.

Lodestar

Project

Clone this wiki locally