Skip to content

Embedding Models API

OGXEmbeddingModel

OGXEmbeddingModel(client: OgxClient, model_id: str, params: dict | OGXEmbeddingParams | None = None)

Bases: BaseEmbeddingModel[OgxClient, OGXEmbeddingParams]

Creates embeddings for OGX client.

Source code in ai4rag/rag/embedding/ogx.py
def __init__(self, client: OgxClient, model_id: str, params: dict | OGXEmbeddingParams | None = None):
    super().__init__(client=client, model_id=model_id, params=params)

Attributes

params property writable

params: OGXEmbeddingParams

Get model params.

Functions

embed_documents

embed_documents(texts: list[str]) -> list[list[float]]

Embeds given list of strings. The maximum batch size supported is 2048 chunks, hence we need to do it iteratively.

Parameters:

  • texts (list[str]) –

    List of text-like chunks.

Returns:

  • list[list[float]]

    Embeddings made from the list of texts.

Source code in ai4rag/rag/embedding/ogx.py
def embed_documents(self, texts: list[str]) -> list[list[float]]:
    """Embeds given list of strings.
    The maximum batch size supported is 2048 chunks,
    hence we need to do it iteratively.

    Parameters
    ----------
    texts : list[str]
        List of text-like chunks.

    Returns
    -------
    list[list[float]]
        Embeddings made from the list of texts.
    """
    resp = []
    for idx in range(0, len(texts), self._BATCH_SIZE):
        resp.extend(self._embed_text(text_input=texts[idx : idx + self._BATCH_SIZE]))

    return resp

embed_query

embed_query(query: str) -> list[float]

Embeds given query.

Parameters:

  • query (str) –

    Single text-like chunk.

Returns:

  • list[]

    Embeddings made from a single text.

Source code in ai4rag/rag/embedding/ogx.py
def embed_query(self, query: str) -> list[float]:
    """Embeds given query.

    Parameters
    ----------
    query : str
        Single text-like chunk.

    Returns
    -------
    list[]
        Embeddings made from a single text.
    """
    return self._embed_text(text_input=query)[0]