Cohere

Qdrant 兼容 Cohere co.embed API 及其官方 Python SDK,该 SDK 可以像其他包一样安装。

pip install cohere

co.embed API 返回的嵌入向量可以直接用于 Qdrant 客户端的调用中。

import cohere
import qdrant_client
from qdrant_client.models import Batch

cohere_client = cohere.Client("<< your_api_key >>")
qdrant_client = qdrant_client.QdrantClient()
qdrant_client.upsert(
    collection_name="MyCollection",
    points=Batch(
        ids=[1],
        vectors=cohere_client.embed(
            model="large",
            texts=["The best vector database"],
        ).embeddings,
    ),
)

如果您有兴趣查看使用 co.embed API 和 Qdrant 创建的端到端项目,请查阅“使用 Cohere 和 Qdrant 的问答即服务”文章。

Embed v3

Embed v3 是 Cohere 模型家族的新成员,于 2023 年 11 月发布。新模型要求在 API 调用中传递一个额外参数:input_type。它决定了您希望使用嵌入向量执行的任务类型。

  • input_type="search_document" - 用于存储在 Qdrant 中的文档
  • input_type="search_query" - 用于搜索查询以查找最相关的文档
  • input_type="classification" - 用于分类任务
  • input_type="clustering" - 用于文本聚类

在实现语义搜索应用程序(例如 RAG)时,您应该对索引文档使用 input_type="search_document",对搜索查询使用 input_type="search_query"。以下示例展示了如何使用 Embed v3 模型索引文档

import cohere
import qdrant_client
from qdrant_client.models import Batch

cohere_client = cohere.Client("<< your_api_key >>")
client = qdrant_client.QdrantClient()
client.upsert(
    collection_name="MyCollection",
    points=Batch(
        ids=[1],
        vectors=cohere_client.embed(
            model="embed-english-v3.0",  # New Embed v3 model
            input_type="search_document",  # Input type for documents
            texts=["Qdrant is the a vector database written in Rust"],
        ).embeddings,
    ),
)

文档索引完成后,您可以使用 Embed v3 模型搜索最相关的文档

client.query_points(
    collection_name="MyCollection",
    query=cohere_client.embed(
        model="embed-english-v3.0",  # New Embed v3 model
        input_type="search_query",  # Input type for search queries
        texts=["The best vector database"],
    ).embeddings[0],
)
此页面有用吗?

感谢您的反馈!🙏

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