xtrace_sdk.inference.embedding

Classes

Embedding

This class provides an interface to generate embeddings using different providers.

Module Contents

class xtrace_sdk.inference.embedding.Embedding(provider, model_name, dim)

This class provides an interface to generate embeddings using different providers. Supported providers include “ollama”, “openai”, and “sentence_transformer”. It also includes methods to convert float embeddings to binary format.

Parameters:
dim
provider
url
model_name
__hash__()
Return type:

int

__eq__(other)
Parameters:

other (Any)

Return type:

bool

embed(text)

Generates an embedding for the given text using the specified provider.

Parameters:

text (str) – The input text to be embedded.

Returns:

A numpy array representing the embedding of the input text.

Return type:

np.ndarray

Raises:

ValueError – If the embedding dimension does not match the expected dimension.

static float_2_bin(float_array)

Convert a list of floats to a list of binary integers, naive implementation, preserves dimension

Parameters:

float_array (np.ndarray or list[float]) – A numpy array or list of floats to be converted.

Returns:

A numpy array of binary integers (0s and 1s).

Return type:

np.ndarray

sim_hash(float_array)
Parameters:

float_array (numpy.ndarray | list[float])

Return type:

None

bin_embed(text)

Generates a binary embedding for the given text. :param text: The input text to be embedded. :type text: str :return: A numpy array representing the binary embedding of the input text. :rtype: np.ndarray

Parameters:

text (str)

Return type:

numpy.ndarray