Skip to content

Embedding Models API

LSEmbeddingModel

LSEmbeddingModel(client: LlamaStackClient, model_id: str, params: dict | LSEmbeddingParams | None = None)

Bases: BaseEmbeddingModel[LlamaStackClient, LSEmbeddingParams]

Creates embeddings for LLamaStack client.

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

Attributes

params property writable

params: LSEmbeddingParams

Get model params.

Functions

embed_documents

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

Embeds given list of strings. For llama-stack 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/llama_stack.py
def embed_documents(self, texts: list[str]) -> list[list[float]]:
    """Embeds given list of strings.
    For llama-stack 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), 2048):
        resp.extend(self._embed_text(text_input=texts[idx : idx + 2048]))

    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/llama_stack.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]