# Sentence Embedding with Azure OpenAI *author: David*
## Description A sentence embedding operator generates one embedding vector in ndarray for each input text. The embedding represents the semantic information of the whole input text as one vector. This operator is implemented with embedding models from [OpenAI](https://platform.openai.com/docs/guides/embeddings). This operator is designed specifically for Azure OpenAI, get more information from [link](https://learn.microsoft.com/en-us/azure/ai-services/openai/tutorials/embeddings?tabs=command-line)
## Code Example Use the pre-trained model '' to generate an embedding for the sentence "Hello, world.". *Write a pipeline with explicit inputs/outputs name specifications:* ```python from towhee import pipe, ops, DataCollection p = ( pipe.input('text') .map('text', 'vec', ops.sentence_embedding.azure_openai(model_name='text-embedding-ada-002', api_key=api_key, api_base=api_base)) .output('text', 'vec') ) DataCollection(p('Hello, world.')).show() ```
## Factory Constructor Create the operator via the following factory method: ***sentence_embedding.azure_openai(model_name='text-embedding-ada-002')*** **Parameters:** ***model_name***: *str* The model name in string, defaults to 'text-embedding-ada-002'. Supported model names: - text-embedding-ada-002 - text-similarity-davinci-001 - text-similarity-curie-001 - text-similarity-babbage-001 - text-similarity-ada-001 ***api_type***: *str='azure'* The OpenAI type in string, defaults to 'azure'. ***api_version***: *str='2023-07-01-preview'* The OpenAI version in string, defaults to '2023-07-01-preview'. ***api_key***: *str=None* The OpenAI API key in string, defaults to None. ***api_base***: *str=None* The OpenAI base in string, defaults to None.
## Interface The operator takes a piece of text in string as input. It returns a text emabedding in numpy.ndarray. ***\_\_call\_\_(txt)*** **Parameters:** ***text***: *str* ​ The text in string. **Returns**: *numpy.ndarray or list* ​ The text embedding extracted by model.
***supported_model_names()*** Get a list of supported model names. # More Resources - [All-Mpnet-Base-V2: Enhancing Sentence Embedding with AI - Zilliz blog](https://zilliz.com/learn/all-mpnet-base-v2-enhancing-sentence-embedding-with-ai): Delve into one of the deep learning models that has played a significant role in the development of sentence embedding: MPNet. - [The guide to text-embedding-ada-002 model | OpenAI](https://zilliz.com/ai-models/text-embedding-ada-002): text-embedding-ada-002: OpenAI's legacy text embedding model; average price/performance compared to text-embedding-3-large and text-embedding-3-small. - [OpenAI text-embedding-3-large | Zilliz](https://zilliz.com/ai-models/text-embedding-3-large): Building GenAI applications with text-embedding-3-large model and Zilliz Cloud / Milvus - [Mastering Text Similarity Search with Vectors in Zilliz Cloud - Zilliz blog](https://zilliz.com/learn/mastering-text-similarity-search-with-vectors-in-zilliz-cloud): We explore the fundamentals of vector embeddings and demonstrated their application in a practical book title search using Zilliz Cloud and OpenAI embedding models. - [A Guide to Using OpenAI Text Embedding Models for NLP Tasks - Zilliz blog](https://zilliz.com/learn/guide-to-using-openai-text-embedding-models): A comprehensive guide to using OpenAI text embedding models for embedding creation and semantic search.