AlephAlphaSymmetricSemanticEmbedding#

class langchain_community.embeddings.aleph_alpha.AlephAlphaSymmetricSemanticEmbedding[source]#

Bases: AlephAlphaAsymmetricSemanticEmbedding

Symmetric version of the Aleph Alpha’s semantic embeddings.

The main difference is that here, both the documents and queries are embedded with a SemanticRepresentation.Symmetric .. rubric:: Example

from aleph_alpha import AlephAlphaSymmetricSemanticEmbedding

embeddings = AlephAlphaAsymmetricSemanticEmbedding(
    normalize=True, compress_to_size=128
)
text = "This is a test text"

doc_result = embeddings.embed_documents([text])
query_result = embeddings.embed_query(text)

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

param aleph_alpha_api_key: str | None = None#

API key for Aleph Alpha API.

param compress_to_size: int | None = None#

Should the returned embeddings come back as an original 5120-dim vector, or should it be compressed to 128-dim.

param contextual_control_threshold: int | None = None#

Attention control parameters only apply to those tokens that have explicitly been set in the request.

param control_log_additive: bool = True#

Apply controls on prompt items by adding the log(control_factor) to attention scores.

param host: str = 'https://api.aleph-alpha.com'#

The hostname of the API host. The default one is “https://api.aleph-alpha.com”)

param hosting: str | None = None#

Determines in which datacenters the request may be processed. You can either set the parameter to “aleph-alpha” or omit it (defaulting to None). Not setting this value, or setting it to None, gives us maximal flexibility in processing your request in our own datacenters and on servers hosted with other providers. Choose this option for maximal availability. Setting it to “aleph-alpha” allows us to only process the request in our own datacenters. Choose this option for maximal data privacy.

param model: str = 'luminous-base'#

Model name to use.

param nice: bool = False#

Setting this to True, will signal to the API that you intend to be nice to other users by de-prioritizing your request below concurrent ones.

param normalize: bool = False#

Should returned embeddings be normalized

param request_timeout_seconds: int = 305#

Client timeout that will be set for HTTP requests in the requests library’s API calls. Server will close all requests after 300 seconds with an internal server error.

param total_retries: int = 8#

The number of retries made in case requests fail with certain retryable status codes. If the last retry fails a corresponding exception is raised. Note, that between retries an exponential backoff is applied, starting with 0.5 s after the first retry and doubling for each retry made. So with the default setting of 8 retries a total wait time of 63.5 s is added between the retries.

async aembed_documents(texts: list[str]) list[list[float]]#

Asynchronous Embed search docs.

Parameters:

texts (list[str]) – List of text to embed.

Returns:

List of embeddings.

Return type:

list[list[float]]

async aembed_query(text: str) list[float]#

Asynchronous Embed query text.

Parameters:

text (str) – Text to embed.

Returns:

Embedding.

Return type:

list[float]

embed_documents(texts: List[str]) List[List[float]][source]#

Call out to Aleph Alpha’s Document endpoint.

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]#

Call out to Aleph Alpha’s asymmetric, query embedding endpoint :param text: The text to embed.

Returns:

Embeddings for the text.

Parameters:

text (str)

Return type:

List[float]

Examples using AlephAlphaSymmetricSemanticEmbedding