DeterministicEmbeddingClient
Models & Types · AiDotNet.Agentic.Embeddings
A hashing embedding client that contacts nothing and returns the same vector for the same text forever.
Implements: IEmbeddingClient
For Beginners
Use this wherever you want the embedding path to run without paying a provider: in tests, in a demo, or while you are still deciding which model to buy. It turns text into numbers using simple arithmetic on the words themselves, so similar text still gets similar numbers, and the same text always gets exactly the same numbers.
How It Works
Every token of the input is hashed with FNV-1a into a bucket and a sign, and the bucket counts become the vector — the classic hashing-trick bag of tokens. That makes it a genuine similarity model rather than a stub: two texts sharing most of their tokens produce vectors with a high cosine similarity, and two unrelated texts do not, so an embedding-gated code path can be exercised end to end with no provider, no key, and no network. It is not a semantic model: it cannot tell that two differently-worded programs do the same thing.
The hash is computed here rather than taken from GetHashCode, whose string implementation is
randomized per process on modern frameworks, so results are stable across processes, machines, and target
frameworks — which is what makes a test written against it reproducible.
Constructors
| Constructor | Summary |
|---|---|
DeterministicEmbeddingClient(int dimensions, string modelId) |
Initializes a deterministic client. |
Properties
| Property | Summary |
|---|---|
int Dimensions { get; } |
Gets the length of every vector this client produces. |
long Calls { get; } |
Gets how many batches this client has answered. |
long TextsEmbedded { get; } |
Gets how many individual texts this client has embedded. |
string ModelId { get; } |
Methods
| Method | Summary |
|---|---|
EmbeddingVector Embed(string text) |
Computes the vector this client would return for one text. |
ValueTask<EmbeddingBatch> EmbedAsync(IReadOnlyList<string> texts, CancellationToken cancellationToken) |
Fields
| Field | Summary |
|---|---|
int DefaultDimensions |
The default number of components in a produced vector. |
string DefaultModelId |
The model identifier reported when none is supplied. |