Hyperplane.Cider
0.1.26
dotnet add package Hyperplane.Cider --version 0.1.26
NuGet\Install-Package Hyperplane.Cider -Version 0.1.26
<PackageReference Include="Hyperplane.Cider" Version="0.1.26" />
<PackageVersion Include="Hyperplane.Cider" Version="0.1.26" />
<PackageReference Include="Hyperplane.Cider" />
paket add Hyperplane.Cider --version 0.1.26
#r "nuget: Hyperplane.Cider, 0.1.26"
#:package Hyperplane.Cider@0.1.26
#addin nuget:?package=Hyperplane.Cider&version=0.1.26
#tool nuget:?package=Hyperplane.Cider&version=0.1.26
Hyperplane.Cider
Optional reader adapter for Hyperplane.NET: CiderEmbedder turns any
Cider.NET IEmbeddingBackend — including Cider.Native's in-process llama.cpp
LlamaEmbedder over GGUF models — into a Hyperplane IEmbedder, so a DecisionService can answer questions over raw
text without a Python reader.
Quick start (G#)
import Hyperplane
import Hyperplane.Cider
// Loads a GGUF file (or a local Ollama model name) in-process; the embedder owns and disposes the model.
using let reader = CiderEmbedder.FromGguf("/models/Qwen3-Embedding-0.6B-Q8_0.gguf")
let service = DecisionService(embedder: reader) // heuristic head sized to the reader's dimensions
Console.WriteLine(reader.Profile.Id) // experimental:cider/<digest>/last
For an explicitly configured device, for example with a compatible EmbeddingGemma 2 GGUF:
import Cider.Native
import Hyperplane.Cider
let device = LlamaDeviceOptions.ExplicitGpu("Vulkan1")
using let reader = CiderEmbedder.FromGguf("/models/embeddinggemma-2-BF16.gguf", device: device, assertVenn1: true)
let vectors = reader.Embed([]string{"A short example."})
Replace Vulkan1 with a device reported by LlamaRuntime.Devices() on your system. Explicit configuration
ignores ambient Cider configuration, requires an absolute GGUF path, and fails rather than silently falling back
to CPU. Use LlamaDeviceOptions.ExplicitCpu() for explicit CPU placement; see Cider.Native for CUDA and
other options. If device is supplied, its GpuLayers takes precedence over nGpuLayers. Without device,
the existing nGpuLayers and environment-driven selection remain unchanged. The backend and device in
ReaderIdentity describe actual placement, not the requested options.
The runnable example
accepts the GGUF path as its argument.
Any other backend works too: CiderEmbedder(backend) wraps an existing IEmbeddingBackend (for example a shared
LlamaCppBackend) without taking ownership unless ownsBackend: true. Ownership transfers on constructor
entry: validation/probe failures dispose an owned backend exactly once, but never dispose a borrowed backend.
FromGguf transfers ownership through the same path.
Profiles: honest by default
Vectors are only comparable within one profile. By default the profile is derived from Cider's EmbeddingProvenance
(discovered by embedding one probe text, or passed explicitly):
| Field | Value |
|---|---|
Id |
experimental:cider/<digest>/<pooling> (override with profileId:, which must start with experimental:) |
Reader |
cider/<digest>, independent of the model path or name |
Revision |
first 40 hex digits of the model's SHA-256 digest (SHA-256 of the digest when it is not hex) |
Dimensions |
the backend's embedding dimensions |
Prompt |
promptName:, else the promptPrefix:, else none |
Every batch is checked against the pinned provenance (model digest, pooling, dimensions) and every row against the
profile's dimensions (ContractError codes reader_provenance, reader_rows, reader_dimensions); rows must
be finite and nonzero (non_finite_vector, zero_vector) and are returned L2-normalized. Explicit provenance
must identify immutable model weights with a nonempty digest and a resolved pooling mode, not Auto;
omit provenance to probe the backend. Derived profile dimensions are 1..16384.
SHA-256 digests compare independent of hex case or an optional sha256: prefix; opaque digests compare
as case-sensitive strings after trimming. Supplied native provenance is checked against the probe, whose
actual provenance is retained. Generic backends with supplied provenance remain unprobed until embedding.
The profile is not the actual reader. ReaderIdentity separately records the full model digest, resolved
pooling, dimensions, actual native backend and device(s), GPU layer count, context, batch size, truncation,
literal prompt prefix and special-token setting. For non-SHA-256 opaque backend digests the field is the
SHA-256 of that opaque value. It never uses the model path. assertVenn1 changes the asserted profile, not
the identity, and does not establish parity with the PyTorch reader.
FromGguf knows its batch size. With an explicitly constructed LlamaEmbedder, the nine-argument
CiderEmbedder constructor accepts nativeBatchSize as a caller assertion matching the native nBatch.
The original constructor leaves batch size unknown; Cider does not expose it. Packed native readers
therefore require the explicit nativeBatchSize assertion or FromGguf with a positive nCtx:
different native batch budgets can change truncation and must not share calibrated profiles.
Cap-1 construction retains its existing behavior. Other Cider backends and
native default-device selection can also leave backend/device unknown. Unknown fields are null and
complete is false, never inferred from an asserted profile. A supplied native provenance is probed and
checked. Identity does not guarantee bit-identical output across driver or native-library versions.
Text-fitted families persist the reader identity in their v3 identity and report; it describes only text
embedded by the service, not caller-supplied vectors in mixed or vector-only training. This includes regression
families fitted from text indexes; the index retains its original reader identity, and its handle binds that
identity. App-owned outcome stores do not provide reader provenance. Native answers and index streams report
the identity for embedded state, question, option or index text, including prepared question references;
Decisions API answers put it in hyperplane and venn. Descriptive text alongside a supplied vector is not
treated as embedded. Model metadata describes the configured reader even for vector input. Existing v1/v2 families remain readable; old
families bound to path-based experimental profiles need their original profile or a refit. Serving does
not enforce identity matching: compare the stored family reader with the active reader before using text.
Both Embed and EmbedAsync forward cancellation tokens, check cancellation before/after backend work,
and check disposal even for empty batches.
Context limits
FromGguf(..., truncateToContext: true) defaults to context truncation, matching Venn's bounded-token reader.
Set it to false for strict rejection; context overflow becomes ContractError("reader_context"), not an
unhandled server error. The constructor otherwise preserves the supplied EmbeddingOptions truncation
policy. Pin the context size, truncation policy and prompt consistently across producers of one profile:
truncation does not establish exact parity with SentenceTransformers. DecisionService separately bounds
each input text to 1..32768 UTF-16 code units.
EmbedWithInfo / EmbedWithInfoAsync return EmbeddingRow values with Vector and optional Info.
With published Cider 0.1.34, Info.TokenCount is the original token count including the
configured prompt prefix and special tokens, before truncation; Info.Truncated reports whether tokens
were actually removed. Both information APIs make one batch request and consume ordered RowTokens
from that exact evaluation. Row count, nonnegative original/effective counts, effective ⇐ original,
and aggregate effective token totals are validated (reader_tokens). No context-limit or aggregate-only
heuristics are used. Cancellation is forwarded and checked before returning any result.
If RowTokens is nil, a native LlamaEmbedder falls back to literal per-row tokenization and
single-row evaluation to recover exact truncation metadata. Other backends retain the already computed
vectors with unknown (nil) information, even if they implement token counting: their aggregate totals
do not prove per-row truncation. Strict mode rejects oversized native inputs rather than returning a truncated row. Cider
retains the head of truncated inputs; tail-preserving policies are not provided here.
DecisionService uses the information-aware API when available. Native answer rows include token_count
and truncated when known; translated Decisions API answers put them in hyperplane and venn.
For plural states, per-row answers include their own information, and the enclosing answer's truncated
means at least one row was truncated (omitted if no row is known truncated and some are unknown).
Question and option text is not attributed to the state. Numeric states and unknown readers omit these
fields rather than claiming false.
CachedEmbedder.Embed and EmbedAsync use the inner vector-only batch APIs. Information requests refresh
vector-only cache hits when the reader can provide information, retaining the newly computed vector with
its information. New vector-only entries use .vector files; information-bearing entries are stored
atomically in separate information-category files. In memory, each key retains only the best
vector-and-info pair, preferring a known truncation warning, then more complete information; it never
combines fields from different vectors. This can leave a token count unreported when only another vector
has that count. A complete truncation warning is the highest priority and can be served without disk
reads; lower-priority information hits check higher-priority categories for updates from another instance.
Legacy generic files are checked by header before reading their vector, with both read from one file handle.
Existing .embedding, .embedding-partial and vector-only .f32 entries remain readable;
vector-only entries are refreshed when possible and otherwise remain unknown. Concurrent processes using
this version and the same cache directory preserve distinct information categories without a shared lock,
using atomic same-directory replacement for each file. This requires a filesystem with atomic rename
and coherent file visibility; network filesystems and concurrent writers from older versions are not
covered. Generic Cider backends can now supply row metadata, so information requests check vector-only
entries once. Unknown results are remembered in memory, but a new cache
instance may retry it because the on-disk entry cannot establish another reader's capabilities.
Complete reader identities use a separate, configuration-bound cache key; old profile-only entries are
not reused. An incomplete or unavailable identity uses memory only by default. For legacy custom
readers without an identity, the four-argument CachedEmbedder constructor can opt into old profile-only
disk keys with allowLegacyProfileKeys: true, but the caller must isolate configurations and trust the
profile. This opt-in never enables disk caching for an explicitly incomplete identity.
The native integration test is opt-in: set HYPERPLANE_TEST_GGUF to a local embedding GGUF and run
dotnet test test/Hyperplane.Tests/Hyperplane.Tests.gsproj --filter FullyQualifiedName~CiderEmbedderTests.
Native packing (experimental, explicitly opt-in)
Metadata batching does not enable native multi-sequence packing. The default remains
maxSequencesPerBatch: 1, with the existing single-sequence representations and profiles.
To evaluate isolated sequences together where Cider supports it:
import Cider.Native
import Hyperplane
import Hyperplane.Cider
using let reader = CiderEmbedder.FromGguf(
"/models/embeddinggemma-2-BF16.gguf",
device: LlamaDeviceOptions.ExplicitGpu("Vulkan1"),
maxSequencesPerBatch: 8
)
// Dispose the wrapper before the reader; the wrapper never owns the reader.
using let batched = CoalescingEmbedder(reader, maximumBatchSize: 8, delayMilliseconds: 1)
let service = DecisionService(embedder: batched)
// Route ALL access to this reader through this wrapper, including other services.
The constructor also accepts EmbeddingOptions.MaxSequencesPerBatch. When wrapping a LlamaEmbedder,
use the nine-argument constructor with its actual nativeBatchSize; omitting it is rejected for packing.
Values must be 1..64; 8–16
is a starting point, not a performance guarantee. Cider limits groups to the native context/batch/micro-batch
token budget, preserves order and sequence isolation, and evaluates unsupported models one row at a time.
Encoder-decoder embedding models remain unsupported, not a fallback. Consult the native backend's
SupportsMultiSequenceEvaluation; reader.NativeEvaluations counts cumulative reported native calls
(zero can mean unavailable), allowing rows/native-call measurements rather than assuming packing occurred.
Packed vectors are numerically close, not bit-identical. Opt-in configurations use separate
experimental:cider/packed/... profile ids, readers and revisions, binding the requested cap and actual
reader identity (runtime, device, context, prompt, special tokens, truncation). Even custom profileId
values are configuration-bound; packed/unpacked cache keys and calibrated families must not be shared.
Packing cannot be combined with assertVenn1. If native capability changes after initialization (for example
a backend rejects packing), the adapter fails closed with reader_provenance: recreate the reader under
the resulting capability before using new vectors. A requested cap on an initially unsupported runtime
remains a separate experimental profile.
IReaderValidation exposes this live validity check; CachedEmbedder and CoalescingEmbedder forward it
and validate before returning rows, including cache hits and empty reads. Cached data cannot bypass
capability drift or disposal. Custom wrappers must forward the optional check rather than hiding it.
Hardware-backed coverage here is Linux x64 BF16 EmbeddingGemma-2 on CPU and RTX 4060 Laptop Vulkan: mixed short/overlong/context-boundary/empty-prefixed rows, ordered metadata, sync/async cosine >= 0.995, pre-cancellation, interrupted multi-row work and subsequent recovery. Fake-backend tests and packed-library JIT/NativeAOT parity cover managed contracts; they do not establish native safety on CUDA, Metal, other models, quantizations or operating systems. Native changes cross a process-aborting boundary: validate your model/runtime before opting in. See actual end-to-end throughput measurements.
Asserting venn-1 (opt-in)
assertVenn1: true reports the pinned venn-1 profile (google/embeddinggemma-2, 768 dimensions, Classification
prompt — exact prefix task: classification | query: ) so the vectors can be scored by the
published venn-1 head and mixed with venn-1 vectors from other readers. Only opt in deliberately: GGUF / llama.cpp
embeddings (quantization, kernels, tokenizer and pooling differences) are not bit-identical to the PyTorch
sentence-transformers reader that defines venn-1, so decisions can drift near thresholds. The backend must produce
768-dimensional vectors with a nonempty model digest. A supplied prefix must equal Venn1PromptPrefix and
a supplied prompt name must equal Classification; arbitrary prompt overrides cannot claim the pinned profile.
An actual BF16 GGUF-versus-PyTorch measurement, its fixed inputs and reproduction commands are documented
here. That small CPU
measurement is not evidence that other quantizations, devices, texts or decisions have the same drift.
Native runtime
FromGguf uses Cider.Native 0.1.34, which needs libllama. Explicitly reference
Cider.Native.Runtime.<rid> version 0.1.34 for each deployed RID (linux-x64, linux-arm64,
linux-musl-*, win-x64, win-arm64, osx-*): automatic transitive download can be missed on the first
restore, and a warning is not evidence of a matching runtime. This repository's native tests and throughput
harness explicitly download the matching host runtime. See Cider.Native's README to supply your own build
(CiderUseBundledLlamaRuntime=false); explicit device configuration ignores CIDER_LLAMA_LIB, so set
LlamaDeviceOptions.NativeLibraryPath / ExtraBackendPaths instead.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Cider.Native (>= 0.1.34)
- Cider.NET (>= 0.1.34)
- Hyperplane.NET (>= 0.1.26)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.