使用Aleph Alpha嵌入与Qdrant
Aleph Alpha 是一个多模态和多语言的嵌入提供者。他们的 API 允许为文本和图像创建嵌入,两者都在相同的潜在空间中。他们维护了一个官方的 Python 客户端,可以通过 pip 安装:
pip install aleph-alpha-client
有同步和异步客户端可用。获取图像的嵌入并将其存储到Qdrant可以通过以下方式完成:
import qdrant_client
from qdrant_client.models import Batch
from aleph_alpha_client import (
Prompt,
AsyncClient,
SemanticEmbeddingRequest,
SemanticRepresentation,
ImagePrompt
)
aa_token = "<< your_token >>"
model = "luminous-base"
qdrant_client = qdrant_client.QdrantClient()
async with AsyncClient(token=aa_token) as client:
prompt = ImagePrompt.from_file("./path/to/the/image.jpg")
prompt = Prompt.from_image(prompt)
query_params = {
"prompt": prompt,
"representation": SemanticRepresentation.Symmetric,
"compress_to_size": 128,
}
query_request = SemanticEmbeddingRequest(**query_params)
query_response = await client.semantic_embed(
request=query_request, model=model
)
qdrant_client.upsert(
collection_name="MyCollection",
points=Batch(
ids=[1],
vectors=[query_response.embedding],
)
)
如果我们想用相同的模型创建文本嵌入,我们不会使用ImagePrompt.from_file,而是直接将输入文本提供给Prompt.from_text方法。
