Skip to content

Openai embedding

get_openai_embedding(text, llm_emb_model='text-embedding-3-small')

Get the embedding from OpenAI API

Parameters:

Name Type Description Default
text str

The text to get the embedding

required
llm_emb_model str

The name of the LLM model

'text-embedding-3-small'

Returns:

Name Type Description
str

The embedding of the text

Source code in Docs2KG/modules/llm/openai_embedding.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
def get_openai_embedding(text: str, llm_emb_model: str = "text-embedding-3-small"):
    """
    Get the embedding from OpenAI API

    Args:
        text (str): The text to get the embedding
        llm_emb_model (str): The name of the LLM model

    Returns:
        str: The embedding of the text
    """
    response = client.embeddings.create(input=text, model=llm_emb_model)

    return response.data[0].embedding