SambaStudioEmbeddings#

class langchain_community.embeddings.sambanova.SambaStudioEmbeddings[source]#

Bases: BaseModel, Embeddings

SambaNova embedding models.

To use, you should have the environment variables SAMBASTUDIO_EMBEDDINGS_BASE_URL, SAMBASTUDIO_EMBEDDINGS_BASE_URI SAMBASTUDIO_EMBEDDINGS_PROJECT_ID, SAMBASTUDIO_EMBEDDINGS_ENDPOINT_ID, SAMBASTUDIO_EMBEDDINGS_API_KEY set with your personal sambastudio variable or pass it as a named parameter to the constructor.

Example

from langchain_community.embeddings import SambaStudioEmbeddings

embeddings = SambaStudioEmbeddings(sambastudio_embeddings_base_url=base_url,
                              sambastudio_embeddings_base_uri=base_uri,
                              sambastudio_embeddings_project_id=project_id,
                              sambastudio_embeddings_endpoint_id=endpoint_id,
                              sambastudio_embeddings_api_key=api_key,
                              batch_size=32)
(or)

embeddings = SambaStudioEmbeddings(batch_size=32)

(or)

# CoE example
embeddings = SambaStudioEmbeddings(
    batch_size=1,
    model_kwargs={
        'select_expert':'e5-mistral-7b-instruct'
    }
)

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

param batch_size: int = 32#

Batch size for the embedding models

param model_kwargs: dict = {}#

Key word arguments to pass to the model.

param sambastudio_embeddings_api_key: str = ''#

sambastudio api key

param sambastudio_embeddings_base_uri: str = ''#

endpoint base uri

param sambastudio_embeddings_base_url: str = ''#

Base url to use

param sambastudio_embeddings_endpoint_id: str = ''#

endpoint id on sambastudio for model

param sambastudio_embeddings_project_id: str = ''#

Project id on sambastudio for model

async aembed_documents(texts: list[str]) list[list[float]]#

Asynchronous Embed search docs.

Parameters:

texts (list[str]) – List of text to embed.

Returns:

List of embeddings.

Return type:

list[list[float]]

async aembed_query(text: str) list[float]#

Asynchronous Embed query text.

Parameters:

text (str) – Text to embed.

Returns:

Embedding.

Return type:

list[float]

embed_documents(texts: List[str], batch_size: int | None = None) List[List[float]][source]#

Returns a list of embeddings for the given sentences. :param texts: List of texts to encode :type texts: List[str] :param batch_size: Batch size for the encoding :type batch_size: int

Returns:

List of embeddings for the given sentences

Return type:

List[np.ndarray] or List[tensor]

Parameters:
  • texts (List[str])

  • batch_size (int | None)

embed_query(text: str) List[float][source]#

Returns a list of embeddings for the given sentences. :param sentences: List of sentences to encode :type sentences: List[str]

Returns:

List of embeddings for the given sentences

Return type:

List[np.ndarray] or List[tensor]

Parameters:

text (str)

classmethod validate_environment(values: Dict) Dict[source]#

Validate that api key and python package exists in environment.

Parameters:

values (Dict)

Return type:

Dict

Examples using SambaStudioEmbeddings