Interface: Embedder
Defined in: internal/embedder/Embedder.ts:55
Embedder -- text to vector, with the one embedding model of the platform
About
The same ruler for write and read: what is stored and what is searched are measured alike.
Implements IEmbedder: a thin class over LLMClient.embed that batches the texts (batchSize per call), keeps the
order and checks that the model returned one vector per text, each of dimensions numbers; a vector of another length
cannot be compared with the ones in the index. Exposes embeddingModelId and dimensions, so the VectorStore and the
KbIngestor can check the index against them.
The embedding model is a platform setting, not a tenant choice: vectors of different models are not comparable, and changing it means re-ingesting every knowledge base.
Who needs it
KbIngestor.ingestDocument (embed, write side) and KbRetriever.retrieve (embedOne, read side);
KbIngestor.checkIndex reads embeddingModelId and dimensions. A host replaces it with its own IEmbedder in
overrides.embedder.
What needs
llmClient for the provider call.
Usage
When to use it
Always, through the gateway: createGatewayDeps creates it from IAIGatewayConfig.embedder.
When shouldn't use it
A host with its own embedding service implements IEmbedder and passes it in overrides; it must report the same
dimensions as its index.
Pitfalls
embeddingModelId must be a model with caps.embeddings in the ModelRegistry, else every call is a 400 from the
LLMClient. dimensions is not verified against the model at construction: a wrong value is found on the first call
(error 5372630367840).
Implements
Accessors
dimensions
Get Signature
get dimensions():
number
Defined in: internal/embedder/Embedder.ts:168
dimensions -- the length of every vector this embedder produces
About
The ruler's length.
The configured dimensions, as the index must have been created with.
Who needs it
KbIngestor.checkIndex, compared with VectorStore.describeIndex before every ingest.
Returns
number
Implementation of
IEmbedder.dimensions
embeddingModelId
Get Signature
get embeddingModelId():
string
Defined in: internal/embedder/Embedder.ts:185
embeddingModelId -- the model every vector comes from
About
Written with every record, so the index can refuse a vector of another model.
The configured embeddingModelId.
Who needs it
KbIngestor.ingestDocument, on every IChunkRecord it writes; KbIngestor.checkIndex, compared with the index.
Returns
string
Implementation of
IEmbedder.embeddingModelId
Methods
embed()
embed(
__namedParameters):Promise<number[][]>
Defined in: internal/embedder/Embedder.ts:81
embed -- the vectors of many texts
About
One vector per text, in the same order, all of the same length.
Sends the texts in batches of batchSize to LLMClient.embed, one call after the other, and returns the vectors in
the order of the texts. Throws when a batch comes back with another number of vectors than texts (error
5372630367606, a 502) or with a vector of another length than dimensions (error 5372630367840, a 500).
Who needs it
KbIngestor.ingestDocument, for the chunks of one document (heading path and text together); embedOne.
Pitfalls
A failing batch stops the call; the vectors of the earlier batches are lost, nothing is written. Every batch is one usage-guard check and one trace of kind EMBED.
Parameters
__namedParameters
meta
For the usage adapter and the trace; kind = EMBED.
texts
string[]
Returns
Promise<number[][]>
Implementation of
IEmbedder.embed
embedOne()
embedOne(
__namedParameters):Promise<number[]>
Defined in: internal/embedder/Embedder.ts:139
embedOne -- the vector of one text
About
The query side of
embed.
embed with one text; returns its vector.
Who needs it
KbRetriever.retrieve, for the rewritten query of every call with a knowledge base.
Parameters
__namedParameters
meta
text
string
Returns
Promise<number[]>
Implementation of
IEmbedder.embedOne