-
Notifications
You must be signed in to change notification settings - Fork 0
Embeddings embeddingindex fromownedblock
Development build. This page describes
main, not a released package. The latest published Lodestar.Embeddings is 0.4.0 — read its documentation.
Builds an index that takes the block, without copying it.
public static EmbeddingIndex FromOwnedBlock(float[] block, int dimension, BlockNormalization normalization, IReadOnlyList<string> ids = null)Parameters — block is the vectors laid out row after row in C order, handed over rather than
lent: it becomes the index's backing store. Its length must be a multiple of dimension.
dimension is the length every vector has, at least 1. normalization says what is to be done
about the block and what the index's own normalization flag becomes —
BlockNormalization has the three answers, and Normalize rewrites
block in place. ids is one id per vector, or null for an anonymous index; it is copied, never
retained, which the block is not.
Returns — a new EmbeddingIndex holding block.Length / dimension vectors, backed by the very
array it was given.
Exceptions — ArgumentNullException when block is null. ArgumentOutOfRangeException when
dimension is below 1, or normalization is not one of the enum's values. ArgumentException
when block's length is not a multiple of dimension, or ids holds a number of entries other
than the vector count.
Example — the array is the index's now, and normalization is visible in it.
using Lodestar.Embeddings.Search;
float[] block = { 3f, 4f };
var index = EmbeddingIndex.FromOwnedBlock(block, dimension: 2, BlockNormalization.Normalize);
// The index took the array, so normalization happened in the caller's own values.
float first = block[0]; // => 0.6
int count = index.Count; // => 1Remarks — ownership transfers. The index reads this array for as long as it lives, so
three obligations move to the caller and stay there: do not write to it, do not return it to an
ArrayPool, and expect Normalize to change its values in place. None of the three can be
checked by the library, and a breach is silent — a returned array re-rented elsewhere becomes this
index's embeddings, and it goes on scoring queries against another renter's bytes without raising
anything.
EmbeddingIndex.FromBlock is the one to reach for unless that copy
has been measured and matters. It costs one pass over the block and asks nothing of the caller;
this saves the pass and asks for a permanent invariant.
Decision 0056
records why both ship rather than only the copying one: a caller holding a block from a model's
output, a memory-mapped file or a column store would otherwise have no way to avoid a copy the
library can see is unnecessary.
The array whose ownership is easiest to give up is one nobody else has ever held — the freshly
allocated block that NpyFile.Read returns is the shape this
exists for. That block is not yet reachable from here: NpyFile.Read hands it back as a
ReadOnlyMemory<float>, and there is no supported way from that back to the array. Closing that
gap is
decision 0055's
work.
A block holding NaN or an infinity is accepted here, exactly as Add
accepts one — the two ingest paths cannot disagree about what an index may hold. It is
Save that refuses it.
Applies to — net10.0, netstandard2.0.
See also — EmbeddingIndex.FromBlock,
BlockNormalization, EmbeddingIndex.Add,
EmbeddingIndex.
- 0001-target-framework
- 0002-unicode-comparison-unit
- 0003-provenance-and-licensing
- 0004-levenshtein-myers-backlog
- 0005-hamming-jellyfish-divergence
- 0006-ratcliff-autojunk
- 0007-metaphone-scope
- 0008-italian-enza-nltk-divergence
- 0009-sample-consumes-a-local-feed
- 0010-stop-word-list-provenance
- 0011-persistence-format
- 0012-per-package-versioning
- 0013-sentencepiece-parity-scope
- 0014-precompiled-normalizer
- 0015-sonar-rules-in-the-build
- 0016-metrics-package-placement
- 0017-bpe-parity-scope
- 0018-multiclass-roc-auc-parallelism-is-opt-in
- 0019-the-net-analysers-run-in-the-build-too
- 0020-normalize-is-a-projection-not-a-parameter
- 0021-multioutput-is-a-method-not-an-enum
- 0022-added-token-matching-flags
- 0023-byte-level-decode-substitutes
- 0024-weighted-median-averages-within-scikit-learns-epsilon
- 0025-quickselect-replaces-a-full-sort-for-the-median
- 0026-r2-and-explainedvariance-split-their-undefined-cases-differently
- 0027-r2-and-explainedvariance-vectorize-only-a-single-output
- 0028-log1p-is-kahans-identity-not-math-log-1-plus-x
- 0029-balanced-accuracy-adjusted-is-left-to-ieee-754-at-the-edge
- 0030-cohen-kappa-keeps-scikit-learns-expected-matrix-orientation
- 0031-nosamplecorrect-mirrors-numpys-float64-upcast
- 0032-fbeta-substitutes-tp-predicted-and-support-algebraically
- 0033-compensated-sum-is-neumaiers-variant
- 0034-dropout-is-refused-for-want-of-a-user
- 0035-a-null-pre-split-is-removed-with-invert-not-isolated
- 0036-a-member-may-ship-without-an-oracle-if-it-says-so
- 0037-the-guards-run-before-the-commit
- 0038-the-gate-confronts-an-exception-tag-with-the-page-that-documents-it
- 0039-mutual-information-returns-zero-on-an-empty-input
- 0040-a-curve-is-a-sealed-class-per-curve
- 0041-one-sample-file-per-public-class
- 0042-phonetic-encoders-refuse-a-null-word
- 0043-the-equality-table-is-sized-to-the-pattern
- 0044-compression-belongs-to-the-caller
- 0045-a-console-call-carries-its-reason-on-the-line
- 0046-check-adr-immutable-runs-in-ci-only
- 0047-one-gate-per-kernel-not-one-per-alphabet
- 0048-the-gate-depends-on-the-kernel-and-the-alphabet
- 0049-two-gates-per-kernel-tested-where-the-width-is-known
- 0050-the-sentencepiece-bpe-lineage-stays-a-bpe-model
- 0051-the-save-paths-cost-is-the-buffer-not-the-encoding
- 0052-pre-sizing-the-artifact-file-buys-nothing-on-a-delayed-allocation-filesystem
- 0053-the-payload-buffer-is-not-pooled-because-residency-outlives-the-load
- 0054-the-payload-buffer-is-pooled-after-all-because-the-collection-is-the-cost
- 0055-the-artifact-gets-a-binary-sidecar-once-a-block-can-be-ingested-whole
- 0056-a-block-may-be-adopted-and-the-invariant-is-the-callers-to-keep
- benchmark_latest
- decisions
- equivalence
- matplotlib
- migration
- nightly_run
- numpy
- pandas
- performance
- pytorch
- seaborn
- sklearn
- statsmodels