将 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 方法。

本页面是否有用?

感谢您的反馈! 🙏

很抱歉听到这个消息。😔 您可以在 GitHub 上编辑此页面,或创建一个 GitHub Issue。