langchain_community.embeddings.openvino.OpenVINOBgeEmbeddings

class langchain_community.embeddings.openvino.OpenVINOBgeEmbeddings[source]

Bases: OpenVINOEmbeddings

OpenVNO BGE embedding models.

Bge Example:
from langchain_community.embeddings import OpenVINOBgeEmbeddings

model_name = "BAAI/bge-large-en"
model_kwargs = {'device': 'CPU'}
encode_kwargs = {'normalize_embeddings': True}
ov = OpenVINOBgeEmbeddings(
    model_name_or_path=model_name,
    model_kwargs=model_kwargs,
    encode_kwargs=encode_kwargs
)

Initialize the sentence_transformer.

param embed_instruction: str = ''

Instruction to use for embedding document.

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 query_instruction: str = 'Represent this question for searching relevant passages: '

Instruction to use for embedding query.

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]) –

Return type

List[List[float]]

async aembed_query(text: str) List[float]

Asynchronous Embed query text.

Parameters

text (str) –

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

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
Parameters

model_path (str) –

Return type

bool

Examples using OpenVINOBgeEmbeddings