Aleph Alpha
使用 Aleph Alpha 的语义嵌入有两种可能的方法。如果您有结构不相似的文本(例如文档和查询),您可能希望使用非对称嵌入。相反,对于结构相似的文本,建议使用对称嵌入。
非对称
<!--IMPORTS:[{"imported": "AlephAlphaAsymmetricSemanticEmbedding", "source": "langchain_community.embeddings", "docs": "https://python.langchain.com/api_reference/community/embeddings/langchain_community.embeddings.aleph_alpha.AlephAlphaAsymmetricSemanticEmbedding.html", "title": "Aleph Alpha"}]-->
from langchain_community.embeddings import AlephAlphaAsymmetricSemanticEmbedding
document = "This is a content of the document"
query = "What is the content of the document?"
embeddings = AlephAlphaAsymmetricSemanticEmbedding(normalize=True, compress_to_size=128)
doc_result = embeddings.embed_documents([document])
query_result = embeddings.embed_query(query)
对称
<!--IMPORTS:[{"imported": "AlephAlphaSymmetricSemanticEmbedding", "source": "langchain_community.embeddings", "docs": "https://python.langchain.com/api_reference/community/embeddings/langchain_community.embeddings.aleph_alpha.AlephAlphaSymmetricSemanticEmbedding.html", "title": "Aleph Alpha"}]-->
from langchain_community.embeddings import AlephAlphaSymmetricSemanticEmbedding
text = "This is a test text"
embeddings = AlephAlphaSymmetricSemanticEmbedding(normalize=True, compress_to_size=128)
doc_result = embeddings.embed_documents([text])
query_result = embeddings.embed_query(text)