Add an embedding model#
Make a model usable for embedding and shared retrieval, from a pack.
Two things connect a model. An embedding adapter turns a request into the body a model
endpoint expects. A retrieval model supplies the recipes, preparers and encoder that the
shared retrieval pipeline runs. The Nemotron pack (packs/nemotron/) does both for text
and images; the Clay pack (packs/clay/) does both for Sentinel-2 tensors.
Embedding and retrieval shows where they sit in the flow.
Prerequisites#
A pack. See Write a pack.
A model endpoint reachable through a configured inference gateway, and an
EmbeddingProfileentry for it (see below).
Steps#
Write the adapter. A request adapter has one method:
class MyAdapter: def body(self, profile, values, *, is_query, images): return { "model": profile.model_id, "input": values, "input_type": "query" if is_query else "passage", }
packs/nemotron/adapter.pyis the complete small example. A locally hosted model can add attributes the service reads:gpu_modelandgpu_labelfor GPU admission,unavailable_reason(settings),validate_profile(profile)and the transport (protocol,path,timeout) used bypacks/clay/adapter.py.Register it in
part.pyunder a unique name:registry.add_embedding_adapter("my-model", _adapter)
Add a profile that names the adapter. Profiles live in the deployment’s
embedding-models.yaml(deploy/configs/embedding-models.yaml):profiles: - id: my-model name: My model model_id: vendor/my-model model_identity: vendor/my-model model_revision: v1 preprocessing_revision: my-model-v1 dimension: 1024 input_types: [text, image] adapter: my-model gateway_id: my-gateway
Model identity, revision, preprocessing and dimension together define the embedding space. Equal dimensions never make two models compatible.
For shared retrieval, write the retrieval model module and register it:
registry.add_retrieval_model( "mymodel", "geonemo.packs.mypack.retrieval", settings=_settings )
The module provides these names (see
PartRegistry.add_retrieval_model):Name
Meaning
contribute(runtime, products, **settings, budget)Returns
(profile, recipe, preparer, encoder_type, output)tuplesCONTENT_QUERY_SCHEMASRecipe output schemas that accept content queries; empty if none
check_arguments(**settings)Optional. Raises
ValueErrorfor settings it cannot useA preparer implements
prepare(source, content, recipe)and yieldsPreparedInputitems. An encoder implementsencode(inputs, space, *, role)and returns one vector per input (knowledge/embedding_retrieval/ports.py).contributeshould check the profile against the model’s pinned identity and refuse a mismatch, aspacks/nemotron/retrieval.pydoes.Add the model’s settings.
settings()returns a pydantic model whose fields are keys of the retrieval configuration file, each named<model>_<setting>. A model is enabled by<model>_profile_id. Nemotron’s arenemotron_profile_id,nemotron_text_chunk_charsandnemotron_raster.Test offline with a fake provider transport and the in-memory registry. See
packs/nemotron/tests/test_nemotron_retrieval_composition.py.
Add a preparer to an existing model#
A preparer changes how sources become model inputs without a new model. A new recipe gives a
new embedding space. Nemotron’s optional text chunking (nemotron_text_chunk_chars) and
native TIFF windows (nemotron_raster) are examples: each is another entry returned from
contribute, selected by its own setting, with its recipe identity covering every
parameter. Changing a parameter creates a different space and never reinterprets old
vectors.
Result#
With the pack in the parts list and the profile configured, the model appears in
client.retrieval.contracts() as a space. Embedding jobs and searches use it through the
normal retrieval API. See Server settings for the configuration keys.