Skip to content

References

This module provides functions and classes for embedding queries, files, and directories using different embedding models.

The module includes the following functions:

  • embed_query: Embeds the given query and returns an EmbedData object.
  • embed_file: Embeds the file at the given path and returns a list of EmbedData objects.
  • embed_directory: Embeds all the files in the given directory and returns a list of EmbedData objects.

The module also includes the EmbedData class, which represents the data of an embedded file.

Usage:

  • To embed a query, use the embed_query function:

    embed_query(query: list[str], embeder: str) -> list[EmbedData]

  • To embed a file, use the embed_file function:

    embed_file(file_path: str, embeder: str) -> list[EmbedData]

  • To embed a directory, use the embed_directory function:

    embed_directory(file_path: str, embeder: str) -> list[EmbedData]

The EmbedData class has the following attributes: - embedding: The embedding of the file. - text: The text for which the embedding is generated for. - metadata: Additional metadata associated with the embedding.

Supported Embedding Models:

  • Text Embedding Models:

    • "OpenAI"
    • "Bert"
  • Image Embedding Models:

    • "Clip"
  • Audio Embedding Models:

    • "Whisper-Bert"

EmbedData

Represents the data of an embedded file.

Attributes:

Name Type Description
embedding list[float]

The embedding of the file.

text str

The text for which the embedding is generated for.

metadata dict[str, str]

Additional metadata associated with the embedding.

Source code in python/embed_anything/embed_anything.pyi
82
83
84
85
86
87
88
89
90
91
92
93
94
class EmbedData:
    """
    Represents the data of an embedded file.

    Attributes:
        embedding: The embedding of the file.
        text: The text for which the embedding is generated for.
        metadata: Additional metadata associated with the embedding.
    """

    embedding: list[float]
    text: str
    metadata: dict[str, str]

embed_directory(file_path, embeder)

Embeds all the files in the given directory and returns a list of EmbedData objects.

Parameters:

Name Type Description Default
file_path str

The path to the directory containing the files to embed.

required
embeder str

The name of the embedding model to use. Choose between "OpenAI" and "Bert"

required

Returns: - A list of EmbedData objects.

Source code in python/embed_anything/embed_anything.pyi
70
71
72
73
74
75
76
77
78
79
80
def embed_directory(file_path: str, embeder: str) -> list[EmbedData]:
    """
    Embeds all the files in the given directory and returns a list of EmbedData objects.

    Args:
        file_path: The path to the directory containing the files to embed.
        embeder: The name of the embedding model to use. Choose between "OpenAI" and "Bert"

    Returns:
    - A list of EmbedData objects.
    """

embed_file(file_path, embeder)

Embeds the file at the given path and returns a list of EmbedData objects.

  • Text -> "OpenAI", "Bert"
  • Image -> "Clip"
  • Audio -> "Whisper-Bert"

Parameters:

Name Type Description Default
file_path str

The path to the file to embed.

required
embeder str

The name of the embedding model to use.

required

Returns:

Type Description
list[EmbedData]

A list of EmbedData objects.

Source code in python/embed_anything/embed_anything.pyi
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
def embed_file(file_path: str, embeder: str) -> list[EmbedData]:
    """
    Embeds the file at the given path and returns a list of EmbedData objects.

    - Text -> "OpenAI", "Bert"
    - Image -> "Clip"
    - Audio -> "Whisper-Bert"

    Args:
        file_path: The path to the file to embed.
        embeder: The name of the embedding model to use.

    Returns:
        A list of EmbedData objects.

    """

embed_query(query, embeder)

Embeds the given query and returns an EmbedData object.

Parameters:

Name Type Description Default
query list[str]

The query to embed.

required
embeder str

The name of the embedding model to use. Choose between "OpenAI" and "Bert"

required

Returns:

Type Description
list[EmbedData]

An EmbedData object.

Source code in python/embed_anything/embed_anything.pyi
42
43
44
45
46
47
48
49
50
51
def embed_query(query: list[str], embeder: str) -> list[EmbedData]:
    """Embeds the given query and returns an EmbedData object.

    Args:
        query: The query to embed.
        embeder: The name of the embedding model to use. Choose between "OpenAI" and "Bert"

    Returns:
        An EmbedData object.
    """