langchain.embeddings.aleph_alpha.AlephAlphaAsymmetricSemanticEmbedding¶

class langchain.embeddings.aleph_alpha.AlephAlphaAsymmetricSemanticEmbedding(*, client: Any = None, model: Optional[str] = 'luminous-base', hosting: Optional[str] = 'https://api.aleph-alpha.com', normalize: Optional[bool] = True, compress_to_size: Optional[int] = 128, contextual_control_threshold: Optional[int] = None, control_log_additive: Optional[bool] = True, aleph_alpha_api_key: Optional[str] = None)[source]¶

Bases: BaseModel, Embeddings

Aleph Alpha’s asymmetric semantic embedding.

AA provides you with an endpoint to embed a document and a query. The models were optimized to make the embeddings of documents and the query for a document as similar as possible. To learn more, check out: https://docs.aleph-alpha.com/docs/tasks/semantic_embed/

Example

from aleph_alpha import AlephAlphaAsymmetricSemanticEmbedding

embeddings = AlephAlphaSymmetricSemanticEmbedding()

document = "This is a content of the document"
query = "What is the content of the document?"

doc_result = embeddings.embed_documents([document])
query_result = embeddings.embed_query(query)

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

Raises ValidationError if the input data cannot be parsed to form a valid model.

param aleph_alpha_api_key: Optional[str] = None¶

API key for Aleph Alpha API.

param client: Any = None¶

Aleph Alpha client.

param compress_to_size: Optional[int] = 128¶

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

param contextual_control_threshold: Optional[int] = None¶

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

param control_log_additive: Optional[bool] = True¶

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

param hosting: Optional[str] = 'https://api.aleph-alpha.com'¶

Optional parameter that specifies which datacenters may process the request.

param model: Optional[str] = 'luminous-base'¶

Model name to use.

param normalize: Optional[bool] = True¶

Should returned embeddings be normalized

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

Call out to Aleph Alpha’s asymmetric Document endpoint.

Parameters

texts – The list of texts to embed.

Returns

List of embeddings, one for each text.

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.

validator validate_environment  »  all fields[source]¶

Validate that api key and python package exists in environment.

Examples using AlephAlphaAsymmetricSemanticEmbedding¶