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 EmbeddingProfile entry for it (see below).

Steps#

  1. 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.py is the complete small example. A locally hosted model can add attributes the service reads: gpu_model and gpu_label for GPU admission, unavailable_reason(settings), validate_profile(profile) and the transport (protocol, path, timeout) used by packs/clay/adapter.py.

  2. Register it in part.py under a unique name:

    registry.add_embedding_adapter("my-model", _adapter)
    
  3. 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.

  4. 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) tuples

    CONTENT_QUERY_SCHEMAS

    Recipe output schemas that accept content queries; empty if none

    check_arguments(**settings)

    Optional. Raises ValueError for settings it cannot use

    A preparer implements prepare(source, content, recipe) and yields PreparedInput items. An encoder implements encode(inputs, space, *, role) and returns one vector per input (knowledge/embedding_retrieval/ports.py). contribute should check the profile against the model’s pinned identity and refuse a mismatch, as packs/nemotron/retrieval.py does.

  5. 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 are nemotron_profile_id, nemotron_text_chunk_chars and nemotron_raster.

  6. 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.