OpenVINOEmbeddings#

class langchain_community.embeddings.openvino.OpenVINOEmbeddings[source]#

Bases: BaseModel, Embeddings

OpenVINO embedding models.

Example

from langchain_community.embeddings import OpenVINOEmbeddings

model_name = "sentence-transformers/all-mpnet-base-v2"
model_kwargs = {'device': 'CPU'}
encode_kwargs = {'normalize_embeddings': True}
ov = OpenVINOEmbeddings(
    model_name_or_path=model_name,
    model_kwargs=model_kwargs,
    encode_kwargs=encode_kwargs
)

Initialize the sentence_transformer.

param encode_kwargs: Dict[str, Any] [Optional]#

Keyword arguments to pass when calling the encode method of the model.

param model_kwargs: Dict[str, Any] [Optional]#

Keyword arguments to pass to the model.

param model_name_or_path: str [Required]#

HuggingFace model id.

param ov_model: Any = None#

OpenVINO model object.

param show_progress: bool = False#

Whether to show a progress bar.

param tokenizer: Any = None#

Tokenizer for embedding 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]) List[List[float]][source]#

Compute doc embeddings using a HuggingFace transformer model.

Parameters:

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

Returns:

List of embeddings, one for each text.

Return type:

List[List[float]]

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

Compute query embeddings using a HuggingFace transformer model.

Parameters:

text (str) – The text to embed.

Returns:

Embeddings for the text.

Return type:

List[float]

encode(sentences: Any, batch_size: int = 4, show_progress_bar: bool = False, convert_to_numpy: bool = True, convert_to_tensor: bool = False, mean_pooling: bool = False, normalize_embeddings: bool = True) Any[source]#

Computes sentence embeddings.

Parameters:
  • sentences (Any) – the sentences to embed.

  • batch_size (int) – the batch size used for the computation.

  • show_progress_bar (bool) – Whether to output a progress bar.

  • convert_to_numpy (bool) – Whether the output should be a list of numpy vectors.

  • convert_to_tensor (bool) – Whether the output should be one large tensor.

  • mean_pooling (bool) – Whether to pool returned vectors.

  • normalize_embeddings (bool) – Whether to normalize returned vectors.

Returns:

By default, a 2d numpy array with shape [num_inputs, output_dimension].

Return type:

Any

save_model(model_path: str) bool[source]#
Parameters:

model_path (str)

Return type:

bool

Examples using OpenVINOEmbeddings